DefaultsConfigurator.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  12. /**
  13. * @author Nicolas Grekas <p@tchwork.com>
  14. *
  15. * @method InstanceofConfigurator instanceof(string $fqcn)
  16. */
  17. class DefaultsConfigurator extends AbstractServiceConfigurator
  18. {
  19. const FACTORY = 'defaults';
  20. use Traits\AutoconfigureTrait;
  21. use Traits\AutowireTrait;
  22. use Traits\BindTrait;
  23. use Traits\PublicTrait;
  24. /**
  25. * Adds a tag for this definition.
  26. *
  27. * @param string $name The tag name
  28. * @param array $attributes An array of attributes
  29. *
  30. * @return $this
  31. *
  32. * @throws InvalidArgumentException when an invalid tag name or attribute is provided
  33. */
  34. final public function tag($name, array $attributes = array())
  35. {
  36. if (!is_string($name) || '' === $name) {
  37. throw new InvalidArgumentException('The tag name in "_defaults" must be a non-empty string.');
  38. }
  39. foreach ($attributes as $attribute => $value) {
  40. if (!is_scalar($value) && null !== $value) {
  41. throw new InvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type.', $name, $attribute));
  42. }
  43. }
  44. $this->definition->addTag($name, $attributes);
  45. return $this;
  46. }
  47. /**
  48. * Defines an instanceof-conditional to be applied to following service definitions.
  49. *
  50. * @param string $fqcn
  51. *
  52. * @return InstanceofConfigurator
  53. */
  54. final protected function setInstanceof($fqcn)
  55. {
  56. return $this->parent->instanceof($fqcn);
  57. }
  58. }