ContainerConfigurator example

$env = $container->getParameter('kernel.environment');
        $loader = $this->createContainerLoader($container$env);
        $file = (new \ReflectionObject($subject))->getFileName();
        $bundleLoader = $loader->getResolver()->resolve($file);
        if (!$bundleLoader instanceof PhpFileLoader) {
            throw new \LogicException('Unable to create the ContainerConfigurator.');
        }
        $bundleLoader->setCurrentDir(\dirname($file));
        $instanceof = &\Closure::bind(fn &() => $this->instanceof, $bundleLoader$bundleLoader)();

        try {
            $callback(new ContainerConfigurator($container$bundleLoader$instanceof$file$file$env));
        } finally {
            $instanceof = [];
            $bundleLoader->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    private function createContainerLoader(ContainerBuilder $container, string $env): DelegatingLoader
    {
        $buildDir = $container->getParameter('kernel.build_dir');
        $locator = new FileLocator();
        $resolver = new LoaderResolver([
            
$this->container->fileExists($path);

        // the closure forbids access to the private scope in the included file         $load = \Closure::bind(function D$path$env) use ($container$loader$resource$type) {
            return include $path;
        }$this, ProtectedPhpFileLoader::class);

        try {
            $callback = $load($path$this->env);

            if (\is_object($callback) && \is_callable($callback)) {
                $this->executeCallback($callbacknew ContainerConfigurator($this->container, $this$this->instanceof, $path$resource$this->env)$path);
            }
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }

        return null;
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        
$env = $container->getParameter('kernel.environment');
        $loader = $this->createContainerLoader($container$env);
        $file = (new \ReflectionObject($subject))->getFileName();
        $bundleLoader = $loader->getResolver()->resolve($file);
        if (!$bundleLoader instanceof PhpFileLoader) {
            throw new \LogicException('Unable to create the ContainerConfigurator.');
        }
        $bundleLoader->setCurrentDir(\dirname($file));
        $instanceof = &\Closure::bind(fn &() => $this->instanceof, $bundleLoader$bundleLoader)();

        try {
            $callback(new ContainerConfigurator($container$bundleLoader$instanceof$file$file$env));
        } finally {
            $instanceof = [];
            $bundleLoader->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    private function createContainerLoader(ContainerBuilder $container, string $env): DelegatingLoader
    {
        $buildDir = $container->getParameter('kernel.build_dir');
        $locator = new FileLocator();
        $resolver = new LoaderResolver([
            
$this->container->fileExists($path);

        // the closure forbids access to the private scope in the included file         $load = \Closure::bind(function D$path$env) use ($container$loader$resource$type) {
            return include $path;
        }$this, ProtectedPhpFileLoader::class);

        try {
            $callback = $load($path$this->env);

            if (\is_object($callback) && \is_callable($callback)) {
                $this->executeCallback($callbacknew ContainerConfigurator($this->container, $this$this->instanceof, $path$resource$this->env)$path);
            }
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }

        return null;
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        
$file = (new \ReflectionObject($this))->getFileName();
            /* @var ContainerPhpFileLoader $kernelLoader */
            $kernelLoader = $loader->getResolver()->resolve($file);
            $kernelLoader->setCurrentDir(\dirname($file));
            $instanceof = &\Closure::bind(fn &() => $this->instanceof, $kernelLoader$kernelLoader)();

            $valuePreProcessor = AbstractConfigurator::$valuePreProcessor;
            AbstractConfigurator::$valuePreProcessor = fn ($value) => $this === $value ? new Reference('kernel') : $value;

            try {
                $configureContainer->getClosure($this)(new ContainerConfigurator($container$kernelLoader$instanceof$file$file$this->getEnvironment())$loader$container);
            } finally {
                $instanceof = [];
                $kernelLoader->registerAliasesForSinglyImplementedInterfaces();
                AbstractConfigurator::$valuePreProcessor = $valuePreProcessor;
            }

            $container->setAlias($kernelClass, 'kernel')->setPublic(true);
        });
    }

    /** * @internal */
Home | Imprint | This part of the site doesn't use cookies.