use Symfony\Component\DependencyInjection\Definition; // Create a new service definition $definition = new Definition(MyService::class); // Add some tags to the service $definition->addTag('my_tag'); $definition->addTag('another_tag'); // Get the tags assigned to the service $tags = $definition->getTags(); // Output the list of tags foreach ($tags as $tagName => $attributes) { echo "$tagName\n"; }
use Symfony\Component\DependencyInjection\Definition; // Create a new service definition $definition = new Definition(MyService::class); // Add some tags to the service $definition->addTag('my_tag'); $definition->addTag('another_tag'); // Check if the service has the 'my_tag' tag $hasMyTag = isset($definition->getTags()['my_tag']); // Output the result echo $hasMyTag ? 'The service has the "my_tag" tag' : 'The service does not have the "my_tag" tag';In this example, we create a new service definition and add two tags to it ('my_tag' and 'another_tag'). We use the Definition::getTags() method to retrieve the tags assigned to the service and then check if the 'my_tag' tag is present. Based on the namespace of the class we used in the examples (Symfony\Component\DependencyInjection\Definition), the Definition class belongs to the DependencyInjection Component of the Symfony framework.