getTags example

if (str_starts_with($id, '\\') && 1 < substr_count($id, '\\')) {
                        throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "%s" to get rid of this error.', $idsubstr($id, 1)));
                    }

                    throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Please specify the class attribute explicitly to get rid of this error.', $id));
                }

                throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.', $id));
            }

            // tag attribute values must be scalars             foreach ($definition->getTags() as $name => $tags) {
                foreach ($tags as $attributes) {
                    $this->validateAttributes($id$name$attributes);
                }
            }

            if ($definition->isPublic() && !$definition->isPrivate()) {
                $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
                if (null !== $usedEnvs) {
                    throw new EnvParameterException([$resolvedId], null, 'A service name ("%s") cannot contain dynamic values.');
                }
            }
        }
private function generateTags(string $name, Request $request, SalesChannelContext $context): array
    {
        $tags = array_merge(
            $this->cacheTracer->get($name),
            [$name, self::ALL_TAG]
        );

        $event = new NotFoundPageTagsEvent($tags$request$context);

        $this->eventDispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }

    private function setSalesChannelContext(Request $request): void
    {
        $salesChannelId = (string) $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);

        $context = $this->contextService->get(
            new SalesChannelContextServiceParameters(
                $salesChannelId,
                Uuid::randomHex(),
                $request->headers->get(PlatformRequest::HEADER_LANGUAGE_ID),
                

    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($context->getSalesChannelId())),
            [self::buildName($context->getSalesChannelId()), self::ALL_TAG]
        );

        $event = new LanguageRouteCacheTagsEvent($tags$request$response$context$criteria);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }
}
$class = substr($class, 1);
            }

            $code .= sprintf(" class: %s\n", $this->dumper->dump($class));
        }

        if (!$definition->isPrivate()) {
            $code .= sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
        }

        $tagsCode = '';
        $tags = $definition->getTags();
        $tags['container.error'] = array_map(fn ($e) => ['message' => $e]$definition->getErrors());
        foreach ($tags as $name => $tags) {
            foreach ($tags as $attributes) {
                $att = [];
                foreach ($attributes as $key => $value) {
                    $att[] = sprintf('%s: %s', $this->dumper->dump($key)$this->dumper->dump($value));
                }
                $att = $att ? ': { '.implode(', ', $att).' }' : '';

                $tagsCode .= sprintf(" - %s%s\n", $this->dumper->dump($name)$att);
            }
        }
 else {
                $output .= "\n".'- Factory Function: `'.$factory.'`';
            }
        }

        $calls = $definition->getMethodCalls();
        foreach ($calls as $callData) {
            $output .= "\n".'- Call: `'.$callData[0].'`';
        }

        if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
            foreach ($this->sortTagsByPriority($definition->getTags()) as $tagName => $tagData) {
                foreach ($tagData as $parameters) {
                    $output .= "\n".'- Tag: `'.$tagName.'`';
                    foreach ($parameters as $name => $value) {
                        $output .= "\n".' - '.ucfirst($name).': '.(\is_array($value) ? $this->formatParameter($value) : $value);
                    }
                }
            }
        }

        $inEdges = null !== $container && isset($options['id']) ? $this->getServiceEdges($container$options['id']) : [];
        $output .= "\n".'- Usages: '.($inEdges ? implode(', ', $inEdges) : 'none');

        
