updated-packages
This commit is contained in:
@@ -32,9 +32,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
* 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)
|
||||
{
|
||||
@@ -59,7 +57,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
*
|
||||
* @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
|
||||
*/
|
||||
public function render($uri, Request $request, array $options = array())
|
||||
public function render($uri, Request $request, array $options = [])
|
||||
{
|
||||
if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
|
||||
if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
|
||||
@@ -73,17 +71,17 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
$uri = $this->generateSignedFragmentUri($uri, $request);
|
||||
}
|
||||
|
||||
$alt = isset($options['alt']) ? $options['alt'] : null;
|
||||
$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'] : '');
|
||||
$tag = $this->surrogate->renderIncludeTag($uri, $alt, $options['ignore_errors'] ?? false, $options['comment'] ?? '');
|
||||
|
||||
return new Response($tag);
|
||||
}
|
||||
|
||||
private function generateSignedFragmentUri($uri, Request $request): string
|
||||
private function generateSignedFragmentUri(ControllerReference $uri, Request $request): string
|
||||
{
|
||||
if (null === $this->signer) {
|
||||
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
|
||||
@@ -98,9 +96,11 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
private function containsNonScalars(array $values): bool
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
if (\is_array($value)) {
|
||||
return $this->containsNonScalars($value);
|
||||
} elseif (!is_scalar($value) && null !== $value) {
|
||||
if (\is_scalar($value) || null === $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\is_array($value) || $this->containsNonScalars($value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -29,15 +29,14 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
class FragmentHandler
|
||||
{
|
||||
private $debug;
|
||||
private $renderers = array();
|
||||
private $renderers = [];
|
||||
private $requestStack;
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @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(), bool $debug = false)
|
||||
public function __construct(RequestStack $requestStack, array $renderers = [], bool $debug = false)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
foreach ($renderers as $renderer) {
|
||||
@@ -63,14 +62,13 @@ class FragmentHandler
|
||||
*
|
||||
* @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())
|
||||
public function render($uri, $renderer = 'inline', array $options = [])
|
||||
{
|
||||
if (!isset($options['ignore_errors'])) {
|
||||
$options['ignore_errors'] = !$this->debug;
|
||||
@@ -100,7 +98,7 @@ class FragmentHandler
|
||||
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()));
|
||||
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
|
||||
}
|
||||
|
||||
if (!$response instanceof StreamedResponse) {
|
||||
@@ -108,5 +106,7 @@ class FragmentHandler
|
||||
}
|
||||
|
||||
$response->sendContent();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -25,13 +25,11 @@ 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
|
||||
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
public function render($uri, Request $request, array $options = array());
|
||||
public function render($uri, Request $request, array $options = []);
|
||||
|
||||
/**
|
||||
* Gets the name of the strategy.
|
||||
|
@@ -19,6 +19,7 @@ use Symfony\Component\Templating\EngineInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Loader\ExistsLoaderInterface;
|
||||
use Twig\Loader\SourceContextLoaderInterface;
|
||||
|
||||
/**
|
||||
* Implements the Hinclude rendering strategy.
|
||||
@@ -34,9 +35,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
|
||||
/**
|
||||
* @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, string $globalDefaultTemplate = null, string $charset = 'utf-8')
|
||||
{
|
||||
@@ -52,11 +51,17 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
* @param EngineInterface|Environment|null $templating An EngineInterface or an Environment instance
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
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');
|
||||
throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of Twig\Environment or Symfony\Component\Templating\EngineInterface.');
|
||||
}
|
||||
|
||||
if ($templating instanceof EngineInterface) {
|
||||
@trigger_error(sprintf('Using a "%s" instance for "%s" is deprecated since version 4.3; use a \Twig\Environment instance instead.', EngineInterface::class, __CLASS__), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->templating = $templating;
|
||||
@@ -81,7 +86,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
* * 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())
|
||||
public function render($uri, Request $request, array $options = [])
|
||||
{
|
||||
if ($uri instanceof ControllerReference) {
|
||||
if (null === $this->signer) {
|
||||
@@ -95,20 +100,20 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
// We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
|
||||
$uri = str_replace('&', '&', $uri);
|
||||
|
||||
$template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
|
||||
$template = $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();
|
||||
$attributes = isset($options['attributes']) && \is_array($options['attributes']) ? $options['attributes'] : [];
|
||||
if (isset($options['id']) && $options['id']) {
|
||||
$attributes['id'] = $options['id'];
|
||||
}
|
||||
$renderedAttributes = '';
|
||||
if (\count($attributes) > 0) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
$flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
$renderedAttributes .= sprintf(
|
||||
' %s="%s"',
|
||||
@@ -132,22 +137,23 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
}
|
||||
|
||||
$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);
|
||||
if (1 === Environment::MAJOR_VERSION && !$loader instanceof ExistsLoaderInterface) {
|
||||
try {
|
||||
if ($loader instanceof SourceContextLoaderInterface) {
|
||||
$loader->getSourceContext($template);
|
||||
} else {
|
||||
$loader->getSource($template);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (LoaderError $e) {
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (LoaderError $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $loader->exists($template);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,14 +11,15 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Fragment;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\HttpCache\SubRequestHandler;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel.
|
||||
@@ -33,7 +34,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
*
|
||||
* * alt: an alternative URI to render in case of an error
|
||||
*/
|
||||
public function render($uri, Request $request, array $options = array())
|
||||
public function render($uri, Request $request, array $options = [])
|
||||
{
|
||||
$reference = null;
|
||||
if ($uri instanceof ControllerReference) {
|
||||
@@ -54,10 +55,10 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
// want that as we want to preserve objects (so we manually set Request attributes
|
||||
// below instead)
|
||||
$attributes = $reference->attributes;
|
||||
$reference->attributes = array();
|
||||
$reference->attributes = [];
|
||||
|
||||
// The request format and locale might have been overridden by the user
|
||||
foreach (array('_format', '_locale') as $key) {
|
||||
foreach (['_format', '_locale'] as $key) {
|
||||
if (isset($attributes[$key])) {
|
||||
$reference->attributes[$key] = $attributes[$key];
|
||||
}
|
||||
@@ -80,11 +81,11 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
return SubRequestHandler::handle($this->kernel, $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
|
||||
// the response that comes back is ignored
|
||||
if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
|
||||
$event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
|
||||
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
|
||||
|
||||
$this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
|
||||
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
|
||||
}
|
||||
|
||||
// let's clean up the output buffers that were created by the sub-request
|
||||
@@ -113,7 +114,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
unset($server['HTTP_IF_MODIFIED_SINCE']);
|
||||
unset($server['HTTP_IF_NONE_MATCH']);
|
||||
|
||||
$subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
|
||||
$subRequest = Request::create($uri, 'get', [], $cookies, [], $server);
|
||||
if ($request->headers->has('Surrogate-Capability')) {
|
||||
$subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
|
||||
}
|
||||
@@ -121,7 +122,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
static $setSession;
|
||||
|
||||
if (null === $setSession) {
|
||||
$setSession = \Closure::bind(function ($subRequest, $request) { $subRequest->session = $request->session; }, null, Request::class);
|
||||
$setSession = \Closure::bind(static function ($subRequest, $request) { $subRequest->session = $request->session; }, null, Request::class);
|
||||
}
|
||||
$setSession($subRequest, $request);
|
||||
|
||||
|
@@ -39,10 +39,8 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
|
||||
/**
|
||||
* 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
|
||||
* @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
|
||||
*/
|
||||
@@ -77,12 +75,12 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
|
||||
return $request->getBaseUrl().$path;
|
||||
}
|
||||
|
||||
private function checkNonScalar($values)
|
||||
private function checkNonScalar(array $values)
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
if (\is_array($value)) {
|
||||
$this->checkNonScalar($value);
|
||||
} elseif (!is_scalar($value) && null !== $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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user