public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); $route = $this->routes->get($request->attributes->get('_route')); if ($route && ($converters = $route->getOption('_converters'))) { foreach ($converters as $name => $callback) { $value = $request->attributes->get($name); $middleware = $this->callbackResolver->resolveCallback($callback); $ret = $this->callbackInvoker->call($middleware, [$name => $value, 'Symfony\\Component\\HttpFoundation\\Request' => $request, 0 => $value, 1 => $request]); $request->attributes->set($name, $ret); } } }
public function finish($callback, $priority = 0) { $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use($callback) { $request = $event->getRequest(); $response = $event->getResponse(); $middleware = $this['callback_resolver']->resolveCallback($callback); $this->callbackInvoker->call($middleware, ['Symfony\\Component\\HttpFoundation\\Request' => $request, 'Symfony\\Component\\HttpFoundation\\Response' => $response, 0 => $request, 1 => $response, 2 => $this]); }, $priority); }
public function onKernelResponse(FilterResponseEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); $routeName = $request->attributes->get('_route'); if (!($route = $this->app['routes']->get($routeName))) { return; } foreach ((array) $route->getOption('_after_middlewares') as $callback) { $middleware = $this->app['callback_resolver']->resolveCallback($callback); $ret = $this->callbackInvoker->call($middleware, ['Symfony\\Component\\HttpFoundation\\Request' => $request, 'Symfony\\Component\\HttpFoundation\\Response' => $response, 0 => $request, 1 => $response, 2 => $this->app]); if ($ret instanceof Response) { $event->setResponse($ret); } elseif (null !== $ret) { throw new \RuntimeException(sprintf('An after middleware for route "%s" returned an invalid response value. Must return null or an instance of Response.', $routeName)); } } }
public function finish($callback, $priority = 0) { $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use($callback) { $request = $event->getRequest(); $response = $event->getResponse(); $middleware = $this['callback_resolver']->resolveCallback($callback); $ret = $this->callbackInvoker->call($middleware, ['Symfony\\Component\\HttpFoundation\\Request' => $request, 'Symfony\\Component\\HttpFoundation\\Response' => $response, 0 => $request, 1 => $response, 2 => $this]); if ($ret instanceof Response) { $event->setResponse($ret); } elseif (null !== $ret) { throw new \RuntimeException('An after middleware returned an invalid response value. Must return null or an instance of Response.'); } }, $priority); }