summaryrefslogtreecommitdiff
path: root/vendor/symfony/http-kernel/Fragment
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2018-01-19 15:40:08 +0000
committerGreg Roach <fisharebest@gmail.com>2018-01-19 22:39:48 +0000
commit9499ed38534b88c310649782326f430b724fbe3a (patch)
tree3b10195a8e8e56024f75403869d5a56074314181 /vendor/symfony/http-kernel/Fragment
parentc9b4efa1714b4374cc3446e0d3a1935da0cb3a59 (diff)
downloadwebtrees-9499ed38534b88c310649782326f430b724fbe3a.tar.gz
webtrees-9499ed38534b88c310649782326f430b724fbe3a.tar.bz2
webtrees-9499ed38534b88c310649782326f430b724fbe3a.zip
Add symfony/http-kernel
Diffstat (limited to 'vendor/symfony/http-kernel/Fragment')
-rw-r--r--vendor/symfony/http-kernel/Fragment/AbstractSurrogateFragmentRenderer.php112
-rw-r--r--vendor/symfony/http-kernel/Fragment/EsiFragmentRenderer.php28
-rw-r--r--vendor/symfony/http-kernel/Fragment/FragmentHandler.php118
-rw-r--r--vendor/symfony/http-kernel/Fragment/FragmentRendererInterface.php42
-rw-r--r--vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php167
-rw-r--r--vendor/symfony/http-kernel/Fragment/InlineFragmentRenderer.php158
-rw-r--r--vendor/symfony/http-kernel/Fragment/RoutableFragmentRenderer.php90
-rw-r--r--vendor/symfony/http-kernel/Fragment/SsiFragmentRenderer.php28
8 files changed, 743 insertions, 0 deletions
diff --git a/vendor/symfony/http-kernel/Fragment/AbstractSurrogateFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/AbstractSurrogateFragmentRenderer.php
new file mode 100644
index 0000000000..0d4d26b676
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/AbstractSurrogateFragmentRenderer.php
@@ -0,0 +1,112 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
+use Symfony\Component\HttpKernel\UriSigner;
+
+/**
+ * Implements Surrogate rendering strategy.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRenderer
+{
+ private $surrogate;
+ private $inlineStrategy;
+ private $signer;
+
+ /**
+ * Constructor.
+ *
+ * The "fallback" strategy when surrogate is not available should always be an
+ * instance of InlineFragmentRenderer.
+ *
+ * @param SurrogateInterface $surrogate An Surrogate instance
+ * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported
+ * @param UriSigner $signer
+ */
+ public function __construct(SurrogateInterface $surrogate = null, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
+ {
+ $this->surrogate = $surrogate;
+ $this->inlineStrategy = $inlineStrategy;
+ $this->signer = $signer;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Note that if the current Request has no surrogate capability, this method
+ * falls back to use the inline rendering strategy.
+ *
+ * Additional available options:
+ *
+ * * alt: an alternative URI to render in case of an error
+ * * comment: a comment to add when returning the surrogate tag
+ *
+ * Note, that not all surrogate strategies support all options. For now
+ * 'alt' and 'comment' are only supported by ESI.
+ *
+ * @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
+ */
+ public function render($uri, Request $request, array $options = array())
+ {
+ if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
+ if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
+ @trigger_error('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated since version 3.1, and will be removed in 4.0. Use a different rendering strategy or pass scalar values.', E_USER_DEPRECATED);
+ }
+
+ return $this->inlineStrategy->render($uri, $request, $options);
+ }
+
+ if ($uri instanceof ControllerReference) {
+ $uri = $this->generateSignedFragmentUri($uri, $request);
+ }
+
+ $alt = isset($options['alt']) ? $options['alt'] : null;
+ if ($alt instanceof ControllerReference) {
+ $alt = $this->generateSignedFragmentUri($alt, $request);
+ }
+
+ $tag = $this->surrogate->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : '');
+
+ return new Response($tag);
+ }
+
+ private function generateSignedFragmentUri($uri, Request $request)
+ {
+ if (null === $this->signer) {
+ throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
+ }
+
+ // we need to sign the absolute URI, but want to return the path only.
+ $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true));
+
+ return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
+ }
+
+ private function containsNonScalars(array $values)
+ {
+ foreach ($values as $value) {
+ if (is_array($value) && $this->containsNonScalars($value)) {
+ return true;
+ } elseif (!is_scalar($value) && null !== $value) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/EsiFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/EsiFragmentRenderer.php
new file mode 100644
index 0000000000..a4570e3beb
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/EsiFragmentRenderer.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+/**
+ * Implements the ESI rendering strategy.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class EsiFragmentRenderer extends AbstractSurrogateFragmentRenderer
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'esi';
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/FragmentHandler.php b/vendor/symfony/http-kernel/Fragment/FragmentHandler.php
new file mode 100644
index 0000000000..0d0a042460
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/FragmentHandler.php
@@ -0,0 +1,118 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\StreamedResponse;
+use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+
+/**
+ * Renders a URI that represents a resource fragment.
+ *
+ * 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.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @see FragmentRendererInterface
+ */
+class FragmentHandler
+{
+ private $debug;
+ private $renderers = array();
+ private $requestStack;
+
+ /**
+ * Constructor.
+ *
+ * @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 $requestStack, array $renderers = array(), $debug = false)
+ {
+ $this->requestStack = $requestStack;
+ foreach ($renderers as $renderer) {
+ $this->addRenderer($renderer);
+ }
+ $this->debug = $debug;
+ }
+
+ /**
+ * Adds a renderer.
+ *
+ * @param FragmentRendererInterface $renderer A FragmentRendererInterface instance
+ */
+ public function addRenderer(FragmentRendererInterface $renderer)
+ {
+ $this->renderers[$renderer->getName()] = $renderer;
+ }
+
+ /**
+ * Renders a URI and returns the Response content.
+ *
+ * Available options:
+ *
+ * * ignore_errors: true to return an empty string in case of an error
+ *
+ * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
+ * @param string $renderer The renderer name
+ * @param array $options An array of options
+ *
+ * @return string|null The Response content or null when the Response is streamed
+ *
+ * @throws \InvalidArgumentException when the renderer does not exist
+ * @throws \LogicException when no master request is being handled
+ */
+ public function render($uri, $renderer = 'inline', array $options = array())
+ {
+ if (!isset($options['ignore_errors'])) {
+ $options['ignore_errors'] = !$this->debug;
+ }
+
+ if (!isset($this->renderers[$renderer])) {
+ throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
+ }
+
+ if (!$request = $this->requestStack->getCurrentRequest()) {
+ throw new \LogicException('Rendering a fragment can only be done when handling a Request.');
+ }
+
+ return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));
+ }
+
+ /**
+ * Delivers the Response as a string.
+ *
+ * When the Response is a StreamedResponse, the content is streamed immediately
+ * instead of being returned.
+ *
+ * @param Response $response A Response instance
+ *
+ * @return string|null The Response content or null when the Response is streamed
+ *
+ * @throws \RuntimeException when the Response is not successful
+ */
+ protected function deliver(Response $response)
+ {
+ if (!$response->isSuccessful()) {
+ throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
+ }
+
+ if (!$response instanceof StreamedResponse) {
+ return $response->getContent();
+ }
+
+ $response->sendContent();
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/FragmentRendererInterface.php b/vendor/symfony/http-kernel/Fragment/FragmentRendererInterface.php
new file mode 100644
index 0000000000..b177c3ac12
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/FragmentRendererInterface.php
@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Interface implemented by all rendering strategies.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+interface FragmentRendererInterface
+{
+ /**
+ * Renders a URI and returns the Response content.
+ *
+ * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
+ * @param Request $request A Request instance
+ * @param array $options An array of options
+ *
+ * @return Response A Response instance
+ */
+ public function render($uri, Request $request, array $options = array());
+
+ /**
+ * Gets the name of the strategy.
+ *
+ * @return string The strategy name
+ */
+ public function getName();
+}
diff --git a/vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php
new file mode 100644
index 0000000000..ec2a40716a
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php
@@ -0,0 +1,167 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Templating\EngineInterface;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Symfony\Component\HttpKernel\UriSigner;
+use Twig\Environment;
+use Twig\Error\LoaderError;
+use Twig\Loader\ExistsLoaderInterface;
+
+/**
+ * Implements the Hinclude rendering strategy.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class HIncludeFragmentRenderer extends RoutableFragmentRenderer
+{
+ private $globalDefaultTemplate;
+ private $signer;
+ private $templating;
+ private $charset;
+
+ /**
+ * Constructor.
+ *
+ * @param EngineInterface|Environment $templating An EngineInterface or a Twig instance
+ * @param UriSigner $signer A UriSigner instance
+ * @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
+ * @param string $charset
+ */
+ public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null, $charset = 'utf-8')
+ {
+ $this->setTemplating($templating);
+ $this->globalDefaultTemplate = $globalDefaultTemplate;
+ $this->signer = $signer;
+ $this->charset = $charset;
+ }
+
+ /**
+ * Sets the templating engine to use to render the default content.
+ *
+ * @param EngineInterface|Environment|null $templating An EngineInterface or an Environment instance
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function setTemplating($templating)
+ {
+ if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof Environment) {
+ throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of Twig\Environment or Symfony\Component\Templating\EngineInterface');
+ }
+
+ $this->templating = $templating;
+ }
+
+ /**
+ * Checks if a templating engine has been set.
+ *
+ * @return bool true if the templating engine has been set, false otherwise
+ */
+ public function hasTemplating()
+ {
+ return null !== $this->templating;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Additional available options:
+ *
+ * * default: The default content (it can be a template name or the content)
+ * * id: An optional hx:include tag id attribute
+ * * attributes: An optional array of hx:include tag attributes
+ */
+ public function render($uri, Request $request, array $options = array())
+ {
+ if ($uri instanceof ControllerReference) {
+ if (null === $this->signer) {
+ throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.');
+ }
+
+ // we need to sign the absolute URI, but want to return the path only.
+ $uri = substr($this->signer->sign($this->generateFragmentUri($uri, $request, true)), strlen($request->getSchemeAndHttpHost()));
+ }
+
+ // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
+ $uri = str_replace('&', '&amp;', $uri);
+
+ $template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
+ if (null !== $this->templating && $template && $this->templateExists($template)) {
+ $content = $this->templating->render($template);
+ } else {
+ $content = $template;
+ }
+
+ $attributes = isset($options['attributes']) && is_array($options['attributes']) ? $options['attributes'] : array();
+ if (isset($options['id']) && $options['id']) {
+ $attributes['id'] = $options['id'];
+ }
+ $renderedAttributes = '';
+ if (count($attributes) > 0) {
+ $flags = ENT_QUOTES | ENT_SUBSTITUTE;
+ foreach ($attributes as $attribute => $value) {
+ $renderedAttributes .= sprintf(
+ ' %s="%s"',
+ htmlspecialchars($attribute, $flags, $this->charset, false),
+ htmlspecialchars($value, $flags, $this->charset, false)
+ );
+ }
+ }
+
+ return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
+ }
+
+ /**
+ * @param string $template
+ *
+ * @return bool
+ */
+ private function templateExists($template)
+ {
+ if ($this->templating instanceof EngineInterface) {
+ try {
+ return $this->templating->exists($template);
+ } catch (\InvalidArgumentException $e) {
+ return false;
+ }
+ }
+
+ $loader = $this->templating->getLoader();
+ if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
+ return $loader->exists($template);
+ }
+
+ try {
+ if (method_exists($loader, 'getSourceContext')) {
+ $loader->getSourceContext($template);
+ } else {
+ $loader->getSource($template);
+ }
+
+ return true;
+ } catch (LoaderError $e) {
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'hinclude';
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/InlineFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/InlineFragmentRenderer.php
new file mode 100644
index 0000000000..437b40bf95
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/InlineFragmentRenderer.php
@@ -0,0 +1,158 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+/**
+ * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class InlineFragmentRenderer extends RoutableFragmentRenderer
+{
+ private $kernel;
+ private $dispatcher;
+
+ /**
+ * Constructor.
+ *
+ * @param HttpKernelInterface $kernel A HttpKernelInterface instance
+ * @param EventDispatcherInterface $dispatcher A EventDispatcherInterface instance
+ */
+ public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null)
+ {
+ $this->kernel = $kernel;
+ $this->dispatcher = $dispatcher;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Additional available options:
+ *
+ * * alt: an alternative URI to render in case of an error
+ */
+ public function render($uri, Request $request, array $options = array())
+ {
+ $reference = null;
+ if ($uri instanceof ControllerReference) {
+ $reference = $uri;
+
+ // Remove attributes from the generated URI because if not, the Symfony
+ // routing system will use them to populate the Request attributes. We don't
+ // want that as we want to preserve objects (so we manually set Request attributes
+ // below instead)
+ $attributes = $reference->attributes;
+ $reference->attributes = array();
+
+ // The request format and locale might have been overridden by the user
+ foreach (array('_format', '_locale') as $key) {
+ if (isset($attributes[$key])) {
+ $reference->attributes[$key] = $attributes[$key];
+ }
+ }
+
+ $uri = $this->generateFragmentUri($uri, $request, false, false);
+
+ $reference->attributes = array_merge($attributes, $reference->attributes);
+ }
+
+ $subRequest = $this->createSubRequest($uri, $request);
+
+ // override Request attributes as they can be objects (which are not supported by the generated URI)
+ if (null !== $reference) {
+ $subRequest->attributes->add($reference->attributes);
+ }
+
+ $level = ob_get_level();
+ try {
+ return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
+ } catch (\Exception $e) {
+ // we dispatch the exception event to trigger the logging
+ // the response that comes back is simply ignored
+ if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
+ $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
+
+ $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
+ }
+
+ // let's clean up the output buffers that were created by the sub-request
+ Response::closeOutputBuffers($level, false);
+
+ if (isset($options['alt'])) {
+ $alt = $options['alt'];
+ unset($options['alt']);
+
+ return $this->render($alt, $request, $options);
+ }
+
+ if (!isset($options['ignore_errors']) || !$options['ignore_errors']) {
+ throw $e;
+ }
+
+ return new Response();
+ }
+ }
+
+ protected function createSubRequest($uri, Request $request)
+ {
+ $cookies = $request->cookies->all();
+ $server = $request->server->all();
+
+ // Override the arguments to emulate a sub-request.
+ // Sub-request object will point to localhost as client ip and real client ip
+ // will be included into trusted header for client ip
+ try {
+ if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
+ $currentXForwardedFor = $request->headers->get('X_FORWARDED_FOR', '');
+
+ $server['HTTP_X_FORWARDED_FOR'] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
+ } elseif (method_exists(Request::class, 'getTrustedHeaderName') && $trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP, false)) {
+ $currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
+
+ $server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
+ }
+ } catch (\InvalidArgumentException $e) {
+ // Do nothing
+ }
+
+ $server['REMOTE_ADDR'] = '127.0.0.1';
+ unset($server['HTTP_IF_MODIFIED_SINCE']);
+ unset($server['HTTP_IF_NONE_MATCH']);
+
+ $subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
+ if ($request->headers->has('Surrogate-Capability')) {
+ $subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
+ }
+
+ if ($session = $request->getSession()) {
+ $subRequest->setSession($session);
+ }
+
+ return $subRequest;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'inline';
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/RoutableFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/RoutableFragmentRenderer.php
new file mode 100644
index 0000000000..d7eeb89a6b
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/RoutableFragmentRenderer.php
@@ -0,0 +1,90 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\EventListener\FragmentListener;
+
+/**
+ * Adds the possibility to generate a fragment URI for a given Controller.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+abstract class RoutableFragmentRenderer implements FragmentRendererInterface
+{
+ private $fragmentPath = '/_fragment';
+
+ /**
+ * Sets the fragment path that triggers the fragment listener.
+ *
+ * @param string $path The path
+ *
+ * @see FragmentListener
+ */
+ public function setFragmentPath($path)
+ {
+ $this->fragmentPath = $path;
+ }
+
+ /**
+ * Generates a fragment URI for a given controller.
+ *
+ * @param ControllerReference $reference A ControllerReference instance
+ * @param Request $request A Request instance
+ * @param bool $absolute Whether to generate an absolute URL or not
+ * @param bool $strict Whether to allow non-scalar attributes or not
+ *
+ * @return string A fragment URI
+ */
+ protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false, $strict = true)
+ {
+ if ($strict) {
+ $this->checkNonScalar($reference->attributes);
+ }
+
+ // We need to forward the current _format and _locale values as we don't have
+ // a proper routing pattern to do the job for us.
+ // This makes things inconsistent if you switch from rendering a controller
+ // to rendering a route if the route pattern does not contain the special
+ // _format and _locale placeholders.
+ if (!isset($reference->attributes['_format'])) {
+ $reference->attributes['_format'] = $request->getRequestFormat();
+ }
+ if (!isset($reference->attributes['_locale'])) {
+ $reference->attributes['_locale'] = $request->getLocale();
+ }
+
+ $reference->attributes['_controller'] = $reference->controller;
+
+ $reference->query['_path'] = http_build_query($reference->attributes, '', '&');
+
+ $path = $this->fragmentPath.'?'.http_build_query($reference->query, '', '&');
+
+ if ($absolute) {
+ return $request->getUriForPath($path);
+ }
+
+ return $request->getBaseUrl().$path;
+ }
+
+ private function checkNonScalar($values)
+ {
+ foreach ($values as $key => $value) {
+ if (is_array($value)) {
+ $this->checkNonScalar($value);
+ } elseif (!is_scalar($value) && null !== $value) {
+ throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key));
+ }
+ }
+ }
+}
diff --git a/vendor/symfony/http-kernel/Fragment/SsiFragmentRenderer.php b/vendor/symfony/http-kernel/Fragment/SsiFragmentRenderer.php
new file mode 100644
index 0000000000..45e7122f05
--- /dev/null
+++ b/vendor/symfony/http-kernel/Fragment/SsiFragmentRenderer.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Fragment;
+
+/**
+ * Implements the SSI rendering strategy.
+ *
+ * @author Sebastian Krebs <krebs.seb@gmail.com>
+ */
+class SsiFragmentRenderer extends AbstractSurrogateFragmentRenderer
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'ssi';
+ }
+}