Explorar el Código

[HttpKernel] changed the core.view event to only be notified when the controller does not return a Response

Fabien Potencier hace 14 años
padre
commit
c05fb03c7d

+ 5 - 3
src/Symfony/Component/HttpKernel/HttpKernel.php

@@ -104,11 +104,13 @@ class HttpKernel implements HttpKernelInterface
         $arguments = $this->resolver->getArguments($request, $controller);
 
         // call controller
-        $retval = call_user_func_array($controller, $arguments);
+        $response = call_user_func_array($controller, $arguments);
 
         // view
-        $event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request));
-        $response = $this->dispatcher->filter($event, $retval);
+        if (!$response instanceof Response) {
+            $event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request));
+            $response = $this->dispatcher->filter($event, $response);
+        }
 
         return $this->filterResponse($response, $request, sprintf('The controller must return a response (%s given).', $this->varToString($response)), $type);
     }

+ 16 - 9
src/Symfony/Component/HttpKernel/bootstrap.php

@@ -30,6 +30,10 @@ class Container implements ContainerInterface
 {
     protected $parameterBag;
     protected $services;
+    protected $scopes;
+    protected $scopeChildren;
+    protected $scopedServices;
+    protected $scopeStacks;
     protected $loading = array();
     public function __construct(ParameterBagInterface $parameterBag = null)
     {
@@ -174,13 +178,9 @@ class Container implements ContainerInterface
         }
         $this->scopes[$name] = $parentScope;
         $this->scopeChildren[$name] = array();
-                if ($parentScope !== self::SCOPE_CONTAINER) {
+                while ($parentScope !== self::SCOPE_CONTAINER) {
             $this->scopeChildren[$parentScope][] = $name;
-            foreach ($this->scopeChildren as $pName => $childScopes) {
-                if (in_array($parentScope, $childScopes, true)) {
-                    $this->scopeChildren[$pName][] = $name;
-                }
-            }
+            $parentScope = $this->scopes[$parentScope];
         }
     }
     public function hasScope($name)
@@ -485,9 +485,11 @@ class HttpKernel implements HttpKernelInterface
             throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller)));
         }
                 $arguments = $this->resolver->getArguments($request, $controller);
-                $retval = call_user_func_array($controller, $arguments);
-                $event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request));
-        $response = $this->dispatcher->filter($event, $retval);
+                $response = call_user_func_array($controller, $arguments);
+                if (!$response instanceof Response) {
+            $event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request));
+            $response = $this->dispatcher->filter($event, $response);
+        }
         return $this->filterResponse($response, $request, sprintf('The controller must return a response (%s given).', $this->varToString($response)), $type);
     }
     protected function filterResponse($response, $request, $message, $type)
@@ -967,6 +969,11 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
 class FileBag extends ParameterBag
 {
     private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
+    public function __construct(array $parameters = array())
+    {
+                        parent::__construct();
+        $this->replace($parameters);
+    }
     public function replace(array $files = array())
     {
         $this->parameters = array();

+ 10 - 0
src/Symfony/Component/HttpKernel/bootstrap_cache.php

@@ -1092,6 +1092,11 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
 class FileBag extends ParameterBag
 {
     private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
+    public function __construct(array $parameters = array())
+    {
+                        parent::__construct();
+        $this->replace($parameters);
+    }
     public function replace(array $files = array())
     {
         $this->parameters = array();
@@ -1907,6 +1912,11 @@ namespace Symfony\Component\HttpFoundation
 class ResponseHeaderBag extends HeaderBag
 {
     protected $computedCacheControl = array();
+    public function __construct(array $parameters = array())
+    {
+                        parent::__construct();
+        $this->replace($parameters);
+    }
     public function replace(array $headers = array())
     {
         parent::replace($headers);