f0be7534ea67d4f21dc2c0e856d83c982eff818c
[yaffs-website] / vendor / symfony / dependency-injection / 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\DependencyInjection\Loader;
13
14 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
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 within the file to change the container.
21  *
22  * @author Fabien Potencier <fabien@symfony.com>
23  */
24 class PhpFileLoader extends FileLoader
25 {
26     /**
27      * {@inheritdoc}
28      */
29     public function load($resource, $type = null)
30     {
31         // the container and loader variables are exposed to the included file below
32         $container = $this->container;
33         $loader = $this;
34
35         $path = $this->locator->locate($resource);
36         $this->setCurrentDir(dirname($path));
37         $this->container->fileExists($path);
38
39         // the closure forbids access to the private scope in the included file
40         $load = \Closure::bind(function ($path) use ($container, $loader, $resource, $type) {
41             return include $path;
42         }, $this, ProtectedPhpFileLoader::class);
43
44         $callback = $load($path);
45
46         if ($callback instanceof \Closure) {
47             $callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this);
48         }
49     }
50
51     /**
52      * {@inheritdoc}
53      */
54     public function supports($resource, $type = null)
55     {
56         if (!is_string($resource)) {
57             return false;
58         }
59
60         if (null === $type && 'php' === pathinfo($resource, PATHINFO_EXTENSION)) {
61             return true;
62         }
63
64         return 'php' === $type;
65     }
66 }
67
68 /**
69  * @internal
70  */
71 final class ProtectedPhpFileLoader extends PhpFileLoader
72 {
73 }