mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-03 13:40:00 +09:00
Update to laravel 7
This commit is contained in:
124
vendor/symfony/routing/Router.php
vendored
124
vendor/symfony/routing/Router.php
vendored
@@ -12,7 +12,6 @@
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
|
||||
use Symfony\Component\Config\ConfigCacheFactory;
|
||||
use Symfony\Component\Config\ConfigCacheFactoryInterface;
|
||||
use Symfony\Component\Config\ConfigCacheInterface;
|
||||
@@ -23,13 +22,11 @@ use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
|
||||
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
|
||||
use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper;
|
||||
use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Routing\Matcher\CompiledUrlMatcher;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
|
||||
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
||||
|
||||
/**
|
||||
@@ -95,19 +92,17 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
*/
|
||||
private $expressionLanguageProviders = [];
|
||||
|
||||
private static $cache = [];
|
||||
|
||||
/**
|
||||
* @param LoaderInterface $loader A LoaderInterface instance
|
||||
* @param mixed $resource The main resource to load
|
||||
* @param array $options An array of options
|
||||
* @param RequestContext $context The context
|
||||
* @param LoggerInterface $logger A logger instance
|
||||
* @param mixed $resource The main resource to load
|
||||
*/
|
||||
public function __construct(LoaderInterface $loader, $resource, array $options = [], RequestContext $context = null, LoggerInterface $logger = null, string $defaultLocale = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->resource = $resource;
|
||||
$this->logger = $logger;
|
||||
$this->context = $context ?: new RequestContext();
|
||||
$this->context = $context ?? new RequestContext();
|
||||
$this->setOptions($options);
|
||||
$this->defaultLocale = $defaultLocale;
|
||||
}
|
||||
@@ -127,8 +122,6 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
* * strict_requirements: Configure strict requirement checking for generators
|
||||
* implementing ConfigurableRequirementsInterface (default is true)
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @throws \InvalidArgumentException When unsupported option is provided
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
@@ -137,13 +130,9 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
'cache_dir' => null,
|
||||
'debug' => false,
|
||||
'generator_class' => CompiledUrlGenerator::class,
|
||||
'generator_base_class' => UrlGenerator::class, // deprecated
|
||||
'generator_dumper_class' => CompiledUrlGeneratorDumper::class,
|
||||
'generator_cache_class' => 'UrlGenerator', // deprecated
|
||||
'matcher_class' => CompiledUrlMatcher::class,
|
||||
'matcher_base_class' => UrlMatcher::class, // deprecated
|
||||
'matcher_dumper_class' => CompiledUrlMatcherDumper::class,
|
||||
'matcher_cache_class' => 'UrlMatcher', // deprecated
|
||||
'resource_type' => null,
|
||||
'strict_requirements' => true,
|
||||
];
|
||||
@@ -151,7 +140,6 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
// check option names and live merge, if errors are encountered Exception will be thrown
|
||||
$invalid = [];
|
||||
foreach ($options as $key => $value) {
|
||||
$this->checkDeprecatedOption($key);
|
||||
if (\array_key_exists($key, $this->options)) {
|
||||
$this->options[$key] = $value;
|
||||
} else {
|
||||
@@ -167,39 +155,32 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
/**
|
||||
* Sets an option.
|
||||
*
|
||||
* @param string $key The key
|
||||
* @param mixed $value The value
|
||||
* @param mixed $value The value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
public function setOption(string $key, $value)
|
||||
{
|
||||
if (!\array_key_exists($key, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
||||
}
|
||||
|
||||
$this->checkDeprecatedOption($key);
|
||||
|
||||
$this->options[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an option value.
|
||||
*
|
||||
* @param string $key The key
|
||||
*
|
||||
* @return mixed The value
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getOption($key)
|
||||
public function getOption(string $key)
|
||||
{
|
||||
if (!\array_key_exists($key, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
||||
}
|
||||
|
||||
$this->checkDeprecatedOption($key);
|
||||
|
||||
return $this->options[$key];
|
||||
}
|
||||
|
||||
@@ -249,7 +230,7 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
||||
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
return $this->getGenerator()->generate($name, $parameters, $referenceType);
|
||||
}
|
||||
@@ -257,7 +238,7 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function match($pathinfo)
|
||||
public function match(string $pathinfo)
|
||||
{
|
||||
return $this->getMatcher()->match($pathinfo);
|
||||
}
|
||||
@@ -277,9 +258,9 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UrlMatcher instance associated with this Router.
|
||||
* Gets the UrlMatcher or RequestMatcher instance associated with this Router.
|
||||
*
|
||||
* @return UrlMatcherInterface A UrlMatcherInterface instance
|
||||
* @return UrlMatcherInterface|RequestMatcherInterface
|
||||
*/
|
||||
public function getMatcher()
|
||||
{
|
||||
@@ -287,10 +268,9 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
return $this->matcher;
|
||||
}
|
||||
|
||||
$compiled = is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true) && (UrlMatcher::class === $this->options['matcher_base_class'] || RedirectableUrlMatcher::class === $this->options['matcher_base_class']);
|
||||
|
||||
if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
|
||||
if (null === $this->options['cache_dir']) {
|
||||
$routes = $this->getRouteCollection();
|
||||
$compiled = is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true);
|
||||
if ($compiled) {
|
||||
$routes = (new CompiledUrlMatcherDumper($routes))->getCompiledRoutes();
|
||||
}
|
||||
@@ -304,7 +284,7 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
return $this->matcher;
|
||||
}
|
||||
|
||||
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['matcher_cache_class'].'.php',
|
||||
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_matching_routes.php',
|
||||
function (ConfigCacheInterface $cache) {
|
||||
$dumper = $this->getMatcherDumperInstance();
|
||||
if (method_exists($dumper, 'addExpressionLanguageProvider')) {
|
||||
@@ -313,30 +293,17 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
}
|
||||
}
|
||||
|
||||
$options = [
|
||||
'class' => $this->options['matcher_cache_class'],
|
||||
'base_class' => $this->options['matcher_base_class'],
|
||||
];
|
||||
|
||||
$cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
|
||||
$cache->write($dumper->dump(), $this->getRouteCollection()->getResources());
|
||||
}
|
||||
);
|
||||
|
||||
if ($compiled) {
|
||||
return $this->matcher = new $this->options['matcher_class'](require $cache->getPath(), $this->context);
|
||||
}
|
||||
|
||||
if (!class_exists($this->options['matcher_cache_class'], false)) {
|
||||
require_once $cache->getPath();
|
||||
}
|
||||
|
||||
return $this->matcher = new $this->options['matcher_cache_class']($this->context);
|
||||
return $this->matcher = new $this->options['matcher_class'](self::getCompiledRoutes($cache->getPath()), $this->context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UrlGenerator instance associated with this Router.
|
||||
*
|
||||
* @return UrlGeneratorInterface A UrlGeneratorInterface instance
|
||||
* @return UrlGeneratorInterface
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
@@ -344,37 +311,26 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
return $this->generator;
|
||||
}
|
||||
|
||||
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true) && UrlGenerator::class === $this->options['generator_base_class'];
|
||||
|
||||
if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
|
||||
if (null === $this->options['cache_dir']) {
|
||||
$routes = $this->getRouteCollection();
|
||||
$aliases = [];
|
||||
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true);
|
||||
if ($compiled) {
|
||||
$routes = (new CompiledUrlGeneratorDumper($routes))->getCompiledRoutes();
|
||||
$generatorDumper = new CompiledUrlGeneratorDumper($routes);
|
||||
$routes = $generatorDumper->getCompiledRoutes();
|
||||
$aliases = $generatorDumper->getCompiledAliases();
|
||||
}
|
||||
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
|
||||
$this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale);
|
||||
} else {
|
||||
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['generator_cache_class'].'.php',
|
||||
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php',
|
||||
function (ConfigCacheInterface $cache) {
|
||||
$dumper = $this->getGeneratorDumperInstance();
|
||||
|
||||
$options = [
|
||||
'class' => $this->options['generator_cache_class'],
|
||||
'base_class' => $this->options['generator_base_class'],
|
||||
];
|
||||
|
||||
$cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
|
||||
$cache->write($dumper->dump(), $this->getRouteCollection()->getResources());
|
||||
}
|
||||
);
|
||||
|
||||
if ($compiled) {
|
||||
$this->generator = new $this->options['generator_class'](require $cache->getPath(), $this->context, $this->logger);
|
||||
} else {
|
||||
if (!class_exists($this->options['generator_cache_class'], false)) {
|
||||
require_once $cache->getPath();
|
||||
}
|
||||
|
||||
$this->generator = new $this->options['generator_cache_class']($this->context, $this->logger, $this->defaultLocale);
|
||||
}
|
||||
$this->generator = new $this->options['generator_class'](self::getCompiledRoutes($cache->getPath()), $this->context, $this->logger, $this->defaultLocale);
|
||||
}
|
||||
|
||||
if ($this->generator instanceof ConfigurableRequirementsInterface) {
|
||||
@@ -408,10 +364,8 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
/**
|
||||
* Provides the ConfigCache factory implementation, falling back to a
|
||||
* default implementation if necessary.
|
||||
*
|
||||
* @return ConfigCacheFactoryInterface
|
||||
*/
|
||||
private function getConfigCacheFactory()
|
||||
private function getConfigCacheFactory(): ConfigCacheFactoryInterface
|
||||
{
|
||||
if (null === $this->configCacheFactory) {
|
||||
$this->configCacheFactory = new ConfigCacheFactory($this->options['debug']);
|
||||
@@ -420,14 +374,20 @@ class Router implements RouterInterface, RequestMatcherInterface
|
||||
return $this->configCacheFactory;
|
||||
}
|
||||
|
||||
private function checkDeprecatedOption($key)
|
||||
private static function getCompiledRoutes(string $path): array
|
||||
{
|
||||
switch ($key) {
|
||||
case 'generator_base_class':
|
||||
case 'generator_cache_class':
|
||||
case 'matcher_base_class':
|
||||
case 'matcher_cache_class':
|
||||
@trigger_error(sprintf('Option "%s" given to router %s is deprecated since Symfony 4.3.', $key, static::class), E_USER_DEPRECATED);
|
||||
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOLEAN))) {
|
||||
self::$cache = null;
|
||||
}
|
||||
|
||||
if (null === self::$cache) {
|
||||
return require $path;
|
||||
}
|
||||
|
||||
if (isset(self::$cache[$path])) {
|
||||
return self::$cache[$path];
|
||||
}
|
||||
|
||||
return self::$cache[$path] = require $path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user