Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / Fragment / FragmentHandler.php
index dff3773d38a7192f51e5eb520b44a71c19c4b443..0d0a0424607c1864caae202a379bec0aaab3bb32 100644 (file)
@@ -11,7 +11,6 @@
 
 namespace Symfony\Component\HttpKernel\Fragment;
 
-use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpFoundation\StreamedResponse;
 use Symfony\Component\HttpFoundation\RequestStack;
@@ -23,11 +22,6 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference;
  * This class handles the rendering of resource fragments that are included into
  * a main resource. The handling of the rendering is managed by specialized renderers.
  *
- * This listener works in 2 modes:
- *
- *  * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
- *  * 2.4+ mode where you must pass a RequestStack instance in the constructor.
- *
  * @author Fabien Potencier <fabien@symfony.com>
  *
  * @see FragmentRendererInterface
@@ -36,38 +30,17 @@ class FragmentHandler
 {
     private $debug;
     private $renderers = array();
-    private $request;
     private $requestStack;
 
     /**
      * Constructor.
      *
-     * RequestStack will become required in 3.0.
-     *
      * @param RequestStack                $requestStack The Request stack that controls the lifecycle of requests
      * @param FragmentRendererInterface[] $renderers    An array of FragmentRendererInterface instances
      * @param bool                        $debug        Whether the debug mode is enabled or not
      */
-    public function __construct($requestStack = null, $renderers = array(), $debug = false)
+    public function __construct(RequestStack $requestStack, array $renderers = array(), $debug = false)
     {
-        if (is_array($requestStack)) {
-            $tmp = $debug;
-            $debug = func_num_args() < 2 ? false : $renderers;
-            $renderers = $requestStack;
-            $requestStack = func_num_args() < 3 ? null : $tmp;
-
-            @trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as first argument as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
-        } elseif (!$requestStack instanceof RequestStack) {
-            @trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
-        }
-
-        if (null !== $requestStack && !$requestStack instanceof RequestStack) {
-            throw new \InvalidArgumentException('RequestStack instance expected.');
-        }
-        if (!is_array($renderers)) {
-            throw new \InvalidArgumentException('Renderers must be an array.');
-        }
-
         $this->requestStack = $requestStack;
         foreach ($renderers as $renderer) {
             $this->addRenderer($renderer);
@@ -85,24 +58,6 @@ class FragmentHandler
         $this->renderers[$renderer->getName()] = $renderer;
     }
 
-    /**
-     * Sets the current Request.
-     *
-     * This method was used to synchronize the Request, but as the HttpKernel
-     * is doing that automatically now, you should never call it directly.
-     * It is kept public for BC with the 2.3 version.
-     *
-     * @param Request|null $request A Request instance
-     *
-     * @deprecated since version 2.4, to be removed in 3.0.
-     */
-    public function setRequest(Request $request = null)
-    {
-        @trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
-
-        $this->request = $request;
-    }
-
     /**
      * Renders a URI and returns the Response content.
      *
@@ -129,7 +84,7 @@ class FragmentHandler
             throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
         }
 
-        if (!$request = $this->getRequest()) {
+        if (!$request = $this->requestStack->getCurrentRequest()) {
             throw new \LogicException('Rendering a fragment can only be done when handling a Request.');
         }
 
@@ -151,7 +106,7 @@ class FragmentHandler
     protected function deliver(Response $response)
     {
         if (!$response->isSuccessful()) {
-            throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->getRequest()->getUri(), $response->getStatusCode()));
+            throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
         }
 
         if (!$response instanceof StreamedResponse) {
@@ -160,9 +115,4 @@ class FragmentHandler
 
         $response->sendContent();
     }
-
-    private function getRequest()
-    {
-        return $this->requestStack ? $this->requestStack->getCurrentRequest() : $this->request;
-    }
 }