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>
27 class PhpFileLoader
extends FileLoader
32 * @param string $file A PHP file path
33 * @param string|null $type The resource type
35 * @return RouteCollection A RouteCollection instance
39 public function load($file, $type = null)
41 // the loader variable is exposed to the included file below
44 $path = $this->locator
->locate($file);
45 $this->setCurrentDir(dirname($path));
47 $collection = include $path;
48 $collection->addResource(new FileResource($path));
58 public function supports($resource, $type = null)
60 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION
) && (!$type || 'php' === $type);