|
0
|
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\DependencyInjection\Loader; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Config\Resource\FileResource; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* PhpFileLoader loads service definitions from a PHP file. |
|
|
18 |
* |
|
|
19 |
* The PHP file is required and the $container variable can be |
|
|
20 |
* used form the file to change the container. |
|
|
21 |
* |
|
|
22 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
23 |
*/ |
|
|
24 |
class PhpFileLoader extends FileLoader |
|
|
25 |
{ |
|
|
26 |
/** |
|
|
27 |
* Loads a PHP file. |
|
|
28 |
* |
|
|
29 |
* @param mixed $file The resource |
|
|
30 |
* @param string $type The resource type |
|
|
31 |
*/ |
|
|
32 |
public function load($file, $type = null) |
|
|
33 |
{ |
|
|
34 |
// the container and loader variables are exposed to the included file below |
|
|
35 |
$container = $this->container; |
|
|
36 |
$loader = $this; |
|
|
37 |
|
|
|
38 |
$path = $this->locator->locate($file); |
|
|
39 |
$this->setCurrentDir(dirname($path)); |
|
|
40 |
$this->container->addResource(new FileResource($path)); |
|
|
41 |
|
|
|
42 |
include $path; |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
/** |
|
|
46 |
* Returns true if this class supports the given resource. |
|
|
47 |
* |
|
|
48 |
* @param mixed $resource A resource |
|
|
49 |
* @param string $type The resource type |
|
|
50 |
* |
|
|
51 |
* @return Boolean true if this class supports the given resource, false otherwise |
|
|
52 |
*/ |
|
|
53 |
public function supports($resource, $type = null) |
|
|
54 |
{ |
|
|
55 |
return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION); |
|
|
56 |
} |
|
|
57 |
} |