AutoconfigureTrait.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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\Traits;
  11. use Symfony\Component\DependencyInjection\ChildDefinition;
  12. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  13. trait AutoconfigureTrait
  14. {
  15. /**
  16. * Sets whether or not instanceof conditionals should be prepended with a global set.
  17. *
  18. * @param bool $autoconfigured
  19. *
  20. * @return $this
  21. *
  22. * @throws InvalidArgumentException when a parent is already set
  23. */
  24. final public function autoconfigure($autoconfigured = true)
  25. {
  26. if ($autoconfigured && $this->definition instanceof ChildDefinition) {
  27. throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.', $this->id));
  28. }
  29. $this->definition->setAutoconfigured($autoconfigured);
  30. return $this;
  31. }
  32. }