upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -83,14 +83,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
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.');
}
// 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()));
return (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request);
}
private function containsNonScalars(array $values): bool

View File

@@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
* Renders a URI that represents a resource fragment.
@@ -60,15 +61,14 @@ class FragmentHandler
*
* * 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 string|ControllerReference $uri A URI as a string or a ControllerReference instance
*
* @return string|null The Response content or null when the Response is streamed
* @return string|null
*
* @throws \InvalidArgumentException when the renderer does not exist
* @throws \LogicException when no master request is being handled
* @throws \LogicException when no main request is being handled
*/
public function render($uri, $renderer = 'inline', array $options = [])
public function render($uri, string $renderer = 'inline', array $options = [])
{
if (!isset($options['ignore_errors'])) {
$options['ignore_errors'] = !$this->debug;
@@ -98,7 +98,8 @@ class FragmentHandler
protected function deliver(Response $response)
{
if (!$response->isSuccessful()) {
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
$responseStatusCode = $response->getStatusCode();
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $responseStatusCode), 0, new HttpException($responseStatusCode));
}
if (!$response instanceof StreamedResponse) {

View File

@@ -27,14 +27,14 @@ interface FragmentRendererInterface
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
*
* @return Response A Response instance
* @return Response
*/
public function render($uri, Request $request, array $options = []);
/**
* Gets the name of the strategy.
*
* @return string The strategy name
* @return string
*/
public function getName();
}

View File

@@ -0,0 +1,93 @@
<?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\RequestStack;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\UriSigner;
/**
* Generates a fragment URI.
*
* @author Kévin Dunglas <kevin@dunglas.fr>
* @author Fabien Potencier <fabien@symfony.com>
*/
final class FragmentUriGenerator implements FragmentUriGeneratorInterface
{
private $fragmentPath;
private $signer;
private $requestStack;
public function __construct(string $fragmentPath, UriSigner $signer = null, RequestStack $requestStack = null)
{
$this->fragmentPath = $fragmentPath;
$this->signer = $signer;
$this->requestStack = $requestStack;
}
/**
* {@inheritDoc}
*/
public function generate(ControllerReference $controller, Request $request = null, bool $absolute = false, bool $strict = true, bool $sign = true): string
{
if (null === $request && (null === $this->requestStack || null === $request = $this->requestStack->getCurrentRequest())) {
throw new \LogicException('Generating a fragment URL can only be done when handling a Request.');
}
if ($sign && null === $this->signer) {
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
}
if ($strict) {
$this->checkNonScalar($controller->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($controller->attributes['_format'])) {
$controller->attributes['_format'] = $request->getRequestFormat();
}
if (!isset($controller->attributes['_locale'])) {
$controller->attributes['_locale'] = $request->getLocale();
}
$controller->attributes['_controller'] = $controller->controller;
$controller->query['_path'] = http_build_query($controller->attributes, '', '&');
$path = $this->fragmentPath.'?'.http_build_query($controller->query, '', '&');
// we need to sign the absolute URI, but want to return the path only.
$fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl().$path;
if (!$sign) {
return $fragmentUri;
}
$fragmentUri = $this->signer->sign($fragmentUri);
return $absolute ? $fragmentUri : substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
}
private function checkNonScalar(array $values): void
{
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));
}
}
}
}

View File

@@ -0,0 +1,32 @@
<?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;
/**
* Interface implemented by rendering strategies able to generate an URL for a fragment.
*
* @author Kévin Dunglas <kevin@dunglas.fr>
*/
interface FragmentUriGeneratorInterface
{
/**
* Generates a fragment URI for a given controller.
*
* @param bool $absolute Whether to generate an absolute URL or not
* @param bool $strict Whether to allow non-scalar attributes or not
* @param bool $sign Whether to sign the URL or not
*/
public function generate(ControllerReference $controller, Request $request = null, bool $absolute = false, bool $strict = true, bool $sign = true): string;
}

View File

@@ -15,11 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\UriSigner;
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.
@@ -30,51 +26,28 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
{
private $globalDefaultTemplate;
private $signer;
private $templating;
private $twig;
private $charset;
/**
* @param EngineInterface|Environment $templating An EngineInterface or a Twig instance
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
*/
public function __construct($templating = null, UriSigner $signer = null, string $globalDefaultTemplate = null, string $charset = 'utf-8')
public function __construct(Environment $twig = null, UriSigner $signer = null, string $globalDefaultTemplate = null, string $charset = 'utf-8')
{
$this->setTemplating($templating);
$this->twig = $twig;
$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
*
* @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.');
}
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;
}
/**
* Checks if a templating engine has been set.
*
* @return bool true if the templating engine has been set, false otherwise
* @return bool
*/
public function hasTemplating()
{
return null !== $this->templating;
return null !== $this->twig;
}
/**
@@ -89,20 +62,15 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
public function render($uri, Request $request, array $options = [])
{
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()));
$uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request);
}
// 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 = $options['default'] ?? $this->globalDefaultTemplate;
if (null !== $this->templating && $template && $this->templateExists($template)) {
$content = $this->templating->render($template);
if (null !== $this->twig && $template && $this->twig->getLoader()->exists($template)) {
$content = $this->twig->render($template);
} else {
$content = $template;
}
@@ -126,36 +94,6 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
}
private function templateExists(string $template): bool
{
if ($this->templating instanceof EngineInterface) {
try {
return $this->templating->exists($template);
} catch (\Exception $e) {
return false;
}
}
$loader = $this->templating->getLoader();
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 false;
}
return $loader->exists($template);
}
/**
* {@inheritdoc}
*/

View File

@@ -11,7 +11,6 @@
namespace Symfony\Component\HttpKernel\Fragment;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
@@ -34,7 +33,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null)
{
$this->kernel = $kernel;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
$this->dispatcher = $dispatcher;
}
/**
@@ -106,7 +105,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
}
}
protected function createSubRequest($uri, Request $request)
protected function createSubRequest(string $uri, Request $request)
{
$cookies = $request->cookies->all();
$server = $request->server->all();

View File

@@ -22,16 +22,17 @@ use Symfony\Component\HttpKernel\EventListener\FragmentListener;
*/
abstract class RoutableFragmentRenderer implements FragmentRendererInterface
{
private $fragmentPath = '/_fragment';
/**
* @internal
*/
protected $fragmentPath = '/_fragment';
/**
* Sets the fragment path that triggers the fragment listener.
*
* @param string $path The path
*
* @see FragmentListener
*/
public function setFragmentPath($path)
public function setFragmentPath(string $path)
{
$this->fragmentPath = $path;
}
@@ -42,47 +43,10 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
* @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
* @return string
*/
protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false, $strict = true)
protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $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(array $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));
}
}
return (new FragmentUriGenerator($this->fragmentPath))->generate($reference, $request, $absolute, $strict, false);
}
}