namespace Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\Config\Resource\FileResource;
+use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
/**
* PhpFileLoader loads service definitions from a PHP file.
$loader = $this;
$path = $this->locator->locate($resource);
- $this->setCurrentDir(dirname($path));
- $this->container->addResource(new FileResource($path));
+ $this->setCurrentDir(\dirname($path));
+ $this->container->fileExists($path);
- include $path;
+ // 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);
+ }
}
/**
*/
public function supports($resource, $type = null)
{
- return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION);
+ if (!\is_string($resource)) {
+ return false;
+ }
+
+ if (null === $type && 'php' === pathinfo($resource, PATHINFO_EXTENSION)) {
+ return true;
+ }
+
+ return 'php' === $type;
}
}
+
+/**
+ * @internal
+ */
+final class ProtectedPhpFileLoader extends PhpFileLoader
+{
+}