c165b6503e7975add9509110435f7cb6d1e18181
[yaffs-website] / vendor / symfony / dependency-injection / Loader / Configurator / Traits / TagTrait.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
13
14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
15
16 trait TagTrait
17 {
18     /**
19      * Adds a tag for this definition.
20      *
21      * @param string $name       The tag name
22      * @param array  $attributes An array of attributes
23      *
24      * @return $this
25      */
26     final public function tag($name, array $attributes = array())
27     {
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));
30         }
31
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));
35             }
36         }
37
38         $this->definition->addTag($name, $attributes);
39
40         return $this;
41     }
42 }