comparison vendor/symfony/dependency-injection/Loader/PhpFileLoader.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\DependencyInjection\Loader; 12 namespace Symfony\Component\DependencyInjection\Loader;
13 13
14 use Symfony\Component\Config\Resource\FileResource; 14 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
15 15
16 /** 16 /**
17 * PhpFileLoader loads service definitions from a PHP file. 17 * PhpFileLoader loads service definitions from a PHP file.
18 * 18 *
19 * The PHP file is required and the $container variable can be 19 * The PHP file is required and the $container variable can be
32 $container = $this->container; 32 $container = $this->container;
33 $loader = $this; 33 $loader = $this;
34 34
35 $path = $this->locator->locate($resource); 35 $path = $this->locator->locate($resource);
36 $this->setCurrentDir(dirname($path)); 36 $this->setCurrentDir(dirname($path));
37 $this->container->addResource(new FileResource($path)); 37 $this->container->fileExists($path);
38 38
39 include $path; 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 }
40 } 49 }
41 50
42 /** 51 /**
43 * {@inheritdoc} 52 * {@inheritdoc}
44 */ 53 */
45 public function supports($resource, $type = null) 54 public function supports($resource, $type = null)
46 { 55 {
47 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION); 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;
48 } 65 }
49 } 66 }
67
68 /**
69 * @internal
70 */
71 final class ProtectedPhpFileLoader extends PhpFileLoader
72 {
73 }