Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Loader; Chris@0: Chris@14: use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; Chris@0: Chris@0: /** Chris@0: * PhpFileLoader loads service definitions from a PHP file. Chris@0: * Chris@0: * The PHP file is required and the $container variable can be Chris@0: * used within the file to change the container. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class PhpFileLoader extends FileLoader Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function load($resource, $type = null) Chris@0: { Chris@0: // the container and loader variables are exposed to the included file below Chris@0: $container = $this->container; Chris@0: $loader = $this; Chris@0: Chris@0: $path = $this->locator->locate($resource); Chris@17: $this->setCurrentDir(\dirname($path)); Chris@14: $this->container->fileExists($path); Chris@0: Chris@14: // the closure forbids access to the private scope in the included file Chris@14: $load = \Closure::bind(function ($path) use ($container, $loader, $resource, $type) { Chris@14: return include $path; Chris@14: }, $this, ProtectedPhpFileLoader::class); Chris@14: Chris@14: $callback = $load($path); Chris@14: Chris@14: if ($callback instanceof \Closure) { Chris@14: $callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this); Chris@14: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supports($resource, $type = null) Chris@0: { Chris@17: if (!\is_string($resource)) { Chris@14: return false; Chris@14: } Chris@14: Chris@14: if (null === $type && 'php' === pathinfo($resource, PATHINFO_EXTENSION)) { Chris@14: return true; Chris@14: } Chris@14: Chris@14: return 'php' === $type; Chris@0: } Chris@0: } Chris@14: Chris@14: /** Chris@14: * @internal Chris@14: */ Chris@14: final class ProtectedPhpFileLoader extends PhpFileLoader Chris@14: { Chris@14: }