b4ba5fbc7f8badedacc6eaa52c94a8d6fecf3071
[yaffs-website] / vendor / symfony / routing / Loader / PhpFileLoader.php
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\RouteCollection;
17
18 /**
19  * PhpFileLoader loads routes from a PHP file.
20  *
21  * The file must return a RouteCollection instance.
22  *
23  * @author Fabien Potencier <fabien@symfony.com>
24  */
25 class PhpFileLoader extends FileLoader
26 {
27     /**
28      * Loads a PHP file.
29      *
30      * @param string      $file A PHP file path
31      * @param string|null $type The resource type
32      *
33      * @return RouteCollection A RouteCollection instance
34      */
35     public function load($file, $type = null)
36     {
37         $path = $this->locator->locate($file);
38         $this->setCurrentDir(dirname($path));
39
40         $collection = self::includeFile($path, $this);
41         $collection->addResource(new FileResource($path));
42
43         return $collection;
44     }
45
46     /**
47      * {@inheritdoc}
48      */
49     public function supports($resource, $type = null)
50     {
51         return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
52     }
53
54     /**
55      * Safe include. Used for scope isolation.
56      *
57      * @param string        $file   File to include
58      * @param PhpFileLoader $loader the loader variable is exposed to the included file below
59      *
60      * @return RouteCollection
61      */
62     private static function includeFile($file, PhpFileLoader $loader)
63     {
64         return include $file;
65     }
66 }