registerAliasesForSinglyImplementedInterfaces example

$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([
            new XmlFileLoader($container$locator$env),
            new YamlFileLoader($container$locator$env),
            new IniFileLoader($container$locator$env),
            

                    $this->aliases[$alias] = new Alias($class$public);
                }
            }
        }

        foreach ($this->aliases as $alias => $aliasDefinition) {
            $this->container->setAlias($alias$aliasDefinition);
        }

        if ($this->autoRegisterAliasesForSinglyImplementedInterfaces) {
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    /** * @return void */
    public function registerAliasesForSinglyImplementedInterfaces()
    {
        foreach ($this->interfaces as $interface) {
            if (!empty($this->singlyImplemented[$interface]) && !isset($this->aliases[$interface]) && !$this->container->has($interface)) {
                $this->container->setAlias($interface$this->singlyImplemented[$interface]);
            }
/** * Registers a service. */
    final public function __invoke(string $id, string $class = null): ServiceConfigurator
    {
        return $this->set($id$class);
    }

    public function __destruct()
    {
        $this->loader->registerAliasesForSinglyImplementedInterfaces();
    }
}
$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 */
    public function loadRoutes(LoaderInterface $loader): RouteCollection
    {

                    $this->aliases[$alias] = new Alias($class$public);
                }
            }
        }

        foreach ($this->aliases as $alias => $aliasDefinition) {
            $this->container->setAlias($alias$aliasDefinition);
        }

        if ($this->autoRegisterAliasesForSinglyImplementedInterfaces) {
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    /** * @return void */
    public function registerAliasesForSinglyImplementedInterfaces()
    {
        foreach ($this->interfaces as $interface) {
            if (!empty($this->singlyImplemented[$interface]) && !isset($this->aliases[$interface]) && !$this->container->has($interface)) {
                $this->container->setAlias($interface$this->singlyImplemented[$interface]);
            }
$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([
            new XmlFileLoader($container$locator$env),
            new YamlFileLoader($container$locator$env),
            new IniFileLoader($container$locator$env),
            
// extensions         $this->loadFromExtensions($content);

        // services         $this->anonymousServicesCount = 0;
        $this->anonymousServicesSuffix = '~'.ContainerBuilder::hash($path);
        $this->setCurrentDir(\dirname($path));
        try {
            $this->parseDefinitions($content$path);
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        if (!\is_string($resource)) {
            return false;
        }

        if (null === $type && \in_array(pathinfo($resource, \PATHINFO_EXTENSION)['yaml', 'yml'], true)) {
            return true;
        }
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
    {
        if (!\is_string($resource)) {
            return false;
        }

        
// extensions         $this->loadFromExtensions($content);

        // services         $this->anonymousServicesCount = 0;
        $this->anonymousServicesSuffix = '~'.ContainerBuilder::hash($path);
        $this->setCurrentDir(\dirname($path));
        try {
            $this->parseDefinitions($content$path);
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        if (!\is_string($resource)) {
            return false;
        }

        if (null === $type && \in_array(pathinfo($resource, \PATHINFO_EXTENSION)['yaml', 'yml'], true)) {
            return true;
        }
/** * Registers a service. */
    final public function __invoke(string $id, string $class = null): ServiceConfigurator
    {
        return $this->set($id$class);
    }

    public function __destruct()
    {
        $this->loader->registerAliasesForSinglyImplementedInterfaces();
    }
}
// parameters         $this->parseParameters($xml$path$root);

        // extensions         $this->loadFromExtensions($xml$root);

        // services         try {
            $this->parseDefinitions($xml$path$defaults$root);
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        if (!\is_string($resource)) {
            return false;
        }

        if (null === $type && 'xml' === pathinfo($resource, \PATHINFO_EXTENSION)) {
            return true;
        }


    public function testRegisterClasses()
    {
        $container = new ContainerBuilder();
        $container->setParameter('sub_dir', 'Sub');
        $loader = new TestFileLoader($containernew FileLocator(self::$fixturesPath.'/Fixtures'));
        $loader->noAutoRegisterAliasesForSinglyImplementedInterfaces();

        $loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
        $loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*'); // loading twice should not be an issue         $loader->registerAliasesForSinglyImplementedInterfaces();

        $this->assertEquals(
            ['service_container', Bar::class],
            array_keys($container->getDefinitions())
        );
        $this->assertEquals([BarInterface::class]array_keys($container->getAliases()));
    }

    public function testRegisterClassesWithExclude()
    {
        $container = new ContainerBuilder();
        
// parameters         $this->parseParameters($xml$path$root);

        // extensions         $this->loadFromExtensions($xml$root);

        // services         try {
            $this->parseDefinitions($xml$path$defaults$root);
        } finally {
            $this->instanceof = [];
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    public function supports(mixed $resource, string $type = null): bool
    {
        if (!\is_string($resource)) {
            return false;
        }

        if (null === $type && 'xml' === pathinfo($resource, \PATHINFO_EXTENSION)) {
            return true;
        }
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
    {
        if (!\is_string($resource)) {
            return false;
        }

        
Home | Imprint | This part of the site doesn't use cookies.