Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Routing\Loader;
13
 
14
use Symfony\Component\Config\Loader\FileLoader;
15
use Symfony\Component\Config\Resource\FileResource;
16
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
17
use Symfony\Component\Routing\RouteCollection;
18
 
19
/**
20
 * PhpFileLoader loads routes from a PHP file.
21
 *
22
 * The file must return a RouteCollection instance.
23
 *
24
 * @author Fabien Potencier <fabien@symfony.com>
25
 * @author Nicolas grekas <p@tchwork.com>
26
 * @author Jules Pietri <jules@heahprod.com>
27
 */
28
class PhpFileLoader extends FileLoader
29
{
30
    /**
31
     * Loads a PHP file.
32
     */
33
    public function load(mixed $file, string $type = null): RouteCollection
34
    {
35
        $path = $this->locator->locate($file);
36
        $this->setCurrentDir(\dirname($path));
37
 
38
        // the closure forbids access to the private scope in the included file
39
        $loader = $this;
40
        $load = \Closure::bind(static function ($file) use ($loader) {
41
            return include $file;
42
        }, null, ProtectedPhpFileLoader::class);
43
 
44
        $result = $load($path);
45
 
46
        if (\is_object($result) && \is_callable($result)) {
47
            $collection = $this->callConfigurator($result, $path, $file);
48
        } else {
49
            $collection = $result;
50
        }
51
 
52
        $collection->addResource(new FileResource($path));
53
 
54
        return $collection;
55
    }
56
 
57
    public function supports(mixed $resource, string $type = null): bool
58
    {
59
        return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'php' === $type);
60
    }
61
 
62
    protected function callConfigurator(callable $result, string $path, string $file): RouteCollection
63
    {
64
        $collection = new RouteCollection();
65
 
66
        $result(new RoutingConfigurator($collection, $this, $path, $file, $this->env));
67
 
68
        return $collection;
69
    }
70
}
71
 
72
/**
73
 * @internal
74
 */
75
final class ProtectedPhpFileLoader extends PhpFileLoader
76
{
77
}