getIndexAttribute example

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;

class TaggedIteratorArgumentTest extends TestCase
{
    public function testWithTagOnly()
    {
        $taggedIteratorArgument = new TaggedIteratorArgument('foo');

        $this->assertSame('foo', $taggedIteratorArgument->getTag());
        $this->assertNull($taggedIteratorArgument->getIndexAttribute());
        $this->assertNull($taggedIteratorArgument->getDefaultIndexMethod());
        $this->assertFalse($taggedIteratorArgument->needsIndexes());
        $this->assertNull($taggedIteratorArgument->getDefaultPriorityMethod());
    }

    public function testOnlyTagWithNeedsIndexes()
    {
        $taggedIteratorArgument = new TaggedIteratorArgument('foo', null, null, true);

        $this->assertSame('foo', $taggedIteratorArgument->getTag());
        $this->assertSame('foo', $taggedIteratorArgument->getIndexAttribute());
        
if ($withKeys) {
                $element->setAttribute($keyAttribute$key);
            }

            if (\is_array($tag = $value)) {
                $element->setAttribute('type', 'collection');
                $this->convertParameters($value$type$element, 'key');
            } elseif ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
                $element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
                $element->setAttribute('tag', $tag->getTag());

                if (null !== $tag->getIndexAttribute()) {
                    $element->setAttribute('index-by', $tag->getIndexAttribute());

                    if (null !== $tag->getDefaultIndexMethod()) {
                        $element->setAttribute('default-index-method', $tag->getDefaultIndexMethod());
                    }
                    if (null !== $tag->getDefaultPriorityMethod()) {
                        $element->setAttribute('default-priority-method', $tag->getDefaultPriorityMethod());
                    }
                }
                if ($excludes = $tag->getExclude()) {
                    if (1 === \count($excludes)) {
                        

    private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagName, ContainerBuilder $container, array $exclude = []): array
    {
        $indexAttribute = $defaultIndexMethod = $needsIndexes = $defaultPriorityMethod = null;

        if ($tagName instanceof TaggedIteratorArgument) {
            $indexAttribute = $tagName->getIndexAttribute();
            $defaultIndexMethod = $tagName->getDefaultIndexMethod();
            $needsIndexes = $tagName->needsIndexes();
            $defaultPriorityMethod = $tagName->getDefaultPriorityMethod() ?? 'getDefaultPriority';
            $exclude = array_merge($exclude$tagName->getExclude());
            $tagName = $tagName->getTag();
        }

        $i = 0;
        $services = [];

        foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $attributes) {
            
private function dumpValue(mixed $value): mixed
    {
        if ($value instanceof ServiceClosureArgument) {
            $value = $value->getValues()[0];

            return new TaggedValue('service_closure', $this->dumpValue($value));
        }
        if ($value instanceof ArgumentInterface) {
            $tag = $value;

            if ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
                if (null === $tag->getIndexAttribute()) {
                    $content = $tag->getTag();
                } else {
                    $content = [
                        'tag' => $tag->getTag(),
                        'index_by' => $tag->getIndexAttribute(),
                    ];

                    if (null !== $tag->getDefaultIndexMethod()) {
                        $content['default_index_method'] = $tag->getDefaultIndexMethod();
                    }
                    if (null !== $tag->getDefaultPriorityMethod()) {
                        

    private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagName, ContainerBuilder $container, array $exclude = []): array
    {
        $indexAttribute = $defaultIndexMethod = $needsIndexes = $defaultPriorityMethod = null;

        if ($tagName instanceof TaggedIteratorArgument) {
            $indexAttribute = $tagName->getIndexAttribute();
            $defaultIndexMethod = $tagName->getDefaultIndexMethod();
            $needsIndexes = $tagName->needsIndexes();
            $defaultPriorityMethod = $tagName->getDefaultPriorityMethod() ?? 'getDefaultPriority';
            $exclude = array_merge($exclude$tagName->getExclude());
            $tagName = $tagName->getTag();
        }

        $i = 0;
        $services = [];

        foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $attributes) {
            
/** * When creating a tagged iterator using the array syntax, all optional parameters should be properly handled. */
    public function testDefaultValueOfTagged()
    {
        $container = new ContainerBuilder();
        $loader = new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yaml'));
        $loader->load('tagged_iterator_optional.yml');

        $iteratorArgument = $container->getDefinition('iterator_service')->getArgument(0);
        $this->assertInstanceOf(TaggedIteratorArgument::class$iteratorArgument);
        $this->assertNull($iteratorArgument->getIndexAttribute());
    }

    public function testEnumeration()
    {
        $container = new ContainerBuilder();
        $loader = new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yaml'));
        $loader->load('services_with_enumeration.yml');
        $container->compile();

        $definition = $container->getDefinition(FooClassWithEnumAttribute::class);
        $this->assertSame([FooUnitEnum::BAR]$definition->getArguments());
    }
private function dumpValue(mixed $value): mixed
    {
        if ($value instanceof ServiceClosureArgument) {
            $value = $value->getValues()[0];

            return new TaggedValue('service_closure', $this->dumpValue($value));
        }
        if ($value instanceof ArgumentInterface) {
            $tag = $value;

            if ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
                if (null === $tag->getIndexAttribute()) {
                    $content = $tag->getTag();
                } else {
                    $content = [
                        'tag' => $tag->getTag(),
                        'index_by' => $tag->getIndexAttribute(),
                    ];

                    if (null !== $tag->getDefaultIndexMethod()) {
                        $content['default_index_method'] = $tag->getDefaultIndexMethod();
                    }
                    if (null !== $tag->getDefaultPriorityMethod()) {
                        
if ($withKeys) {
                $element->setAttribute($keyAttribute$key);
            }

            if (\is_array($tag = $value)) {
                $element->setAttribute('type', 'collection');
                $this->convertParameters($value$type$element, 'key');
            } elseif ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
                $element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
                $element->setAttribute('tag', $tag->getTag());

                if (null !== $tag->getIndexAttribute()) {
                    $element->setAttribute('index-by', $tag->getIndexAttribute());

                    if (null !== $tag->getDefaultIndexMethod()) {
                        $element->setAttribute('default-index-method', $tag->getDefaultIndexMethod());
                    }
                    if (null !== $tag->getDefaultPriorityMethod()) {
                        $element->setAttribute('default-priority-method', $tag->getDefaultPriorityMethod());
                    }
                }
                if ($excludes = $tag->getExclude()) {
                    if (1 === \count($excludes)) {
                        

        $container = $this->createContainerFromFile('cache');
        $this->assertTrue($container->hasDefinition('console.command.cache_pool_invalidate_tags'));

        $locator = $container->getDefinition('console.command.cache_pool_invalidate_tags')->getArgument(0);
        $this->assertInstanceOf(ServiceLocatorArgument::class$locator);

        $iterator = $locator->getTaggedIteratorArgument();
        $this->assertInstanceOf(TaggedIteratorArgument::class$iterator);

        $this->assertSame('cache.taggable', $iterator->getTag());
        $this->assertSame('pool', $iterator->getIndexAttribute());
        $this->assertTrue($iterator->needsIndexes());
    }

    public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebug()
    {
        $container = $this->createContainer(['kernel.debug' => true]);
        (new FrameworkExtension())->load([['annotations' => false, 'http_method_override' => false, 'handle_all_throwables' => true, 'php_errors' => ['log' => true]]]$container);
        $this->assertCount(1, $container->getDefinition('config_cache_factory')->getArguments());

        $container = $this->createContainer(['kernel.debug' => false]);
        (new FrameworkExtension())->load([['annotations' => false, 'http_method_override' => false, 'handle_all_throwables' => true, 'php_errors' => ['log' => true]]]$container);
        
Home | Imprint | This part of the site doesn't use cookies.