2010-07-18 10:26:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-07-18 10:26:47 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-07-18 10:26:47 +01:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-07-18 10:26:47 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Loader;
|
|
|
|
|
2017-08-08 18:11:20 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
|
|
|
|
2010-07-18 10:26:47 +01:00
|
|
|
/**
|
|
|
|
* PhpFileLoader loads service definitions from a PHP file.
|
|
|
|
*
|
|
|
|
* The PHP file is required and the $container variable can be
|
2013-09-14 15:21:59 +01:00
|
|
|
* used within the file to change the container.
|
2010-07-18 10:26:47 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-07-18 10:26:47 +01:00
|
|
|
*/
|
|
|
|
class PhpFileLoader extends FileLoader
|
|
|
|
{
|
|
|
|
/**
|
2014-10-13 20:09:32 +01:00
|
|
|
* {@inheritdoc}
|
2010-07-18 10:26:47 +01:00
|
|
|
*/
|
2014-10-13 20:09:32 +01:00
|
|
|
public function load($resource, $type = null)
|
2010-07-18 10:26:47 +01:00
|
|
|
{
|
2011-02-04 18:38:42 +00:00
|
|
|
// the container and loader variables are exposed to the included file below
|
|
|
|
$container = $this->container;
|
|
|
|
$loader = $this;
|
|
|
|
|
2014-10-13 20:09:32 +01:00
|
|
|
$path = $this->locator->locate($resource);
|
2018-07-05 12:24:53 +01:00
|
|
|
$this->setCurrentDir(\dirname($path));
|
2017-02-02 08:31:13 +00:00
|
|
|
$this->container->fileExists($path);
|
2010-07-18 10:26:47 +01:00
|
|
|
|
2017-08-08 18:11:20 +01:00
|
|
|
// the closure forbids access to the private scope in the included file
|
|
|
|
$load = \Closure::bind(function ($path) use ($container, $loader, $resource, $type) {
|
|
|
|
return include $path;
|
|
|
|
}, $this, ProtectedPhpFileLoader::class);
|
|
|
|
|
|
|
|
$callback = $load($path);
|
|
|
|
|
|
|
|
if ($callback instanceof \Closure) {
|
|
|
|
$callback(new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource), $this->container, $this);
|
|
|
|
}
|
2010-07-18 10:26:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-13 20:09:32 +01:00
|
|
|
* {@inheritdoc}
|
2010-07-18 10:26:47 +01:00
|
|
|
*/
|
2011-02-10 15:15:51 +00:00
|
|
|
public function supports($resource, $type = null)
|
2010-07-18 10:26:47 +01:00
|
|
|
{
|
2018-07-26 09:45:46 +01:00
|
|
|
if (!\is_string($resource)) {
|
2016-11-23 18:19:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-02 17:06:40 +01:00
|
|
|
if (null === $type && 'php' === pathinfo($resource, \PATHINFO_EXTENSION)) {
|
2016-11-23 18:19:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'php' === $type;
|
2010-07-18 10:26:47 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-08 18:11:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
final class ProtectedPhpFileLoader extends PhpFileLoader
|
|
|
|
{
|
|
|
|
}
|