コード例 #1
0
 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);
         }
     }
 }
コード例 #2
0
ファイル: Application.php プロジェクト: php-di/silex-bridge
 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);
 }
コード例 #3
0
 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));
         }
     }
 }
コード例 #4
0
ファイル: Application.php プロジェクト: jdreesen/Silex-Bridge
 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);
 }