private function generateTags(string $navigationId, CategoryRouteResponse $response, Request $request, SalesChannelContext $context): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($navigationId)),
            $this->extractProductIds($response),
            [self::buildName($navigationId)]
        );

        $event = new CategoryRouteCacheTagsEvent($navigationId$tags$request$response$context, null);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }

    /** * @return array<string> */
    private function extractProductIds(CategoryRouteResponse $response): array
    {
        $page = $response->getCategory()->getCmsPage();

        if ($page === null) {
            return [];
        }
$this->logger->error(sprintf('Unable to add translation for key "%s" in locale "%s" to Loco: "%s".', $id$locale$response->getContent(false)));

                if (500 <= $statusCode) {
                    throw new ProviderException(sprintf('Unable to add translation for key "%s" in locale "%s" to Loco.', $id$locale)$response);
                }
            }
        }
    }

    private function tagsAssets(array $ids, string $tag): void
    {
        if (!\in_array($tag$this->getTags(), true)) {
            $this->createTag($tag);
        }

        // Separate ids with and without comma.         $idsWithComma = $idsWithoutComma = [];
        foreach ($ids as $id) {
            if (str_contains($id, ',')) {
                $idsWithComma[] = $id;
            } else {
                $idsWithoutComma[] = $id;
            }
        }
foreach ($this->faker->randomElements($productLineItemsrandom_int(3, 5)) as $lineItem) {
                $cart->add($lineItem);
            }
            foreach ($this->faker->randomElements($promotionLineItemsrandom_int(0, 3)) as $lineItem) {
                $cart->add($lineItem);
            }

            $cart = $this->cartCalculator->calculate($cart$salesChannelContext);
            $tempOrder = $this->orderConverter->convertToOrder($cart$salesChannelContextnew OrderConversionContext());

            $tempOrder['orderDateTime'] = (new \DateTime())->modify('-' . random_int(0, 30) . ' days')->format(Defaults::STORAGE_DATE_TIME_FORMAT);
            $tempOrder['tags'] = $this->getTags($tags);

            $orders[] = $tempOrder;

            if (\count($orders) >= 20) {
                $this->writer->upsert($this->orderDefinition, $orders$writeContext);
                $context->getConsole()->progressAdvance(\count($orders));
                $orders = [];
            }
        }

        if (!empty($orders)) {
            
private readonly CacheTagCollection $collection
    ) {
    }

    /** * @param string $key */
    public function getItem($key): CacheItem
    {
        $item = $this->decorated->getItem($key);

        $this->collection->add($this->getTags($item));

        return $item;
    }

    /** * @return \Generator<CacheItem> */
    public function getItems(array $keys = []): \Generator
    {
        foreach ($this->decorated->getItems($keys) as $item) {
            $this->collection->add($this->getTags($item));
            
$class = substr($class, 1);
            }

            $code .= sprintf(" class: %s\n", $this->dumper->dump($class));
        }

        if (!$definition->isPrivate()) {
            $code .= sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
        }

        $tagsCode = '';
        $tags = $definition->getTags();
        $tags['container.error'] = array_map(fn ($e) => ['message' => $e]$definition->getErrors());
        foreach ($tags as $name => $tags) {
            foreach ($tags as $attributes) {
                $att = [];
                foreach ($attributes as $key => $value) {
                    $att[] = sprintf('%s: %s', $this->dumper->dump($key)$this->dumper->dump($value));
                }
                $att = $att ? ': { '.implode(', ', $att).' }' : '';

                $tagsCode .= sprintf(" - %s%s\n", $this->dumper->dump($name)$att);
            }
        }

    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($context->getSalesChannelId())),
            [self::buildName($context->getSalesChannelId()), self::ALL_TAG]
        );

        $event = new CountryRouteCacheTagsEvent($tags$request$response$context$criteria);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }
}
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
        }
        if ($value instanceof Definition) {
            $value->setBindings($this->processValue($value->getBindings()));
            $changes = $value->getChanges();
            if (isset($changes['class'])) {
                $value->setClass($this->bag->resolveValue($value->getClass()));
            }
            if (isset($changes['file'])) {
                $value->setFile($this->bag->resolveValue($value->getFile()));
            }
            $tags = $value->getTags();
            if (isset($tags['proxy'])) {
                $tags['proxy'] = $this->bag->resolveValue($tags['proxy']);
                $value->setTags($tags);
            }
        }

        $value = parent::processValue($value$isRoot);

        if ($value && \is_array($value)) {
            $value = array_combine($this->bag->resolveValue(array_keys($value))$value);
        }

        
if ($interface !== $class && !is_subclass_of($class$interface)) {
                continue;
            }

            foreach ($instanceofDefs as $key => $instanceofDef) {
                /** @var ChildDefinition $instanceofDef */
                $instanceofDef = clone $instanceofDef;
                $instanceofDef->setAbstract(true)->setParent($parent ?: '.abstract.instanceof.'.$id);
                $parent = '.instanceof.'.$interface.'.'.$key.'.'.$id;
                $container->setDefinition($parent$instanceofDef);
                $instanceofTags[] = [$interface$instanceofDef->getTags()];
                $instanceofBindings = $instanceofDef->getBindings() + $instanceofBindings;

                foreach ($instanceofDef->getMethodCalls() as $methodCall) {
                    $instanceofCalls[] = $methodCall;
                }

                $instanceofDef->setTags([]);
                $instanceofDef->setMethodCalls([]);
                $instanceofDef->setBindings([]);

                if (isset($instanceofDef->getChanges()['shared'])) {
                    
$loader->load('services_with_service_closure.xml');

        $this->assertEquals(new ServiceClosureArgument(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))$container->getDefinition('foo')->getArgument(0));
    }

    public function testParseServiceTagsWithArrayAttributes()
    {
        $container = new ContainerBuilder();
        $loader = new XmlFileLoader($containernew FileLocator(self::$fixturesPath.'/xml'));
        $loader->load('services_with_array_tags.xml');

        $this->assertEquals(['foo_tag' => [['foo' => 'bar', 'bar' => ['foo' => 'bar', 'bar' => 'foo']]]]$container->getDefinition('foo')->getTags());
    }

    public function testParseTagsWithoutNameThrowsException()
    {
        $this->expectException(InvalidArgumentException::class);
        $container = new ContainerBuilder();
        $loader = new XmlFileLoader($containernew FileLocator(self::$fixturesPath.'/xml'));
        $loader->load('tag_without_name.xml');
    }

    public function testParseTagWithEmptyNameThrowsException()
    {
$calls = $definition->getMethodCalls();
        if (\count($calls) > 0) {
            $data['calls'] = [];
            foreach ($calls as $callData) {
                $data['calls'][] = $callData[0];
            }
        }

        if (!$omitTags) {
            $data['tags'] = [];
            foreach ($this->sortTagsByPriority($definition->getTags()) as $tagName => $tagData) {
                foreach ($tagData as $parameters) {
                    $data['tags'][] = ['name' => $tagName, 'parameters' => $parameters];
                }
            }
        }

        $data['usages'] = null !== $container && null !== $id ? $this->getServiceEdges($container$id) : [];

        return $data;
    }

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