4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Loader;
14 use Symfony\Component\Config\Loader\FileLoader;
15 use Symfony\Component\Config\Resource\FileResource;
16 use Symfony\Component\Routing\RouteCollection;
19 * PhpFileLoader loads routes from a PHP file.
21 * The file must return a RouteCollection instance.
23 * @author Fabien Potencier <fabien@symfony.com>
25 class PhpFileLoader extends FileLoader
30 * @param string $file A PHP file path
31 * @param string|null $type The resource type
33 * @return RouteCollection A RouteCollection instance
35 public function load($file, $type = null)
37 $path = $this->locator->locate($file);
38 $this->setCurrentDir(dirname($path));
40 $collection = self::includeFile($path, $this);
41 $collection->addResource(new FileResource($path));
49 public function supports($resource, $type = null)
51 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
55 * Safe include. Used for scope isolation.
57 * @param string $file File to include
58 * @param PhpFileLoader $loader the loader variable is exposed to the included file below
60 * @return RouteCollection
62 private static function includeFile($file, PhpFileLoader $loader)