4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
19 * Adds a tag for this definition.
21 * @param string $name The tag name
22 * @param array $attributes An array of attributes
26 final public function tag($name, array $attributes = array())
28 if (!\is_string($name) || '' === $name) {
29 throw new InvalidArgumentException(sprintf('The tag name for service "%s" must be a non-empty string.', $this->id));
32 foreach ($attributes as $attribute => $value) {
33 if (!is_scalar($value) && null !== $value) {
34 throw new InvalidArgumentException(sprintf('A tag attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $this->id, $name, $attribute));
38 $this->definition->addTag($name, $attributes);