Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -66,7 +66,7 @@ class Router implements RouterInterface, RequestMatcherInterface
/**
* @var array
*/
protected $options = array();
protected $options = [];
/**
* @var LoggerInterface|null
@@ -81,7 +81,7 @@ class Router implements RouterInterface, RequestMatcherInterface
/**
* @var ExpressionFunctionProviderInterface[]
*/
private $expressionLanguageProviders = array();
private $expressionLanguageProviders = [];
/**
* @param LoaderInterface $loader A LoaderInterface instance
@@ -90,7 +90,7 @@ class Router implements RouterInterface, RequestMatcherInterface
* @param RequestContext $context The context
* @param LoggerInterface $logger A logger instance
*/
public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
public function __construct(LoaderInterface $loader, $resource, array $options = [], RequestContext $context = null, LoggerInterface $logger = null)
{
$this->loader = $loader;
$this->resource = $resource;
@@ -124,7 +124,7 @@ class Router implements RouterInterface, RequestMatcherInterface
*/
public function setOptions(array $options)
{
$this->options = array(
$this->options = [
'cache_dir' => null,
'debug' => false,
'generator_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
@@ -137,12 +137,12 @@ class Router implements RouterInterface, RequestMatcherInterface
'matcher_cache_class' => 'ProjectUrlMatcher',
'resource_type' => null,
'strict_requirements' => true,
);
];
// check option names and live merge, if errors are encountered Exception will be thrown
$invalid = array();
$invalid = [];
foreach ($options as $key => $value) {
if (array_key_exists($key, $this->options)) {
if (\array_key_exists($key, $this->options)) {
$this->options[$key] = $value;
} else {
$invalid[] = $key;
@@ -164,7 +164,7 @@ class Router implements RouterInterface, RequestMatcherInterface
*/
public function setOption($key, $value)
{
if (!array_key_exists($key, $this->options)) {
if (!\array_key_exists($key, $this->options)) {
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
}
@@ -182,7 +182,7 @@ class Router implements RouterInterface, RequestMatcherInterface
*/
public function getOption($key)
{
if (!array_key_exists($key, $this->options)) {
if (!\array_key_exists($key, $this->options)) {
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
}
@@ -235,7 +235,7 @@ class Router implements RouterInterface, RequestMatcherInterface
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
return $this->getGenerator()->generate($name, $parameters, $referenceType);
}
@@ -263,9 +263,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()
{
@@ -284,32 +284,29 @@ class Router implements RouterInterface, RequestMatcherInterface
return $this->matcher;
}
$class = $this->options['matcher_cache_class'];
$baseClass = $this->options['matcher_base_class'];
$expressionLanguageProviders = $this->expressionLanguageProviders;
$that = $this; // required for PHP 5.3 where "$this" cannot be use()d in anonymous functions. Change in Symfony 3.0.
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$class.'.php',
function (ConfigCacheInterface $cache) use ($that, $class, $baseClass, $expressionLanguageProviders) {
$dumper = $that->getMatcherDumperInstance();
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['matcher_cache_class'].'.php',
function (ConfigCacheInterface $cache) {
$dumper = $this->getMatcherDumperInstance();
if (method_exists($dumper, 'addExpressionLanguageProvider')) {
foreach ($expressionLanguageProviders as $provider) {
foreach ($this->expressionLanguageProviders as $provider) {
$dumper->addExpressionLanguageProvider($provider);
}
}
$options = array(
'class' => $class,
'base_class' => $baseClass,
);
$options = [
'class' => $this->options['matcher_cache_class'],
'base_class' => $this->options['matcher_base_class'],
];
$cache->write($dumper->dump($options), $that->getRouteCollection()->getResources());
$cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
}
);
require_once $cache->getPath();
if (!class_exists($this->options['matcher_cache_class'], false)) {
require_once $cache->getPath();
}
return $this->matcher = new $class($this->context);
return $this->matcher = new $this->options['matcher_cache_class']($this->context);
}
/**
@@ -326,25 +323,24 @@ class Router implements RouterInterface, RequestMatcherInterface
if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
$this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->logger);
} else {
$class = $this->options['generator_cache_class'];
$baseClass = $this->options['generator_base_class'];
$that = $this; // required for PHP 5.3 where "$this" cannot be use()d in anonymous functions. Change in Symfony 3.0.
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$class.'.php',
function (ConfigCacheInterface $cache) use ($that, $class, $baseClass) {
$dumper = $that->getGeneratorDumperInstance();
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['generator_cache_class'].'.php',
function (ConfigCacheInterface $cache) {
$dumper = $this->getGeneratorDumperInstance();
$options = array(
'class' => $class,
'base_class' => $baseClass,
);
$options = [
'class' => $this->options['generator_cache_class'],
'base_class' => $this->options['generator_base_class'],
];
$cache->write($dumper->dump($options), $that->getRouteCollection()->getResources());
$cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
}
);
require_once $cache->getPath();
if (!class_exists($this->options['generator_cache_class'], false)) {
require_once $cache->getPath();
}
$this->generator = new $class($this->context, $this->logger);
$this->generator = new $this->options['generator_cache_class']($this->context, $this->logger);
}
if ($this->generator instanceof ConfigurableRequirementsInterface) {
@@ -360,25 +356,17 @@ class Router implements RouterInterface, RequestMatcherInterface
}
/**
* This method is public because it needs to be callable from a closure in PHP 5.3. It should be converted back to protected in 3.0.
*
* @internal
*
* @return GeneratorDumperInterface
*/
public function getGeneratorDumperInstance()
protected function getGeneratorDumperInstance()
{
return new $this->options['generator_dumper_class']($this->getRouteCollection());
}
/**
* This method is public because it needs to be callable from a closure in PHP 5.3. It should be converted back to protected in 3.0.
*
* @internal
*
* @return MatcherDumperInterface
*/
public function getMatcherDumperInstance()
protected function getMatcherDumperInstance()
{
return new $this->options['matcher_dumper_class']($this->getRouteCollection());
}