12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace Symfony\Component\Routing\Loader;
- use Symfony\Component\Config\Loader\FileLoader;
- use Symfony\Component\Config\Resource\FileResource;
- use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
- use Symfony\Component\Routing\RouteCollection;
- class PhpFileLoader extends FileLoader
- {
-
- public function load($file, string $type = null)
- {
- $path = $this->locator->locate($file);
- $this->setCurrentDir(\dirname($path));
-
- $loader = $this;
- $load = \Closure::bind(static function ($file) use ($loader) {
- return include $file;
- }, null, ProtectedPhpFileLoader::class);
- $result = $load($path);
- if (\is_object($result) && \is_callable($result)) {
- $collection = $this->callConfigurator($result, $path, $file);
- } else {
- $collection = $result;
- }
- $collection->addResource(new FileResource($path));
- return $collection;
- }
-
- public function supports($resource, string $type = null)
- {
- return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'php' === $type);
- }
- protected function callConfigurator(callable $result, string $path, string $file): RouteCollection
- {
- $collection = new RouteCollection();
- $result(new RoutingConfigurator($collection, $this, $path, $file, $this->env));
- return $collection;
- }
- }
- final class ProtectedPhpFileLoader extends PhpFileLoader
- {
- }
|