vendor/symfony/src/Symfony/Component/Routing/Loader/PhpFileLoader.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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\Resource\FileResource;
       
    15 use Symfony\Component\Config\Loader\FileLoader;
       
    16 
       
    17 /**
       
    18  * PhpFileLoader loads routes from a PHP file.
       
    19  *
       
    20  * The file must return a RouteCollection instance.
       
    21  *
       
    22  * @author Fabien Potencier <fabien@symfony.com>
       
    23  *
       
    24  * @api
       
    25  */
       
    26 class PhpFileLoader extends FileLoader
       
    27 {
       
    28     /**
       
    29      * Loads a PHP file.
       
    30      *
       
    31      * @param mixed  $file A PHP file path
       
    32      * @param string $type The resource type
       
    33      *
       
    34      * @api
       
    35      */
       
    36     public function load($file, $type = null)
       
    37     {
       
    38         // the loader variable is exposed to the included file below
       
    39         $loader = $this;
       
    40 
       
    41         $path = $this->locator->locate($file);
       
    42         $this->setCurrentDir(dirname($path));
       
    43 
       
    44         $collection = include $path;
       
    45         $collection->addResource(new FileResource($path));
       
    46 
       
    47         return $collection;
       
    48     }
       
    49 
       
    50     /**
       
    51      * Returns true if this class supports the given resource.
       
    52      *
       
    53      * @param mixed  $resource A resource
       
    54      * @param string $type     The resource type
       
    55      *
       
    56      * @return Boolean True if this class supports the given resource, false otherwise
       
    57      *
       
    58      * @api
       
    59      */
       
    60     public function supports($resource, $type = null)
       
    61     {
       
    62         return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
       
    63     }
       
    64 }