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; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\Definition; Chris@14: use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; Chris@14: Chris@14: abstract class AbstractServiceConfigurator extends AbstractConfigurator Chris@14: { Chris@14: protected $parent; Chris@14: protected $id; Chris@17: private $defaultTags = []; Chris@14: Chris@17: public function __construct(ServicesConfigurator $parent, Definition $definition, $id = null, array $defaultTags = []) Chris@14: { Chris@14: $this->parent = $parent; Chris@14: $this->definition = $definition; Chris@14: $this->id = $id; Chris@14: $this->defaultTags = $defaultTags; Chris@14: } Chris@14: Chris@14: public function __destruct() Chris@14: { Chris@14: // default tags should be added last Chris@14: foreach ($this->defaultTags as $name => $attributes) { Chris@14: foreach ($attributes as $attributes) { Chris@14: $this->definition->addTag($name, $attributes); Chris@14: } Chris@14: } Chris@17: $this->defaultTags = []; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Registers a service. Chris@14: * Chris@14: * @param string $id Chris@14: * @param string|null $class Chris@14: * Chris@14: * @return ServiceConfigurator Chris@14: */ Chris@14: final public function set($id, $class = null) Chris@14: { Chris@14: $this->__destruct(); Chris@14: Chris@14: return $this->parent->set($id, $class); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Creates an alias. Chris@14: * Chris@14: * @param string $id Chris@14: * @param string $referencedId Chris@14: * Chris@14: * @return AliasConfigurator Chris@14: */ Chris@14: final public function alias($id, $referencedId) Chris@14: { Chris@14: $this->__destruct(); Chris@14: Chris@14: return $this->parent->alias($id, $referencedId); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Registers a PSR-4 namespace using a glob pattern. Chris@14: * Chris@14: * @param string $namespace Chris@14: * @param string $resource Chris@14: * Chris@14: * @return PrototypeConfigurator Chris@14: */ Chris@14: final public function load($namespace, $resource) Chris@14: { Chris@14: $this->__destruct(); Chris@14: Chris@14: return $this->parent->load($namespace, $resource); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Gets an already defined service definition. Chris@14: * Chris@14: * @param string $id Chris@14: * Chris@14: * @return ServiceConfigurator Chris@14: * Chris@14: * @throws ServiceNotFoundException if the service definition does not exist Chris@14: */ Chris@14: final public function get($id) Chris@14: { Chris@14: $this->__destruct(); Chris@14: Chris@14: return $this->parent->get($id); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Registers a service. Chris@14: * Chris@14: * @param string $id Chris@14: * @param string|null $class Chris@14: * Chris@14: * @return ServiceConfigurator Chris@14: */ Chris@14: final public function __invoke($id, $class = null) Chris@14: { Chris@14: $this->__destruct(); Chris@14: Chris@14: return $this->parent->set($id, $class); Chris@14: } Chris@14: }