annotate vendor/symfony/dependency-injection/Loader/PhpFileLoader.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\DependencyInjection\Loader;
Chris@0 13
Chris@14 14 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Chris@0 15
Chris@0 16 /**
Chris@0 17 * PhpFileLoader loads service definitions from a PHP file.
Chris@0 18 *
Chris@0 19 * The PHP file is required and the $container variable can be
Chris@0 20 * used within the file to change the container.
Chris@0 21 *
Chris@0 22 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 23 */
Chris@0 24 class PhpFileLoader extends FileLoader
Chris@0 25 {
Chris@0 26 /**
Chris@0 27 * {@inheritdoc}
Chris@0 28 */
Chris@0 29 public function load($resource, $type = null)
Chris@0 30 {
Chris@0 31 // the container and loader variables are exposed to the included file below
Chris@0 32 $container = $this->container;
Chris@0 33 $loader = $this;
Chris@0 34
Chris@0 35 $path = $this->locator->locate($resource);
Chris@17 36 $this->setCurrentDir(\dirname($path));
Chris@14 37 $this->container->fileExists($path);
Chris@0 38
Chris@14 39 // the closure forbids access to the private scope in the included file
Chris@14 40 $load = \Closure::bind(function ($path) use ($container, $loader, $resource, $type) {
Chris@14 41 return include $path;
Chris@14 42 }, $this, ProtectedPhpFileLoader::class);
Chris@14 43
Chris@14 44 $callback = $load($path);
Chris@14 45
Chris@14 46 if ($callback instanceof \Closure) {
Chris@14 47 $callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this);
Chris@14 48 }
Chris@0 49 }
Chris@0 50
Chris@0 51 /**
Chris@0 52 * {@inheritdoc}
Chris@0 53 */
Chris@0 54 public function supports($resource, $type = null)
Chris@0 55 {
Chris@17 56 if (!\is_string($resource)) {
Chris@14 57 return false;
Chris@14 58 }
Chris@14 59
Chris@14 60 if (null === $type && 'php' === pathinfo($resource, PATHINFO_EXTENSION)) {
Chris@14 61 return true;
Chris@14 62 }
Chris@14 63
Chris@14 64 return 'php' === $type;
Chris@0 65 }
Chris@0 66 }
Chris@14 67
Chris@14 68 /**
Chris@14 69 * @internal
Chris@14 70 */
Chris@14 71 final class ProtectedPhpFileLoader extends PhpFileLoader
Chris@14 72 {
Chris@14 73 }