mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-02 13:09:53 +09:00
Update to laravel 7
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)
|
||||
{
|
||||
@@ -73,26 +71,19 @@ 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.');
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -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.
|
||||
@@ -33,9 +34,8 @@ class FragmentHandler
|
||||
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 = [], bool $debug = false)
|
||||
{
|
||||
@@ -61,16 +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 array $options An array of options
|
||||
* @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;
|
||||
@@ -100,7 +98,8 @@ 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()));
|
||||
$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) {
|
||||
@@ -108,5 +107,7 @@ class FragmentHandler
|
||||
}
|
||||
|
||||
$response->sendContent();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,16 @@ 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
|
||||
* @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();
|
||||
}
|
||||
|
||||
93
vendor/symfony/http-kernel/Fragment/FragmentUriGenerator.php
vendored
Normal file
93
vendor/symfony/http-kernel/Fragment/FragmentUriGenerator.php
vendored
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
vendor/symfony/http-kernel/Fragment/FragmentUriGeneratorInterface.php
vendored
Normal file
32
vendor/symfony/http-kernel/Fragment/FragmentUriGeneratorInterface.php
vendored
Normal 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;
|
||||
}
|
||||
@@ -15,10 +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;
|
||||
|
||||
/**
|
||||
* Implements the Hinclude rendering strategy.
|
||||
@@ -29,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 UriSigner $signer A UriSigner instance
|
||||
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
|
||||
* @param string $charset
|
||||
* @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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,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('&', '&', $uri);
|
||||
|
||||
$template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
|
||||
if (null !== $this->templating && $template && $this->templateExists($template)) {
|
||||
$content = $this->templating->render($template);
|
||||
$template = $options['default'] ?? $this->globalDefaultTemplate;
|
||||
if (null !== $this->twig && $template && $this->twig->getLoader()->exists($template)) {
|
||||
$content = $this->twig->render($template);
|
||||
} else {
|
||||
$content = $template;
|
||||
}
|
||||
@@ -112,7 +81,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
}
|
||||
$renderedAttributes = '';
|
||||
if (\count($attributes) > 0) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
$flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
$renderedAttributes .= sprintf(
|
||||
' %s="%s"',
|
||||
@@ -125,35 +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 ($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}
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
@@ -122,7 +121,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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -39,52 +40,13 @@ 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
|
||||
* @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($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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user