Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\ChildDefinition; Chris@14: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@14: Chris@14: trait AutoconfigureTrait Chris@14: { Chris@14: /** Chris@14: * Sets whether or not instanceof conditionals should be prepended with a global set. Chris@14: * Chris@14: * @param bool $autoconfigured Chris@14: * Chris@14: * @return $this Chris@14: * Chris@14: * @throws InvalidArgumentException when a parent is already set Chris@14: */ Chris@14: final public function autoconfigure($autoconfigured = true) Chris@14: { Chris@14: if ($autoconfigured && $this->definition instanceof ChildDefinition) { Chris@14: throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.', $this->id)); Chris@14: } Chris@14: $this->definition->setAutoconfigured($autoconfigured); Chris@14: Chris@14: return $this; Chris@14: } Chris@14: }