aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php')
-rw-r--r--srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php1672
1 files changed, 0 insertions, 1672 deletions
diff --git a/srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php b/srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php
deleted file mode 100644
index 247a021..0000000
--- a/srcs/phpmyadmin/vendor/symfony/dependency-injection/ContainerBuilder.php
+++ /dev/null
@@ -1,1672 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\DependencyInjection;
-
-use Psr\Container\ContainerInterface as PsrContainerInterface;
-use Symfony\Component\Config\Resource\ClassExistenceResource;
-use Symfony\Component\Config\Resource\ComposerResource;
-use Symfony\Component\Config\Resource\DirectoryResource;
-use Symfony\Component\Config\Resource\FileExistenceResource;
-use Symfony\Component\Config\Resource\FileResource;
-use Symfony\Component\Config\Resource\GlobResource;
-use Symfony\Component\Config\Resource\ReflectionClassResource;
-use Symfony\Component\Config\Resource\ResourceInterface;
-use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
-use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
-use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
-use Symfony\Component\DependencyInjection\Argument\ServiceLocator;
-use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
-use Symfony\Component\DependencyInjection\Compiler\Compiler;
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\Compiler\PassConfig;
-use Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass;
-use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
-use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
-use Symfony\Component\DependencyInjection\Exception\LogicException;
-use Symfony\Component\DependencyInjection\Exception\RuntimeException;
-use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
-use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
-use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
-use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
-use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
-use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
-use Symfony\Component\ExpressionLanguage\Expression;
-use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
-
-/**
- * ContainerBuilder is a DI container that provides an API to easily describe services.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class ContainerBuilder extends Container implements TaggedContainerInterface
-{
- /**
- * @var ExtensionInterface[]
- */
- private $extensions = [];
-
- /**
- * @var ExtensionInterface[]
- */
- private $extensionsByNs = [];
-
- /**
- * @var Definition[]
- */
- private $definitions = [];
-
- /**
- * @var Alias[]
- */
- private $aliasDefinitions = [];
-
- /**
- * @var ResourceInterface[]
- */
- private $resources = [];
-
- private $extensionConfigs = [];
-
- /**
- * @var Compiler
- */
- private $compiler;
-
- private $trackResources;
-
- /**
- * @var InstantiatorInterface|null
- */
- private $proxyInstantiator;
-
- /**
- * @var ExpressionLanguage|null
- */
- private $expressionLanguage;
-
- /**
- * @var ExpressionFunctionProviderInterface[]
- */
- private $expressionLanguageProviders = [];
-
- /**
- * @var string[] with tag names used by findTaggedServiceIds
- */
- private $usedTags = [];
-
- /**
- * @var string[][] a map of env var names to their placeholders
- */
- private $envPlaceholders = [];
-
- /**
- * @var int[] a map of env vars to their resolution counter
- */
- private $envCounters = [];
-
- /**
- * @var string[] the list of vendor directories
- */
- private $vendors;
-
- private $autoconfiguredInstanceof = [];
-
- private $removedIds = [];
-
- private $removedBindingIds = [];
-
- private static $internalTypes = [
- 'int' => true,
- 'float' => true,
- 'string' => true,
- 'bool' => true,
- 'resource' => true,
- 'object' => true,
- 'array' => true,
- 'null' => true,
- 'callable' => true,
- 'iterable' => true,
- 'mixed' => true,
- ];
-
- public function __construct(ParameterBagInterface $parameterBag = null)
- {
- parent::__construct($parameterBag);
-
- $this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');
- $this->setDefinition('service_container', (new Definition(ContainerInterface::class))->setSynthetic(true)->setPublic(true));
- $this->setAlias(PsrContainerInterface::class, new Alias('service_container', false));
- $this->setAlias(ContainerInterface::class, new Alias('service_container', false));
- }
-
- /**
- * @var \ReflectionClass[] a list of class reflectors
- */
- private $classReflectors;
-
- /**
- * Sets the track resources flag.
- *
- * If you are not using the loaders and therefore don't want
- * to depend on the Config component, set this flag to false.
- *
- * @param bool $track True if you want to track resources, false otherwise
- */
- public function setResourceTracking($track)
- {
- $this->trackResources = (bool) $track;
- }
-
- /**
- * Checks if resources are tracked.
- *
- * @return bool true If resources are tracked, false otherwise
- */
- public function isTrackingResources()
- {
- return $this->trackResources;
- }
-
- /**
- * Sets the instantiator to be used when fetching proxies.
- */
- public function setProxyInstantiator(InstantiatorInterface $proxyInstantiator)
- {
- $this->proxyInstantiator = $proxyInstantiator;
- }
-
- public function registerExtension(ExtensionInterface $extension)
- {
- $this->extensions[$extension->getAlias()] = $extension;
-
- if (false !== $extension->getNamespace()) {
- $this->extensionsByNs[$extension->getNamespace()] = $extension;
- }
- }
-
- /**
- * Returns an extension by alias or namespace.
- *
- * @param string $name An alias or a namespace
- *
- * @return ExtensionInterface An extension instance
- *
- * @throws LogicException if the extension is not registered
- */
- public function getExtension($name)
- {
- if (isset($this->extensions[$name])) {
- return $this->extensions[$name];
- }
-
- if (isset($this->extensionsByNs[$name])) {
- return $this->extensionsByNs[$name];
- }
-
- throw new LogicException(sprintf('Container extension "%s" is not registered', $name));
- }
-
- /**
- * Returns all registered extensions.
- *
- * @return ExtensionInterface[] An array of ExtensionInterface
- */
- public function getExtensions()
- {
- return $this->extensions;
- }
-
- /**
- * Checks if we have an extension.
- *
- * @param string $name The name of the extension
- *
- * @return bool If the extension exists
- */
- public function hasExtension($name)
- {
- return isset($this->extensions[$name]) || isset($this->extensionsByNs[$name]);
- }
-
- /**
- * Returns an array of resources loaded to build this configuration.
- *
- * @return ResourceInterface[] An array of resources
- */
- public function getResources()
- {
- return array_values($this->resources);
- }
-
- /**
- * @return $this
- */
- public function addResource(ResourceInterface $resource)
- {
- if (!$this->trackResources) {
- return $this;
- }
-
- if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) {
- return $this;
- }
-
- $this->resources[(string) $resource] = $resource;
-
- return $this;
- }
-
- /**
- * Sets the resources for this configuration.
- *
- * @param ResourceInterface[] $resources An array of resources
- *
- * @return $this
- */
- public function setResources(array $resources)
- {
- if (!$this->trackResources) {
- return $this;
- }
-
- $this->resources = $resources;
-
- return $this;
- }
-
- /**
- * Adds the object class hierarchy as resources.
- *
- * @param object|string $object An object instance or class name
- *
- * @return $this
- */
- public function addObjectResource($object)
- {
- if ($this->trackResources) {
- if (\is_object($object)) {
- $object = \get_class($object);
- }
- if (!isset($this->classReflectors[$object])) {
- $this->classReflectors[$object] = new \ReflectionClass($object);
- }
- $class = $this->classReflectors[$object];
-
- foreach ($class->getInterfaceNames() as $name) {
- if (null === $interface = &$this->classReflectors[$name]) {
- $interface = new \ReflectionClass($name);
- }
- $file = $interface->getFileName();
- if (false !== $file && file_exists($file)) {
- $this->fileExists($file);
- }
- }
- do {
- $file = $class->getFileName();
- if (false !== $file && file_exists($file)) {
- $this->fileExists($file);
- }
- foreach ($class->getTraitNames() as $name) {
- $this->addObjectResource($name);
- }
- } while ($class = $class->getParentClass());
- }
-
- return $this;
- }
-
- /**
- * Retrieves the requested reflection class and registers it for resource tracking.
- *
- * @throws \ReflectionException when a parent class/interface/trait is not found and $throw is true
- *
- * @final
- */
- public function getReflectionClass(?string $class, bool $throw = true): ?\ReflectionClass
- {
- if (!$class = $this->getParameterBag()->resolveValue($class)) {
- return null;
- }
-
- if (isset(self::$internalTypes[$class])) {
- return null;
- }
-
- $resource = $classReflector = null;
-
- try {
- if (isset($this->classReflectors[$class])) {
- $classReflector = $this->classReflectors[$class];
- } elseif (class_exists(ClassExistenceResource::class)) {
- $resource = new ClassExistenceResource($class, false);
- $classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class);
- } else {
- $classReflector = class_exists($class) ? new \ReflectionClass($class) : false;
- }
- } catch (\ReflectionException $e) {
- if ($throw) {
- throw $e;
- }
- }
-
- if ($this->trackResources) {
- if (!$classReflector) {
- $this->addResource($resource ?: new ClassExistenceResource($class, false));
- } elseif (!$classReflector->isInternal()) {
- $path = $classReflector->getFileName();
-
- if (!$this->inVendors($path)) {
- $this->addResource(new ReflectionClassResource($classReflector, $this->vendors));
- }
- }
- $this->classReflectors[$class] = $classReflector;
- }
-
- return $classReflector ?: null;
- }
-
- /**
- * Checks whether the requested file or directory exists and registers the result for resource tracking.
- *
- * @param string $path The file or directory path for which to check the existence
- * @param bool|string $trackContents Whether to track contents of the given resource. If a string is passed,
- * it will be used as pattern for tracking contents of the requested directory
- *
- * @final
- */
- public function fileExists(string $path, $trackContents = true): bool
- {
- $exists = file_exists($path);
-
- if (!$this->trackResources || $this->inVendors($path)) {
- return $exists;
- }
-
- if (!$exists) {
- $this->addResource(new FileExistenceResource($path));
-
- return $exists;
- }
-
- if (is_dir($path)) {
- if ($trackContents) {
- $this->addResource(new DirectoryResource($path, \is_string($trackContents) ? $trackContents : null));
- } else {
- $this->addResource(new GlobResource($path, '/*', false));
- }
- } elseif ($trackContents) {
- $this->addResource(new FileResource($path));
- }
-
- return $exists;
- }
-
- /**
- * Loads the configuration for an extension.
- *
- * @param string $extension The extension alias or namespace
- * @param array $values An array of values that customizes the extension
- *
- * @return $this
- *
- * @throws BadMethodCallException When this ContainerBuilder is compiled
- * @throws \LogicException if the extension is not registered
- */
- public function loadFromExtension($extension, array $values = null)
- {
- if ($this->isCompiled()) {
- throw new BadMethodCallException('Cannot load from an extension on a compiled container.');
- }
-
- if (\func_num_args() < 2) {
- $values = [];
- }
-
- $namespace = $this->getExtension($extension)->getAlias();
-
- $this->extensionConfigs[$namespace][] = $values;
-
- return $this;
- }
-
- /**
- * Adds a compiler pass.
- *
- * @param string $type The type of compiler pass
- * @param int $priority Used to sort the passes
- *
- * @return $this
- */
- public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
- {
- $this->getCompiler()->addPass($pass, $type, $priority);
-
- $this->addObjectResource($pass);
-
- return $this;
- }
-
- /**
- * Returns the compiler pass config which can then be modified.
- *
- * @return PassConfig The compiler pass config
- */
- public function getCompilerPassConfig()
- {
- return $this->getCompiler()->getPassConfig();
- }
-
- /**
- * Returns the compiler.
- *
- * @return Compiler The compiler
- */
- public function getCompiler()
- {
- if (null === $this->compiler) {
- $this->compiler = new Compiler();
- }
-
- return $this->compiler;
- }
-
- /**
- * Sets a service.
- *
- * @param string $id The service identifier
- * @param object|null $service The service instance
- *
- * @throws BadMethodCallException When this ContainerBuilder is compiled
- */
- public function set($id, $service)
- {
- if (!\is_object($service) && null !== $service) {
- @trigger_error(sprintf('Non-object services are deprecated since Symfony 4.4, setting the "%s" service to a value of type "%s" should be avoided.', $id, \gettype($service)), E_USER_DEPRECATED);
- }
-
- $id = (string) $id;
-
- if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) {
- // setting a synthetic service on a compiled container is alright
- throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
- }
-
- unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
-
- parent::set($id, $service);
- }
-
- /**
- * Removes a service definition.
- *
- * @param string $id The service identifier
- */
- public function removeDefinition($id)
- {
- if (isset($this->definitions[$id = (string) $id])) {
- unset($this->definitions[$id]);
- $this->removedIds[$id] = true;
- }
- }
-
- /**
- * Returns true if the given service is defined.
- *
- * @param string $id The service identifier
- *
- * @return bool true if the service is defined, false otherwise
- */
- public function has($id)
- {
- $id = (string) $id;
-
- return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
- }
-
- /**
- * Gets a service.
- *
- * @param string $id The service identifier
- * @param int $invalidBehavior The behavior when the service does not exist
- *
- * @return object|null The associated service
- *
- * @throws InvalidArgumentException when no definitions are available
- * @throws ServiceCircularReferenceException When a circular reference is detected
- * @throws ServiceNotFoundException When the service is not defined
- * @throws \Exception
- *
- * @see Reference
- */
- public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
- {
- if ($this->isCompiled() && isset($this->removedIds[$id = (string) $id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
- return parent::get($id);
- }
-
- $service = $this->doGet($id, $invalidBehavior);
-
- if (!\is_object($service) && null !== $service) {
- @trigger_error(sprintf('Non-object services are deprecated since Symfony 4.4, please fix the "%s" service which is of type "%s" right now.', $id, \gettype($service)), E_USER_DEPRECATED);
- }
-
- return $service;
- }
-
- private function doGet(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, array &$inlineServices = null, bool $isConstructorArgument = false)
- {
- if (isset($inlineServices[$id])) {
- return $inlineServices[$id];
- }
- if (null === $inlineServices) {
- $isConstructorArgument = true;
- $inlineServices = [];
- }
- try {
- if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $invalidBehavior) {
- return parent::get($id, $invalidBehavior);
- }
- if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
- return $service;
- }
- } catch (ServiceCircularReferenceException $e) {
- if ($isConstructorArgument) {
- throw $e;
- }
- }
-
- if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
- $alias = $this->aliasDefinitions[$id];
-
- if ($alias->isDeprecated()) {
- @trigger_error($alias->getDeprecationMessage($id), E_USER_DEPRECATED);
- }
-
- return $this->doGet((string) $alias, $invalidBehavior, $inlineServices, $isConstructorArgument);
- }
-
- try {
- $definition = $this->getDefinition($id);
- } catch (ServiceNotFoundException $e) {
- if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $invalidBehavior) {
- return null;
- }
-
- throw $e;
- }
-
- if ($definition->hasErrors() && $e = $definition->getErrors()) {
- throw new RuntimeException(reset($e));
- }
-
- if ($isConstructorArgument) {
- $this->loading[$id] = true;
- }
-
- try {
- return $this->createService($definition, $inlineServices, $isConstructorArgument, $id);
- } finally {
- if ($isConstructorArgument) {
- unset($this->loading[$id]);
- }
- }
- }
-
- /**
- * Merges a ContainerBuilder with the current ContainerBuilder configuration.
- *
- * Service definitions overrides the current defined ones.
- *
- * But for parameters, they are overridden by the current ones. It allows
- * the parameters passed to the container constructor to have precedence
- * over the loaded ones.
- *
- * $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar']));
- * $loader = new LoaderXXX($container);
- * $loader->load('resource_name');
- * $container->register('foo', 'stdClass');
- *
- * In the above example, even if the loaded resource defines a foo
- * parameter, the value will still be 'bar' as defined in the ContainerBuilder
- * constructor.
- *
- * @throws BadMethodCallException When this ContainerBuilder is compiled
- */
- public function merge(self $container)
- {
- if ($this->isCompiled()) {
- throw new BadMethodCallException('Cannot merge on a compiled container.');
- }
-
- $this->addDefinitions($container->getDefinitions());
- $this->addAliases($container->getAliases());
- $this->getParameterBag()->add($container->getParameterBag()->all());
-
- if ($this->trackResources) {
- foreach ($container->getResources() as $resource) {
- $this->addResource($resource);
- }
- }
-
- foreach ($this->extensions as $name => $extension) {
- if (!isset($this->extensionConfigs[$name])) {
- $this->extensionConfigs[$name] = [];
- }
-
- $this->extensionConfigs[$name] = array_merge($this->extensionConfigs[$name], $container->getExtensionConfig($name));
- }
-
- if ($this->getParameterBag() instanceof EnvPlaceholderParameterBag && $container->getParameterBag() instanceof EnvPlaceholderParameterBag) {
- $envPlaceholders = $container->getParameterBag()->getEnvPlaceholders();
- $this->getParameterBag()->mergeEnvPlaceholders($container->getParameterBag());
- } else {
- $envPlaceholders = [];
- }
-
- foreach ($container->envCounters as $env => $count) {
- if (!$count && !isset($envPlaceholders[$env])) {
- continue;
- }
- if (!isset($this->envCounters[$env])) {
- $this->envCounters[$env] = $count;
- } else {
- $this->envCounters[$env] += $count;
- }
- }
-
- foreach ($container->getAutoconfiguredInstanceof() as $interface => $childDefinition) {
- if (isset($this->autoconfiguredInstanceof[$interface])) {
- throw new InvalidArgumentException(sprintf('"%s" has already been autoconfigured and merge() does not support merging autoconfiguration for the same class/interface.', $interface));
- }
-
- $this->autoconfiguredInstanceof[$interface] = $childDefinition;
- }
- }
-
- /**
- * Returns the configuration array for the given extension.
- *
- * @param string $name The name of the extension
- *
- * @return array An array of configuration
- */
- public function getExtensionConfig($name)
- {
- if (!isset($this->extensionConfigs[$name])) {
- $this->extensionConfigs[$name] = [];
- }
-
- return $this->extensionConfigs[$name];
- }
-
- /**
- * Prepends a config array to the configs of the given extension.
- *
- * @param string $name The name of the extension
- * @param array $config The config to set
- */
- public function prependExtensionConfig($name, array $config)
- {
- if (!isset($this->extensionConfigs[$name])) {
- $this->extensionConfigs[$name] = [];
- }
-
- array_unshift($this->extensionConfigs[$name], $config);
- }
-
- /**
- * Compiles the container.
- *
- * This method passes the container to compiler
- * passes whose job is to manipulate and optimize
- * the container.
- *
- * The main compiler passes roughly do four things:
- *
- * * The extension configurations are merged;
- * * Parameter values are resolved;
- * * The parameter bag is frozen;
- * * Extension loading is disabled.
- *
- * @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
- * env vars or be replaced by uniquely identifiable placeholders.
- * Set to "true" when you want to use the current ContainerBuilder
- * directly, keep to "false" when the container is dumped instead.
- */
- public function compile(bool $resolveEnvPlaceholders = false)
- {
- $compiler = $this->getCompiler();
-
- if ($this->trackResources) {
- foreach ($compiler->getPassConfig()->getPasses() as $pass) {
- $this->addObjectResource($pass);
- }
- }
- $bag = $this->getParameterBag();
-
- if ($resolveEnvPlaceholders && $bag instanceof EnvPlaceholderParameterBag) {
- $compiler->addPass(new ResolveEnvPlaceholdersPass(), PassConfig::TYPE_AFTER_REMOVING, -1000);
- }
-
- $compiler->compile($this);
-
- foreach ($this->definitions as $id => $definition) {
- if ($this->trackResources && $definition->isLazy()) {
- $this->getReflectionClass($definition->getClass());
- }
- }
-
- $this->extensionConfigs = [];
-
- if ($bag instanceof EnvPlaceholderParameterBag) {
- if ($resolveEnvPlaceholders) {
- $this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), true));
- }
-
- $this->envPlaceholders = $bag->getEnvPlaceholders();
- }
-
- parent::compile();
-
- foreach ($this->definitions + $this->aliasDefinitions as $id => $definition) {
- if (!$definition->isPublic() || $definition->isPrivate()) {
- $this->removedIds[$id] = true;
- }
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function getServiceIds()
- {
- return array_map('strval', array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliasDefinitions), parent::getServiceIds())));
- }
-
- /**
- * Gets removed service or alias ids.
- *
- * @return array
- */
- public function getRemovedIds()
- {
- return $this->removedIds;
- }
-
- /**
- * Adds the service aliases.
- */
- public function addAliases(array $aliases)
- {
- foreach ($aliases as $alias => $id) {
- $this->setAlias($alias, $id);
- }
- }
-
- /**
- * Sets the service aliases.
- */
- public function setAliases(array $aliases)
- {
- $this->aliasDefinitions = [];
- $this->addAliases($aliases);
- }
-
- /**
- * Sets an alias for an existing service.
- *
- * @param string $alias The alias to create
- * @param string|Alias $id The service to alias
- *
- * @return Alias
- *
- * @throws InvalidArgumentException if the id is not a string or an Alias
- * @throws InvalidArgumentException if the alias is for itself
- */
- public function setAlias($alias, $id)
- {
- $alias = (string) $alias;
-
- if ('' === $alias || '\\' === $alias[-1] || \strlen($alias) !== strcspn($alias, "\0\r\n'")) {
- throw new InvalidArgumentException(sprintf('Invalid alias id: "%s"', $alias));
- }
-
- if (\is_string($id)) {
- $id = new Alias($id);
- } elseif (!$id instanceof Alias) {
- throw new InvalidArgumentException('$id must be a string, or an Alias object.');
- }
-
- if ($alias === (string) $id) {
- throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
- }
-
- unset($this->definitions[$alias], $this->removedIds[$alias]);
-
- return $this->aliasDefinitions[$alias] = $id;
- }
-
- /**
- * Removes an alias.
- *
- * @param string $alias The alias to remove
- */
- public function removeAlias($alias)
- {
- if (isset($this->aliasDefinitions[$alias = (string) $alias])) {
- unset($this->aliasDefinitions[$alias]);
- $this->removedIds[$alias] = true;
- }
- }
-
- /**
- * Returns true if an alias exists under the given identifier.
- *
- * @param string $id The service identifier
- *
- * @return bool true if the alias exists, false otherwise
- */
- public function hasAlias($id)
- {
- return isset($this->aliasDefinitions[$id = (string) $id]);
- }
-
- /**
- * Gets all defined aliases.
- *
- * @return Alias[] An array of aliases
- */
- public function getAliases()
- {
- return $this->aliasDefinitions;
- }
-
- /**
- * Gets an alias.
- *
- * @param string $id The service identifier
- *
- * @return Alias An Alias instance
- *
- * @throws InvalidArgumentException if the alias does not exist
- */
- public function getAlias($id)
- {
- $id = (string) $id;
-
- if (!isset($this->aliasDefinitions[$id])) {
- throw new InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id));
- }
-
- return $this->aliasDefinitions[$id];
- }
-
- /**
- * Registers a service definition.
- *
- * This methods allows for simple registration of service definition
- * with a fluid interface.
- *
- * @param string $id The service identifier
- * @param string|null $class The service class
- *
- * @return Definition A Definition instance
- */
- public function register($id, $class = null)
- {
- return $this->setDefinition($id, new Definition($class));
- }
-
- /**
- * Registers an autowired service definition.
- *
- * This method implements a shortcut for using setDefinition() with
- * an autowired definition.
- *
- * @param string $id The service identifier
- * @param string|null $class The service class
- *
- * @return Definition The created definition
- */
- public function autowire($id, $class = null)
- {
- return $this->setDefinition($id, (new Definition($class))->setAutowired(true));
- }
-
- /**
- * Adds the service definitions.
- *
- * @param Definition[] $definitions An array of service definitions
- */
- public function addDefinitions(array $definitions)
- {
- foreach ($definitions as $id => $definition) {
- $this->setDefinition($id, $definition);
- }
- }
-
- /**
- * Sets the service definitions.
- *
- * @param Definition[] $definitions An array of service definitions
- */
- public function setDefinitions(array $definitions)
- {
- $this->definitions = [];
- $this->addDefinitions($definitions);
- }
-
- /**
- * Gets all service definitions.
- *
- * @return Definition[] An array of Definition instances
- */
- public function getDefinitions()
- {
- return $this->definitions;
- }
-
- /**
- * Sets a service definition.
- *
- * @param string $id The service identifier
- *
- * @return Definition the service definition
- *
- * @throws BadMethodCallException When this ContainerBuilder is compiled
- */
- public function setDefinition($id, Definition $definition)
- {
- if ($this->isCompiled()) {
- throw new BadMethodCallException('Adding definition to a compiled container is not allowed');
- }
-
- $id = (string) $id;
-
- if ('' === $id || '\\' === $id[-1] || \strlen($id) !== strcspn($id, "\0\r\n'")) {
- throw new InvalidArgumentException(sprintf('Invalid service id: "%s"', $id));
- }
-
- unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
-
- return $this->definitions[$id] = $definition;
- }
-
- /**
- * Returns true if a service definition exists under the given identifier.
- *
- * @param string $id The service identifier
- *
- * @return bool true if the service definition exists, false otherwise
- */
- public function hasDefinition($id)
- {
- return isset($this->definitions[(string) $id]);
- }
-
- /**
- * Gets a service definition.
- *
- * @param string $id The service identifier
- *
- * @return Definition A Definition instance
- *
- * @throws ServiceNotFoundException if the service definition does not exist
- */
- public function getDefinition($id)
- {
- $id = (string) $id;
-
- if (!isset($this->definitions[$id])) {
- throw new ServiceNotFoundException($id);
- }
-
- return $this->definitions[$id];
- }
-
- /**
- * Gets a service definition by id or alias.
- *
- * The method "unaliases" recursively to return a Definition instance.
- *
- * @param string $id The service identifier or alias
- *
- * @return Definition A Definition instance
- *
- * @throws ServiceNotFoundException if the service definition does not exist
- */
- public function findDefinition($id)
- {
- $id = (string) $id;
-
- $seen = [];
- while (isset($this->aliasDefinitions[$id])) {
- $id = (string) $this->aliasDefinitions[$id];
-
- if (isset($seen[$id])) {
-