comparison vendor/symfony/routing/Router.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\Routing; 12 namespace Symfony\Component\Routing;
13 13
14 use Psr\Log\LoggerInterface;
15 use Symfony\Component\Config\ConfigCacheFactory;
16 use Symfony\Component\Config\ConfigCacheFactoryInterface;
17 use Symfony\Component\Config\ConfigCacheInterface;
14 use Symfony\Component\Config\Loader\LoaderInterface; 18 use Symfony\Component\Config\Loader\LoaderInterface;
15 use Symfony\Component\Config\ConfigCacheInterface; 19 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16 use Symfony\Component\Config\ConfigCacheFactoryInterface; 20 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\Config\ConfigCacheFactory;
18 use Psr\Log\LoggerInterface;
19 use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface; 21 use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
22 use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
20 use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 23 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21 use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface; 24 use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
22 use Symfony\Component\Routing\Matcher\RequestMatcherInterface; 25 use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
23 use Symfony\Component\Routing\Matcher\UrlMatcherInterface; 26 use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
24 use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
25 use Symfony\Component\HttpFoundation\Request;
26 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
27 27
28 /** 28 /**
29 * The Router class is an example of the integration of all pieces of the 29 * The Router class is an example of the integration of all pieces of the
30 * routing system for easier use. 30 * routing system for easier use.
31 * 31 *
64 protected $resource; 64 protected $resource;
65 65
66 /** 66 /**
67 * @var array 67 * @var array
68 */ 68 */
69 protected $options = array(); 69 protected $options = [];
70 70
71 /** 71 /**
72 * @var LoggerInterface|null 72 * @var LoggerInterface|null
73 */ 73 */
74 protected $logger; 74 protected $logger;
79 private $configCacheFactory; 79 private $configCacheFactory;
80 80
81 /** 81 /**
82 * @var ExpressionFunctionProviderInterface[] 82 * @var ExpressionFunctionProviderInterface[]
83 */ 83 */
84 private $expressionLanguageProviders = array(); 84 private $expressionLanguageProviders = [];
85 85
86 /** 86 /**
87 * @param LoaderInterface $loader A LoaderInterface instance 87 * @param LoaderInterface $loader A LoaderInterface instance
88 * @param mixed $resource The main resource to load 88 * @param mixed $resource The main resource to load
89 * @param array $options An array of options 89 * @param array $options An array of options
90 * @param RequestContext $context The context 90 * @param RequestContext $context The context
91 * @param LoggerInterface $logger A logger instance 91 * @param LoggerInterface $logger A logger instance
92 */ 92 */
93 public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null) 93 public function __construct(LoaderInterface $loader, $resource, array $options = [], RequestContext $context = null, LoggerInterface $logger = null)
94 { 94 {
95 $this->loader = $loader; 95 $this->loader = $loader;
96 $this->resource = $resource; 96 $this->resource = $resource;
97 $this->logger = $logger; 97 $this->logger = $logger;
98 $this->context = $context ?: new RequestContext(); 98 $this->context = $context ?: new RequestContext();
122 * 122 *
123 * @throws \InvalidArgumentException When unsupported option is provided 123 * @throws \InvalidArgumentException When unsupported option is provided
124 */ 124 */
125 public function setOptions(array $options) 125 public function setOptions(array $options)
126 { 126 {
127 $this->options = array( 127 $this->options = [
128 'cache_dir' => null, 128 'cache_dir' => null,
129 'debug' => false, 129 'debug' => false,
130 'generator_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', 130 'generator_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
131 'generator_base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', 131 'generator_base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
132 'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper', 132 'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper',
135 'matcher_base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', 135 'matcher_base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
136 'matcher_dumper_class' => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper', 136 'matcher_dumper_class' => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper',
137 'matcher_cache_class' => 'ProjectUrlMatcher', 137 'matcher_cache_class' => 'ProjectUrlMatcher',
138 'resource_type' => null, 138 'resource_type' => null,
139 'strict_requirements' => true, 139 'strict_requirements' => true,
140 ); 140 ];
141 141
142 // check option names and live merge, if errors are encountered Exception will be thrown 142 // check option names and live merge, if errors are encountered Exception will be thrown
143 $invalid = array(); 143 $invalid = [];
144 foreach ($options as $key => $value) { 144 foreach ($options as $key => $value) {
145 if (array_key_exists($key, $this->options)) { 145 if (array_key_exists($key, $this->options)) {
146 $this->options[$key] = $value; 146 $this->options[$key] = $value;
147 } else { 147 } else {
148 $invalid[] = $key; 148 $invalid[] = $key;
233 } 233 }
234 234
235 /** 235 /**
236 * {@inheritdoc} 236 * {@inheritdoc}
237 */ 237 */
238 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) 238 public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
239 { 239 {
240 return $this->getGenerator()->generate($name, $parameters, $referenceType); 240 return $this->getGenerator()->generate($name, $parameters, $referenceType);
241 } 241 }
242 242
243 /** 243 /**
291 foreach ($this->expressionLanguageProviders as $provider) { 291 foreach ($this->expressionLanguageProviders as $provider) {
292 $dumper->addExpressionLanguageProvider($provider); 292 $dumper->addExpressionLanguageProvider($provider);
293 } 293 }
294 } 294 }
295 295
296 $options = array( 296 $options = [
297 'class' => $this->options['matcher_cache_class'], 297 'class' => $this->options['matcher_cache_class'],
298 'base_class' => $this->options['matcher_base_class'], 298 'base_class' => $this->options['matcher_base_class'],
299 ); 299 ];
300 300
301 $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources()); 301 $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
302 } 302 }
303 ); 303 );
304 304
325 } else { 325 } else {
326 $cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['generator_cache_class'].'.php', 326 $cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['generator_cache_class'].'.php',
327 function (ConfigCacheInterface $cache) { 327 function (ConfigCacheInterface $cache) {
328 $dumper = $this->getGeneratorDumperInstance(); 328 $dumper = $this->getGeneratorDumperInstance();
329 329
330 $options = array( 330 $options = [
331 'class' => $this->options['generator_cache_class'], 331 'class' => $this->options['generator_cache_class'],
332 'base_class' => $this->options['generator_base_class'], 332 'base_class' => $this->options['generator_base_class'],
333 ); 333 ];
334 334
335 $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources()); 335 $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
336 } 336 }
337 ); 337 );
338 338
373 373
374 /** 374 /**
375 * Provides the ConfigCache factory implementation, falling back to a 375 * Provides the ConfigCache factory implementation, falling back to a
376 * default implementation if necessary. 376 * default implementation if necessary.
377 * 377 *
378 * @return ConfigCacheFactoryInterface $configCacheFactory 378 * @return ConfigCacheFactoryInterface
379 */ 379 */
380 private function getConfigCacheFactory() 380 private function getConfigCacheFactory()
381 { 381 {
382 if (null === $this->configCacheFactory) { 382 if (null === $this->configCacheFactory) {
383 $this->configCacheFactory = new ConfigCacheFactory($this->options['debug']); 383 $this->configCacheFactory = new ConfigCacheFactory($this->options['debug']);