registerClasses example

$definition->setArguments($stack);
            } elseif (null !== $definition = $this->parseDefinition($service$file$defaults)) {
                if ('prototype' === $service->tagName) {
                    $excludes = array_column($this->getChildren($service, 'exclude'), 'nodeValue');
                    if ($service->hasAttribute('exclude')) {
                        if (\count($excludes) > 0) {
                            throw new InvalidArgumentException('You cannot use both the attribute "exclude" and <exclude> tags at the same time.');
                        }
                        $excludes = [$service->getAttribute('exclude')];
                    }
                    $this->registerClasses($definition(string) $service->getAttribute('namespace')(string) $service->getAttribute('resource')$excludes$file);
                } else {
                    $this->setDefinition((string) $service->getAttribute('id')$definition);
                }
            }
        }
    }

    private function getServiceDefaults(\DOMDocument $xml, string $file, \DOMNode $root = null): Definition
    {
        $xpath = new \DOMXPath($xml);
        $xpath->registerNamespace('container', self::NS);

        
$definition->setArguments($stack);
            } elseif (null !== $definition = $this->parseDefinition($service$file$defaults)) {
                if ('prototype' === $service->tagName) {
                    $excludes = array_column($this->getChildren($service, 'exclude'), 'nodeValue');
                    if ($service->hasAttribute('exclude')) {
                        if (\count($excludes) > 0) {
                            throw new InvalidArgumentException('You cannot use both the attribute "exclude" and <exclude> tags at the same time.');
                        }
                        $excludes = [$service->getAttribute('exclude')];
                    }
                    $this->registerClasses($definition(string) $service->getAttribute('namespace')(string) $service->getAttribute('resource')$excludes$file);
                } else {
                    $this->setDefinition((string) $service->getAttribute('id')$definition);
                }
            }
        }
    }

    private function getServiceDefaults(\DOMDocument $xml, string $file, \DOMNode $root = null): Definition
    {
        $xpath = new \DOMXPath($xml);
        $xpath->registerNamespace('container', self::NS);

        
$this->allowParent = $allowParent;
        $this->path = $path;

        parent::__construct($parent$definition$namespace$defaults->getTags());
    }

    public function __destruct()
    {
        parent::__destruct();

        if (isset($this->loader)) {
            $this->loader->registerClasses($this->definition, $this->id, $this->resource, $this->excludes, $this->path);
        }
        unset($this->loader);
    }

    /** * Excludes files from registration using glob patterns. * * @param string[]|string $excludes * * @return $this */
    
$this->assertEquals(array_keys($expected)array_keys($actual), '->load() imports and merges imported files');
    }

    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()
    {


            return $definition;
        }

        if (\array_key_exists('resource', $service)) {
            if (!\is_string($service['resource'])) {
                throw new InvalidArgumentException(sprintf('A "resource" attribute must be of type string for service "%s" in "%s". Check your YAML syntax.', $id$file));
            }
            $exclude = $service['exclude'] ?? null;
            $namespace = $service['namespace'] ?? $id;
            $this->registerClasses($definition$namespace$service['resource']$exclude$file);
        } else {
            $this->setDefinition($id$definition);
        }

        return null;
    }

    /** * @throws InvalidArgumentException When errors occur */
    private function parseCallable(mixed $callable, string $parameter, string $id, string $file): string|array|Reference
    {
$this->allowParent = $allowParent;
        $this->path = $path;

        parent::__construct($parent$definition$namespace$defaults->getTags());
    }

    public function __destruct()
    {
        parent::__destruct();

        if (isset($this->loader)) {
            $this->loader->registerClasses($this->definition, $this->id, $this->resource, $this->excludes, $this->path);
        }
        unset($this->loader);
    }

    /** * Excludes files from registration using glob patterns. * * @param string[]|string $excludes * * @return $this */
    


            return $definition;
        }

        if (\array_key_exists('resource', $service)) {
            if (!\is_string($service['resource'])) {
                throw new InvalidArgumentException(sprintf('A "resource" attribute must be of type string for service "%s" in "%s". Check your YAML syntax.', $id$file));
            }
            $exclude = $service['exclude'] ?? null;
            $namespace = $service['namespace'] ?? $id;
            $this->registerClasses($definition$namespace$service['resource']$exclude$file);
        } else {
            $this->setDefinition($id$definition);
        }

        return null;
    }

    /** * @throws InvalidArgumentException When errors occur */
    private function parseCallable(mixed $callable, string $parameter, string $id, string $file): string|array|Reference
    {
Home | Imprint | This part of the site doesn't use cookies.