Argument
2 years ago
Attribute
2 years ago
Exception
2 years ago
ParameterBag
3 years ago
Alias.php
4 years ago
ChildDefinition.php
4 years ago
Container.php
2 years ago
ContainerAwareInterface.php
2 years ago
ContainerAwareTrait.php
2 years ago
ContainerBuilder.php
2 years ago
ContainerInterface.php
4 years ago
Definition.php
2 years ago
EnvVarLoaderInterface.php
4 years ago
EnvVarProcessor.php
2 years ago
EnvVarProcessorInterface.php
4 years ago
ExpressionLanguage.php
2 years ago
ExpressionLanguageProvider.php
2 years ago
Parameter.php
4 years ago
Reference.php
4 years ago
ReverseContainer.php
2 years ago
ServiceLocator.php
2 years ago
TaggedContainerInterface.php
4 years ago
TypedReference.php
2 years ago
Variable.php
4 years ago
index.php
3 years ago
ContainerBuilder.php
966 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\DependencyInjection; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Composer\InstalledVersions; |
| 5 | use MailPoetVendor\Psr\Container\ContainerInterface as PsrContainerInterface; |
| 6 | use MailPoetVendor\Symfony\Component\Config\Resource\ClassExistenceResource; |
| 7 | use MailPoetVendor\Symfony\Component\Config\Resource\ComposerResource; |
| 8 | use MailPoetVendor\Symfony\Component\Config\Resource\DirectoryResource; |
| 9 | use MailPoetVendor\Symfony\Component\Config\Resource\FileExistenceResource; |
| 10 | use MailPoetVendor\Symfony\Component\Config\Resource\FileResource; |
| 11 | use MailPoetVendor\Symfony\Component\Config\Resource\GlobResource; |
| 12 | use MailPoetVendor\Symfony\Component\Config\Resource\ReflectionClassResource; |
| 13 | use MailPoetVendor\Symfony\Component\Config\Resource\ResourceInterface; |
| 14 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\AbstractArgument; |
| 15 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\IteratorArgument; |
| 16 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\RewindableGenerator; |
| 17 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; |
| 18 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\ServiceLocator; |
| 19 | use MailPoetVendor\Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; |
| 20 | use MailPoetVendor\Symfony\Component\DependencyInjection\Attribute\Target; |
| 21 | use MailPoetVendor\Symfony\Component\DependencyInjection\Compiler\Compiler; |
| 22 | use MailPoetVendor\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 23 | use MailPoetVendor\Symfony\Component\DependencyInjection\Compiler\PassConfig; |
| 24 | use MailPoetVendor\Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass; |
| 25 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\BadMethodCallException; |
| 26 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 27 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\LogicException; |
| 28 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\RuntimeException; |
| 29 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; |
| 30 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
| 31 | use MailPoetVendor\Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
| 32 | use MailPoetVendor\Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface; |
| 33 | use MailPoetVendor\Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator; |
| 34 | use MailPoetVendor\Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; |
| 35 | use MailPoetVendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
| 36 | use MailPoetVendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
| 37 | use MailPoetVendor\Symfony\Component\ExpressionLanguage\Expression; |
| 38 | use MailPoetVendor\Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; |
| 39 | class ContainerBuilder extends Container implements TaggedContainerInterface |
| 40 | { |
| 41 | private $extensions = []; |
| 42 | private $extensionsByNs = []; |
| 43 | private $definitions = []; |
| 44 | private $aliasDefinitions = []; |
| 45 | private $resources = []; |
| 46 | private $extensionConfigs = []; |
| 47 | private $compiler; |
| 48 | private $trackResources; |
| 49 | private $proxyInstantiator; |
| 50 | private $expressionLanguage; |
| 51 | private $expressionLanguageProviders = []; |
| 52 | private $usedTags = []; |
| 53 | private $envPlaceholders = []; |
| 54 | private $envCounters = []; |
| 55 | private $vendors; |
| 56 | private $autoconfiguredInstanceof = []; |
| 57 | private $autoconfiguredAttributes = []; |
| 58 | private $removedIds = []; |
| 59 | private $removedBindingIds = []; |
| 60 | private const INTERNAL_TYPES = ['int' => \true, 'float' => \true, 'string' => \true, 'bool' => \true, 'resource' => \true, 'object' => \true, 'array' => \true, 'null' => \true, 'callable' => \true, 'iterable' => \true, 'mixed' => \true]; |
| 61 | public function __construct(?ParameterBagInterface $parameterBag = null) |
| 62 | { |
| 63 | parent::__construct($parameterBag); |
| 64 | $this->trackResources = \interface_exists(ResourceInterface::class); |
| 65 | $this->setDefinition('service_container', (new Definition(ContainerInterface::class))->setSynthetic(\true)->setPublic(\true)); |
| 66 | $this->setAlias(PsrContainerInterface::class, new Alias('service_container', \false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage = 'The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.'); |
| 67 | $this->setAlias(ContainerInterface::class, new Alias('service_container', \false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage); |
| 68 | } |
| 69 | private $classReflectors; |
| 70 | public function setResourceTracking(bool $track) |
| 71 | { |
| 72 | $this->trackResources = $track; |
| 73 | } |
| 74 | public function isTrackingResources() |
| 75 | { |
| 76 | return $this->trackResources; |
| 77 | } |
| 78 | public function setProxyInstantiator(InstantiatorInterface $proxyInstantiator) |
| 79 | { |
| 80 | $this->proxyInstantiator = $proxyInstantiator; |
| 81 | } |
| 82 | public function registerExtension(ExtensionInterface $extension) |
| 83 | { |
| 84 | $this->extensions[$extension->getAlias()] = $extension; |
| 85 | if (\false !== $extension->getNamespace()) { |
| 86 | $this->extensionsByNs[$extension->getNamespace()] = $extension; |
| 87 | } |
| 88 | } |
| 89 | public function getExtension(string $name) |
| 90 | { |
| 91 | if (isset($this->extensions[$name])) { |
| 92 | return $this->extensions[$name]; |
| 93 | } |
| 94 | if (isset($this->extensionsByNs[$name])) { |
| 95 | return $this->extensionsByNs[$name]; |
| 96 | } |
| 97 | throw new LogicException(\sprintf('Container extension "%s" is not registered.', $name)); |
| 98 | } |
| 99 | public function getExtensions() |
| 100 | { |
| 101 | return $this->extensions; |
| 102 | } |
| 103 | public function hasExtension(string $name) |
| 104 | { |
| 105 | return isset($this->extensions[$name]) || isset($this->extensionsByNs[$name]); |
| 106 | } |
| 107 | public function getResources() |
| 108 | { |
| 109 | return \array_values($this->resources); |
| 110 | } |
| 111 | public function addResource(ResourceInterface $resource) |
| 112 | { |
| 113 | if (!$this->trackResources) { |
| 114 | return $this; |
| 115 | } |
| 116 | if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) { |
| 117 | return $this; |
| 118 | } |
| 119 | $this->resources[(string) $resource] = $resource; |
| 120 | return $this; |
| 121 | } |
| 122 | public function setResources(array $resources) |
| 123 | { |
| 124 | if (!$this->trackResources) { |
| 125 | return $this; |
| 126 | } |
| 127 | $this->resources = $resources; |
| 128 | return $this; |
| 129 | } |
| 130 | public function addObjectResource($object) |
| 131 | { |
| 132 | if ($this->trackResources) { |
| 133 | if (\is_object($object)) { |
| 134 | $object = \get_class($object); |
| 135 | } |
| 136 | if (!isset($this->classReflectors[$object])) { |
| 137 | $this->classReflectors[$object] = new \ReflectionClass($object); |
| 138 | } |
| 139 | $class = $this->classReflectors[$object]; |
| 140 | foreach ($class->getInterfaceNames() as $name) { |
| 141 | if (null === ($interface =& $this->classReflectors[$name])) { |
| 142 | $interface = new \ReflectionClass($name); |
| 143 | } |
| 144 | $file = $interface->getFileName(); |
| 145 | if (\false !== $file && \file_exists($file)) { |
| 146 | $this->fileExists($file); |
| 147 | } |
| 148 | } |
| 149 | do { |
| 150 | $file = $class->getFileName(); |
| 151 | if (\false !== $file && \file_exists($file)) { |
| 152 | $this->fileExists($file); |
| 153 | } |
| 154 | foreach ($class->getTraitNames() as $name) { |
| 155 | $this->addObjectResource($name); |
| 156 | } |
| 157 | } while ($class = $class->getParentClass()); |
| 158 | } |
| 159 | return $this; |
| 160 | } |
| 161 | public function getReflectionClass(?string $class, bool $throw = \true) : ?\ReflectionClass |
| 162 | { |
| 163 | if (!($class = $this->getParameterBag()->resolveValue($class))) { |
| 164 | return null; |
| 165 | } |
| 166 | if (isset(self::INTERNAL_TYPES[$class])) { |
| 167 | return null; |
| 168 | } |
| 169 | $resource = $classReflector = null; |
| 170 | try { |
| 171 | if (isset($this->classReflectors[$class])) { |
| 172 | $classReflector = $this->classReflectors[$class]; |
| 173 | } elseif (\class_exists(ClassExistenceResource::class)) { |
| 174 | $resource = new ClassExistenceResource($class, \false); |
| 175 | $classReflector = $resource->isFresh(0) ? \false : new \ReflectionClass($class); |
| 176 | } else { |
| 177 | $classReflector = \class_exists($class) ? new \ReflectionClass($class) : \false; |
| 178 | } |
| 179 | } catch (\ReflectionException $e) { |
| 180 | if ($throw) { |
| 181 | throw $e; |
| 182 | } |
| 183 | } |
| 184 | if ($this->trackResources) { |
| 185 | if (!$classReflector) { |
| 186 | $this->addResource($resource ?? new ClassExistenceResource($class, \false)); |
| 187 | } elseif (!$classReflector->isInternal()) { |
| 188 | $path = $classReflector->getFileName(); |
| 189 | if (!$this->inVendors($path)) { |
| 190 | $this->addResource(new ReflectionClassResource($classReflector, $this->vendors)); |
| 191 | } |
| 192 | } |
| 193 | $this->classReflectors[$class] = $classReflector; |
| 194 | } |
| 195 | return $classReflector ?: null; |
| 196 | } |
| 197 | public function fileExists(string $path, $trackContents = \true) : bool |
| 198 | { |
| 199 | $exists = \file_exists($path); |
| 200 | if (!$this->trackResources || $this->inVendors($path)) { |
| 201 | return $exists; |
| 202 | } |
| 203 | if (!$exists) { |
| 204 | $this->addResource(new FileExistenceResource($path)); |
| 205 | return $exists; |
| 206 | } |
| 207 | if (\is_dir($path)) { |
| 208 | if ($trackContents) { |
| 209 | $this->addResource(new DirectoryResource($path, \is_string($trackContents) ? $trackContents : null)); |
| 210 | } else { |
| 211 | $this->addResource(new GlobResource($path, '/*', \false)); |
| 212 | } |
| 213 | } elseif ($trackContents) { |
| 214 | $this->addResource(new FileResource($path)); |
| 215 | } |
| 216 | return $exists; |
| 217 | } |
| 218 | public function loadFromExtension(string $extension, ?array $values = null) |
| 219 | { |
| 220 | if ($this->isCompiled()) { |
| 221 | throw new BadMethodCallException('Cannot load from an extension on a compiled container.'); |
| 222 | } |
| 223 | $namespace = $this->getExtension($extension)->getAlias(); |
| 224 | $this->extensionConfigs[$namespace][] = $values ?? []; |
| 225 | return $this; |
| 226 | } |
| 227 | public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0) |
| 228 | { |
| 229 | $this->getCompiler()->addPass($pass, $type, $priority); |
| 230 | $this->addObjectResource($pass); |
| 231 | return $this; |
| 232 | } |
| 233 | public function getCompilerPassConfig() |
| 234 | { |
| 235 | return $this->getCompiler()->getPassConfig(); |
| 236 | } |
| 237 | public function getCompiler() |
| 238 | { |
| 239 | if (null === $this->compiler) { |
| 240 | $this->compiler = new Compiler(); |
| 241 | } |
| 242 | return $this->compiler; |
| 243 | } |
| 244 | public function set(string $id, ?object $service) |
| 245 | { |
| 246 | if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) { |
| 247 | // setting a synthetic service on a compiled container is alright |
| 248 | throw new BadMethodCallException(\sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id)); |
| 249 | } |
| 250 | unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]); |
| 251 | parent::set($id, $service); |
| 252 | } |
| 253 | public function removeDefinition(string $id) |
| 254 | { |
| 255 | if (isset($this->definitions[$id])) { |
| 256 | unset($this->definitions[$id]); |
| 257 | $this->removedIds[$id] = \true; |
| 258 | } |
| 259 | } |
| 260 | public function has(string $id) |
| 261 | { |
| 262 | return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id); |
| 263 | } |
| 264 | public function get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) |
| 265 | { |
| 266 | if ($this->isCompiled() && isset($this->removedIds[$id])) { |
| 267 | return ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior ? parent::get($id) : null; |
| 268 | } |
| 269 | return $this->doGet($id, $invalidBehavior); |
| 270 | } |
| 271 | private function doGet(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, ?array &$inlineServices = null, bool $isConstructorArgument = \false) |
| 272 | { |
| 273 | if (isset($inlineServices[$id])) { |
| 274 | return $inlineServices[$id]; |
| 275 | } |
| 276 | if (null === $inlineServices) { |
| 277 | $isConstructorArgument = \true; |
| 278 | $inlineServices = []; |
| 279 | } |
| 280 | try { |
| 281 | if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $invalidBehavior) { |
| 282 | return $this->privates[$id] ?? parent::get($id, $invalidBehavior); |
| 283 | } |
| 284 | if (null !== ($service = $this->privates[$id] ?? parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE))) { |
| 285 | return $service; |
| 286 | } |
| 287 | } catch (ServiceCircularReferenceException $e) { |
| 288 | if ($isConstructorArgument) { |
| 289 | throw $e; |
| 290 | } |
| 291 | } |
| 292 | if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) { |
| 293 | $alias = $this->aliasDefinitions[$id]; |
| 294 | if ($alias->isDeprecated()) { |
| 295 | $deprecation = $alias->getDeprecation($id); |
| 296 | trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']); |
| 297 | } |
| 298 | return $this->doGet((string) $alias, $invalidBehavior, $inlineServices, $isConstructorArgument); |
| 299 | } |
| 300 | try { |
| 301 | $definition = $this->getDefinition($id); |
| 302 | } catch (ServiceNotFoundException $e) { |
| 303 | if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $invalidBehavior) { |
| 304 | return null; |
| 305 | } |
| 306 | throw $e; |
| 307 | } |
| 308 | if ($definition->hasErrors() && ($e = $definition->getErrors())) { |
| 309 | throw new RuntimeException(\reset($e)); |
| 310 | } |
| 311 | if ($isConstructorArgument) { |
| 312 | $this->loading[$id] = \true; |
| 313 | } |
| 314 | try { |
| 315 | return $this->createService($definition, $inlineServices, $isConstructorArgument, $id); |
| 316 | } finally { |
| 317 | if ($isConstructorArgument) { |
| 318 | unset($this->loading[$id]); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | public function merge(self $container) |
| 323 | { |
| 324 | if ($this->isCompiled()) { |
| 325 | throw new BadMethodCallException('Cannot merge on a compiled container.'); |
| 326 | } |
| 327 | $this->addDefinitions($container->getDefinitions()); |
| 328 | $this->addAliases($container->getAliases()); |
| 329 | $this->getParameterBag()->add($container->getParameterBag()->all()); |
| 330 | if ($this->trackResources) { |
| 331 | foreach ($container->getResources() as $resource) { |
| 332 | $this->addResource($resource); |
| 333 | } |
| 334 | } |
| 335 | foreach ($this->extensions as $name => $extension) { |
| 336 | if (!isset($this->extensionConfigs[$name])) { |
| 337 | $this->extensionConfigs[$name] = []; |
| 338 | } |
| 339 | $this->extensionConfigs[$name] = \array_merge($this->extensionConfigs[$name], $container->getExtensionConfig($name)); |
| 340 | } |
| 341 | if ($this->getParameterBag() instanceof EnvPlaceholderParameterBag && $container->getParameterBag() instanceof EnvPlaceholderParameterBag) { |
| 342 | $envPlaceholders = $container->getParameterBag()->getEnvPlaceholders(); |
| 343 | $this->getParameterBag()->mergeEnvPlaceholders($container->getParameterBag()); |
| 344 | } else { |
| 345 | $envPlaceholders = []; |
| 346 | } |
| 347 | foreach ($container->envCounters as $env => $count) { |
| 348 | if (!$count && !isset($envPlaceholders[$env])) { |
| 349 | continue; |
| 350 | } |
| 351 | if (!isset($this->envCounters[$env])) { |
| 352 | $this->envCounters[$env] = $count; |
| 353 | } else { |
| 354 | $this->envCounters[$env] += $count; |
| 355 | } |
| 356 | } |
| 357 | foreach ($container->getAutoconfiguredInstanceof() as $interface => $childDefinition) { |
| 358 | if (isset($this->autoconfiguredInstanceof[$interface])) { |
| 359 | throw new InvalidArgumentException(\sprintf('"%s" has already been autoconfigured and merge() does not support merging autoconfiguration for the same class/interface.', $interface)); |
| 360 | } |
| 361 | $this->autoconfiguredInstanceof[$interface] = $childDefinition; |
| 362 | } |
| 363 | foreach ($container->getAutoconfiguredAttributes() as $attribute => $configurator) { |
| 364 | if (isset($this->autoconfiguredAttributes[$attribute])) { |
| 365 | throw new InvalidArgumentException(\sprintf('"%s" has already been autoconfigured and merge() does not support merging autoconfiguration for the same attribute.', $attribute)); |
| 366 | } |
| 367 | $this->autoconfiguredAttributes[$attribute] = $configurator; |
| 368 | } |
| 369 | } |
| 370 | public function getExtensionConfig(string $name) |
| 371 | { |
| 372 | if (!isset($this->extensionConfigs[$name])) { |
| 373 | $this->extensionConfigs[$name] = []; |
| 374 | } |
| 375 | return $this->extensionConfigs[$name]; |
| 376 | } |
| 377 | public function prependExtensionConfig(string $name, array $config) |
| 378 | { |
| 379 | if (!isset($this->extensionConfigs[$name])) { |
| 380 | $this->extensionConfigs[$name] = []; |
| 381 | } |
| 382 | \array_unshift($this->extensionConfigs[$name], $config); |
| 383 | } |
| 384 | public function compile(bool $resolveEnvPlaceholders = \false) |
| 385 | { |
| 386 | $compiler = $this->getCompiler(); |
| 387 | if ($this->trackResources) { |
| 388 | foreach ($compiler->getPassConfig()->getPasses() as $pass) { |
| 389 | $this->addObjectResource($pass); |
| 390 | } |
| 391 | } |
| 392 | $bag = $this->getParameterBag(); |
| 393 | if ($resolveEnvPlaceholders && $bag instanceof EnvPlaceholderParameterBag) { |
| 394 | $compiler->addPass(new ResolveEnvPlaceholdersPass(), PassConfig::TYPE_AFTER_REMOVING, -1000); |
| 395 | } |
| 396 | $compiler->compile($this); |
| 397 | foreach ($this->definitions as $id => $definition) { |
| 398 | if ($this->trackResources && $definition->isLazy()) { |
| 399 | $this->getReflectionClass($definition->getClass()); |
| 400 | } |
| 401 | } |
| 402 | $this->extensionConfigs = []; |
| 403 | if ($bag instanceof EnvPlaceholderParameterBag) { |
| 404 | if ($resolveEnvPlaceholders) { |
| 405 | $this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), \true)); |
| 406 | } |
| 407 | $this->envPlaceholders = $bag->getEnvPlaceholders(); |
| 408 | } |
| 409 | parent::compile(); |
| 410 | foreach ($this->definitions + $this->aliasDefinitions as $id => $definition) { |
| 411 | if (!$definition->isPublic() || $definition->isPrivate()) { |
| 412 | $this->removedIds[$id] = \true; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | public function getServiceIds() |
| 417 | { |
| 418 | return \array_map('strval', \array_unique(\array_merge(\array_keys($this->getDefinitions()), \array_keys($this->aliasDefinitions), parent::getServiceIds()))); |
| 419 | } |
| 420 | public function getRemovedIds() |
| 421 | { |
| 422 | return $this->removedIds; |
| 423 | } |
| 424 | public function addAliases(array $aliases) |
| 425 | { |
| 426 | foreach ($aliases as $alias => $id) { |
| 427 | $this->setAlias($alias, $id); |
| 428 | } |
| 429 | } |
| 430 | public function setAliases(array $aliases) |
| 431 | { |
| 432 | $this->aliasDefinitions = []; |
| 433 | $this->addAliases($aliases); |
| 434 | } |
| 435 | public function setAlias(string $alias, $id) |
| 436 | { |
| 437 | if ('' === $alias || '\\' === $alias[-1] || \strlen($alias) !== \strcspn($alias, "\x00\r\n'")) { |
| 438 | throw new InvalidArgumentException(\sprintf('Invalid alias id: "%s".', $alias)); |
| 439 | } |
| 440 | if (\is_string($id)) { |
| 441 | $id = new Alias($id); |
| 442 | } elseif (!$id instanceof Alias) { |
| 443 | throw new InvalidArgumentException('$id must be a string, or an Alias object.'); |
| 444 | } |
| 445 | if ($alias === (string) $id) { |
| 446 | throw new InvalidArgumentException(\sprintf('An alias cannot reference itself, got a circular reference on "%s".', $alias)); |
| 447 | } |
| 448 | unset($this->definitions[$alias], $this->removedIds[$alias]); |
| 449 | return $this->aliasDefinitions[$alias] = $id; |
| 450 | } |
| 451 | public function removeAlias(string $alias) |
| 452 | { |
| 453 | if (isset($this->aliasDefinitions[$alias])) { |
| 454 | unset($this->aliasDefinitions[$alias]); |
| 455 | $this->removedIds[$alias] = \true; |
| 456 | } |
| 457 | } |
| 458 | public function hasAlias(string $id) |
| 459 | { |
| 460 | return isset($this->aliasDefinitions[$id]); |
| 461 | } |
| 462 | public function getAliases() |
| 463 | { |
| 464 | return $this->aliasDefinitions; |
| 465 | } |
| 466 | public function getAlias(string $id) |
| 467 | { |
| 468 | if (!isset($this->aliasDefinitions[$id])) { |
| 469 | throw new InvalidArgumentException(\sprintf('The service alias "%s" does not exist.', $id)); |
| 470 | } |
| 471 | return $this->aliasDefinitions[$id]; |
| 472 | } |
| 473 | public function register(string $id, ?string $class = null) |
| 474 | { |
| 475 | return $this->setDefinition($id, new Definition($class)); |
| 476 | } |
| 477 | public function autowire(string $id, ?string $class = null) |
| 478 | { |
| 479 | return $this->setDefinition($id, (new Definition($class))->setAutowired(\true)); |
| 480 | } |
| 481 | public function addDefinitions(array $definitions) |
| 482 | { |
| 483 | foreach ($definitions as $id => $definition) { |
| 484 | $this->setDefinition($id, $definition); |
| 485 | } |
| 486 | } |
| 487 | public function setDefinitions(array $definitions) |
| 488 | { |
| 489 | $this->definitions = []; |
| 490 | $this->addDefinitions($definitions); |
| 491 | } |
| 492 | public function getDefinitions() |
| 493 | { |
| 494 | return $this->definitions; |
| 495 | } |
| 496 | public function setDefinition(string $id, Definition $definition) |
| 497 | { |
| 498 | if ($this->isCompiled()) { |
| 499 | throw new BadMethodCallException('Adding definition to a compiled container is not allowed.'); |
| 500 | } |
| 501 | if ('' === $id || '\\' === $id[-1] || \strlen($id) !== \strcspn($id, "\x00\r\n'")) { |
| 502 | throw new InvalidArgumentException(\sprintf('Invalid service id: "%s".', $id)); |
| 503 | } |
| 504 | unset($this->aliasDefinitions[$id], $this->removedIds[$id]); |
| 505 | return $this->definitions[$id] = $definition; |
| 506 | } |
| 507 | public function hasDefinition(string $id) |
| 508 | { |
| 509 | return isset($this->definitions[$id]); |
| 510 | } |
| 511 | public function getDefinition(string $id) |
| 512 | { |
| 513 | if (!isset($this->definitions[$id])) { |
| 514 | throw new ServiceNotFoundException($id); |
| 515 | } |
| 516 | return $this->definitions[$id]; |
| 517 | } |
| 518 | public function findDefinition(string $id) |
| 519 | { |
| 520 | $seen = []; |
| 521 | while (isset($this->aliasDefinitions[$id])) { |
| 522 | $id = (string) $this->aliasDefinitions[$id]; |
| 523 | if (isset($seen[$id])) { |
| 524 | $seen = \array_values($seen); |
| 525 | $seen = \array_slice($seen, \array_search($id, $seen)); |
| 526 | $seen[] = $id; |
| 527 | throw new ServiceCircularReferenceException($id, $seen); |
| 528 | } |
| 529 | $seen[$id] = $id; |
| 530 | } |
| 531 | return $this->getDefinition($id); |
| 532 | } |
| 533 | private function createService(Definition $definition, array &$inlineServices, bool $isConstructorArgument = \false, ?string $id = null, bool $tryProxy = \true) |
| 534 | { |
| 535 | if (null === $id && isset($inlineServices[$h = \spl_object_hash($definition)])) { |
| 536 | return $inlineServices[$h]; |
| 537 | } |
| 538 | if ($definition instanceof ChildDefinition) { |
| 539 | throw new RuntimeException(\sprintf('Constructing service "%s" from a parent definition is not supported at build time.', $id)); |
| 540 | } |
| 541 | if ($definition->isSynthetic()) { |
| 542 | throw new RuntimeException(\sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id)); |
| 543 | } |
| 544 | if ($definition->isDeprecated()) { |
| 545 | $deprecation = $definition->getDeprecation($id); |
| 546 | trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']); |
| 547 | } |
| 548 | if ($tryProxy && $definition->isLazy() && !($tryProxy = !($proxy = $this->proxyInstantiator) || $proxy instanceof RealServiceInstantiator)) { |
| 549 | $proxy = $proxy->instantiateProxy($this, $definition, $id, function () use($definition, &$inlineServices, $id) { |
| 550 | return $this->createService($definition, $inlineServices, \true, $id, \false); |
| 551 | }); |
| 552 | $this->shareService($definition, $proxy, $id, $inlineServices); |
| 553 | return $proxy; |
| 554 | } |
| 555 | $parameterBag = $this->getParameterBag(); |
| 556 | if (null !== $definition->getFile()) { |
| 557 | require_once $parameterBag->resolveValue($definition->getFile()); |
| 558 | } |
| 559 | $arguments = $this->doResolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())), $inlineServices, $isConstructorArgument); |
| 560 | if (null !== ($factory = $definition->getFactory())) { |
| 561 | if (\is_array($factory)) { |
| 562 | $factory = [$this->doResolveServices($parameterBag->resolveValue($factory[0]), $inlineServices, $isConstructorArgument), $factory[1]]; |
| 563 | } elseif (!\is_string($factory)) { |
| 564 | throw new RuntimeException(\sprintf('Cannot create service "%s" because of invalid factory.', $id)); |
| 565 | } |
| 566 | } |
| 567 | if (null !== $id && $definition->isShared() && (isset($this->services[$id]) || isset($this->privates[$id])) && ($tryProxy || !$definition->isLazy())) { |
| 568 | return $this->services[$id] ?? $this->privates[$id]; |
| 569 | } |
| 570 | if (!\array_is_list($arguments)) { |
| 571 | $arguments = \array_combine(\array_map(function ($k) { |
| 572 | return \preg_replace('/^.*\\$/', '', $k); |
| 573 | }, \array_keys($arguments)), $arguments); |
| 574 | } |
| 575 | if (null !== $factory) { |
| 576 | $service = $factory(...$arguments); |
| 577 | if (!$definition->isDeprecated() && \is_array($factory) && \is_string($factory[0])) { |
| 578 | $r = new \ReflectionClass($factory[0]); |
| 579 | if (0 < \strpos($r->getDocComment(), "\n * @deprecated ")) { |
| 580 | trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id, $r->name); |
| 581 | } |
| 582 | } |
| 583 | } else { |
| 584 | $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); |
| 585 | $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); |
| 586 | if (!$definition->isDeprecated() && 0 < \strpos($r->getDocComment(), "\n * @deprecated ")) { |
| 587 | trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name); |
| 588 | } |
| 589 | } |
| 590 | $lastWitherIndex = null; |
| 591 | foreach ($definition->getMethodCalls() as $k => $call) { |
| 592 | if ($call[2] ?? \false) { |
| 593 | $lastWitherIndex = $k; |
| 594 | } |
| 595 | } |
| 596 | if (null === $lastWitherIndex && ($tryProxy || !$definition->isLazy())) { |
| 597 | // share only if proxying failed, or if not a proxy, and if no withers are found |
| 598 | $this->shareService($definition, $service, $id, $inlineServices); |
| 599 | } |
| 600 | $properties = $this->doResolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())), $inlineServices); |
| 601 | foreach ($properties as $name => $value) { |
| 602 | $service->{$name} = $value; |
| 603 | } |
| 604 | foreach ($definition->getMethodCalls() as $k => $call) { |
| 605 | $service = $this->callMethod($service, $call, $inlineServices); |
| 606 | if ($lastWitherIndex === $k && ($tryProxy || !$definition->isLazy())) { |
| 607 | // share only if proxying failed, or if not a proxy, and this is the last wither |
| 608 | $this->shareService($definition, $service, $id, $inlineServices); |
| 609 | } |
| 610 | } |
| 611 | if ($callable = $definition->getConfigurator()) { |
| 612 | if (\is_array($callable)) { |
| 613 | $callable[0] = $parameterBag->resolveValue($callable[0]); |
| 614 | if ($callable[0] instanceof Reference) { |
| 615 | $callable[0] = $this->doGet((string) $callable[0], $callable[0]->getInvalidBehavior(), $inlineServices); |
| 616 | } elseif ($callable[0] instanceof Definition) { |
| 617 | $callable[0] = $this->createService($callable[0], $inlineServices); |
| 618 | } |
| 619 | } |
| 620 | if (!\is_callable($callable)) { |
| 621 | throw new InvalidArgumentException(\sprintf('The configure callable for class "%s" is not a callable.', \get_debug_type($service))); |
| 622 | } |
| 623 | $callable($service); |
| 624 | } |
| 625 | return $service; |
| 626 | } |
| 627 | public function resolveServices($value) |
| 628 | { |
| 629 | return $this->doResolveServices($value); |
| 630 | } |
| 631 | private function doResolveServices($value, array &$inlineServices = [], bool $isConstructorArgument = \false) |
| 632 | { |
| 633 | if (\is_array($value)) { |
| 634 | foreach ($value as $k => $v) { |
| 635 | $value[$k] = $this->doResolveServices($v, $inlineServices, $isConstructorArgument); |
| 636 | } |
| 637 | } elseif ($value instanceof ServiceClosureArgument) { |
| 638 | $reference = $value->getValues()[0]; |
| 639 | $value = function () use($reference) { |
| 640 | return $this->resolveServices($reference); |
| 641 | }; |
| 642 | } elseif ($value instanceof IteratorArgument) { |
| 643 | $value = new RewindableGenerator(function () use($value, &$inlineServices) { |
| 644 | foreach ($value->getValues() as $k => $v) { |
| 645 | foreach (self::getServiceConditionals($v) as $s) { |
| 646 | if (!$this->has($s)) { |
| 647 | continue 2; |
| 648 | } |
| 649 | } |
| 650 | foreach (self::getInitializedConditionals($v) as $s) { |
| 651 | if (!$this->doGet($s, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE, $inlineServices)) { |
| 652 | continue 2; |
| 653 | } |
| 654 | } |
| 655 | (yield $k => $this->doResolveServices($v, $inlineServices)); |
| 656 | } |
| 657 | }, function () use($value) : int { |
| 658 | $count = 0; |
| 659 | foreach ($value->getValues() as $v) { |
| 660 | foreach (self::getServiceConditionals($v) as $s) { |
| 661 | if (!$this->has($s)) { |
| 662 | continue 2; |
| 663 | } |
| 664 | } |
| 665 | foreach (self::getInitializedConditionals($v) as $s) { |
| 666 | if (!$this->doGet($s, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)) { |
| 667 | continue 2; |
| 668 | } |
| 669 | } |
| 670 | ++$count; |
| 671 | } |
| 672 | return $count; |
| 673 | }); |
| 674 | } elseif ($value instanceof ServiceLocatorArgument) { |
| 675 | $refs = $types = []; |
| 676 | foreach ($value->getValues() as $k => $v) { |
| 677 | if ($v) { |
| 678 | $refs[$k] = [$v]; |
| 679 | $types[$k] = $v instanceof TypedReference ? $v->getType() : '?'; |
| 680 | } |
| 681 | } |
| 682 | $value = new ServiceLocator(\Closure::fromCallable([$this, 'resolveServices']), $refs, $types); |
| 683 | } elseif ($value instanceof Reference) { |
| 684 | $value = $this->doGet((string) $value, $value->getInvalidBehavior(), $inlineServices, $isConstructorArgument); |
| 685 | } elseif ($value instanceof Definition) { |
| 686 | $value = $this->createService($value, $inlineServices, $isConstructorArgument); |
| 687 | } elseif ($value instanceof Parameter) { |
| 688 | $value = $this->getParameter((string) $value); |
| 689 | } elseif ($value instanceof Expression) { |
| 690 | $value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this]); |
| 691 | } elseif ($value instanceof AbstractArgument) { |
| 692 | throw new RuntimeException($value->getTextWithContext()); |
| 693 | } |
| 694 | return $value; |
| 695 | } |
| 696 | public function findTaggedServiceIds(string $name, bool $throwOnAbstract = \false) |
| 697 | { |
| 698 | $this->usedTags[] = $name; |
| 699 | $tags = []; |
| 700 | foreach ($this->getDefinitions() as $id => $definition) { |
| 701 | if ($definition->hasTag($name)) { |
| 702 | if ($throwOnAbstract && $definition->isAbstract()) { |
| 703 | throw new InvalidArgumentException(\sprintf('The service "%s" tagged "%s" must not be abstract.', $id, $name)); |
| 704 | } |
| 705 | $tags[$id] = $definition->getTag($name); |
| 706 | } |
| 707 | } |
| 708 | return $tags; |
| 709 | } |
| 710 | public function findTags() |
| 711 | { |
| 712 | $tags = []; |
| 713 | foreach ($this->getDefinitions() as $id => $definition) { |
| 714 | $tags[] = \array_keys($definition->getTags()); |
| 715 | } |
| 716 | return \array_unique(\array_merge([], ...$tags)); |
| 717 | } |
| 718 | public function findUnusedTags() |
| 719 | { |
| 720 | return \array_values(\array_diff($this->findTags(), $this->usedTags)); |
| 721 | } |
| 722 | public function addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider) |
| 723 | { |
| 724 | $this->expressionLanguageProviders[] = $provider; |
| 725 | } |
| 726 | public function getExpressionLanguageProviders() |
| 727 | { |
| 728 | return $this->expressionLanguageProviders; |
| 729 | } |
| 730 | public function registerForAutoconfiguration(string $interface) |
| 731 | { |
| 732 | if (!isset($this->autoconfiguredInstanceof[$interface])) { |
| 733 | $this->autoconfiguredInstanceof[$interface] = new ChildDefinition(''); |
| 734 | } |
| 735 | return $this->autoconfiguredInstanceof[$interface]; |
| 736 | } |
| 737 | public function registerAttributeForAutoconfiguration(string $attributeClass, callable $configurator) : void |
| 738 | { |
| 739 | $this->autoconfiguredAttributes[$attributeClass] = $configurator; |
| 740 | } |
| 741 | public function registerAliasForArgument(string $id, string $type, ?string $name = null) : Alias |
| 742 | { |
| 743 | $name = (new Target($name ?? $id))->name; |
| 744 | if (!\preg_match('/^[a-zA-Z_\\x7f-\\xff]/', $name)) { |
| 745 | throw new InvalidArgumentException(\sprintf('Invalid argument name "%s" for service "%s": the first character must be a letter.', $name, $id)); |
| 746 | } |
| 747 | return $this->setAlias($type . ' $' . $name, $id); |
| 748 | } |
| 749 | public function getAutoconfiguredInstanceof() |
| 750 | { |
| 751 | return $this->autoconfiguredInstanceof; |
| 752 | } |
| 753 | public function getAutoconfiguredAttributes() : array |
| 754 | { |
| 755 | return $this->autoconfiguredAttributes; |
| 756 | } |
| 757 | public function resolveEnvPlaceholders($value, $format = null, ?array &$usedEnvs = null) |
| 758 | { |
| 759 | if (null === $format) { |
| 760 | $format = '%%env(%s)%%'; |
| 761 | } |
| 762 | $bag = $this->getParameterBag(); |
| 763 | if (\true === $format) { |
| 764 | $value = $bag->resolveValue($value); |
| 765 | } |
| 766 | if ($value instanceof Definition) { |
| 767 | $value = (array) $value; |
| 768 | } |
| 769 | if (\is_array($value)) { |
| 770 | $result = []; |
| 771 | foreach ($value as $k => $v) { |
| 772 | $result[\is_string($k) ? $this->resolveEnvPlaceholders($k, $format, $usedEnvs) : $k] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs); |
| 773 | } |
| 774 | return $result; |
| 775 | } |
| 776 | if (!\is_string($value) || 38 > \strlen($value) || !\preg_match('/env[_(]/i', $value)) { |
| 777 | return $value; |
| 778 | } |
| 779 | $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; |
| 780 | $completed = \false; |
| 781 | foreach ($envPlaceholders as $env => $placeholders) { |
| 782 | foreach ($placeholders as $placeholder) { |
| 783 | if (\false !== \stripos($value, $placeholder)) { |
| 784 | if (\true === $format) { |
| 785 | $resolved = $bag->escapeValue($this->getEnv($env)); |
| 786 | } else { |
| 787 | $resolved = \sprintf($format, $env); |
| 788 | } |
| 789 | if ($placeholder === $value) { |
| 790 | $value = $resolved; |
| 791 | $completed = \true; |
| 792 | } else { |
| 793 | if (!\is_string($resolved) && !\is_numeric($resolved)) { |
| 794 | throw new RuntimeException(\sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type "%s" inside string value "%s".', $env, \get_debug_type($resolved), $this->resolveEnvPlaceholders($value))); |
| 795 | } |
| 796 | $value = \str_ireplace($placeholder, $resolved, $value); |
| 797 | } |
| 798 | $usedEnvs[$env] = $env; |
| 799 | $this->envCounters[$env] = isset($this->envCounters[$env]) ? 1 + $this->envCounters[$env] : 1; |
| 800 | if ($completed) { |
| 801 | break 2; |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | return $value; |
| 807 | } |
| 808 | public function getEnvCounters() |
| 809 | { |
| 810 | $bag = $this->getParameterBag(); |
| 811 | $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; |
| 812 | foreach ($envPlaceholders as $env => $placeholders) { |
| 813 | if (!isset($this->envCounters[$env])) { |
| 814 | $this->envCounters[$env] = 0; |
| 815 | } |
| 816 | } |
| 817 | return $this->envCounters; |
| 818 | } |
| 819 | public function log(CompilerPassInterface $pass, string $message) |
| 820 | { |
| 821 | $this->getCompiler()->log($pass, $this->resolveEnvPlaceholders($message)); |
| 822 | } |
| 823 | public static final function willBeAvailable(string $package, string $class, array $parentPackages) : bool |
| 824 | { |
| 825 | $skipDeprecation = 3 < \func_num_args() && \func_get_arg(3); |
| 826 | $hasRuntimeApi = \class_exists(InstalledVersions::class); |
| 827 | if (!$hasRuntimeApi && !$skipDeprecation) { |
| 828 | trigger_deprecation('symfony/dependency-injection', '5.4', 'Calling "%s" when dependencies have been installed with Composer 1 is deprecated. Consider upgrading to Composer 2.', __METHOD__); |
| 829 | } |
| 830 | if (!\class_exists($class) && !\interface_exists($class, \false) && !\trait_exists($class, \false)) { |
| 831 | return \false; |
| 832 | } |
| 833 | if (!$hasRuntimeApi || !InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, \false)) { |
| 834 | return \true; |
| 835 | } |
| 836 | // the package is installed but in dev-mode only, check if this applies to one of the parent packages too |
| 837 | $rootPackage = InstalledVersions::getRootPackage()['name'] ?? ''; |
| 838 | if ('symfony/symfony' === $rootPackage) { |
| 839 | return \true; |
| 840 | } |
| 841 | foreach ($parentPackages as $parentPackage) { |
| 842 | if ($rootPackage === $parentPackage || InstalledVersions::isInstalled($parentPackage) && !InstalledVersions::isInstalled($parentPackage, \false)) { |
| 843 | return \true; |
| 844 | } |
| 845 | } |
| 846 | return \false; |
| 847 | } |
| 848 | public function getRemovedBindingIds() : array |
| 849 | { |
| 850 | return $this->removedBindingIds; |
| 851 | } |
| 852 | public function removeBindings(string $id) |
| 853 | { |
| 854 | if ($this->hasDefinition($id)) { |
| 855 | foreach ($this->getDefinition($id)->getBindings() as $key => $binding) { |
| 856 | [, $bindingId] = $binding->getValues(); |
| 857 | $this->removedBindingIds[(int) $bindingId] = \true; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | public static function getServiceConditionals($value) : array |
| 862 | { |
| 863 | $services = []; |
| 864 | if (\is_array($value)) { |
| 865 | foreach ($value as $v) { |
| 866 | $services = \array_unique(\array_merge($services, self::getServiceConditionals($v))); |
| 867 | } |
| 868 | } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) { |
| 869 | $services[] = (string) $value; |
| 870 | } |
| 871 | return $services; |
| 872 | } |
| 873 | public static function getInitializedConditionals($value) : array |
| 874 | { |
| 875 | $services = []; |
| 876 | if (\is_array($value)) { |
| 877 | foreach ($value as $v) { |
| 878 | $services = \array_unique(\array_merge($services, self::getInitializedConditionals($v))); |
| 879 | } |
| 880 | } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior()) { |
| 881 | $services[] = (string) $value; |
| 882 | } |
| 883 | return $services; |
| 884 | } |
| 885 | public static function hash($value) |
| 886 | { |
| 887 | $hash = \substr(\base64_encode(\hash('sha256', \serialize($value), \true)), 0, 7); |
| 888 | return \str_replace(['/', '+'], ['.', '_'], $hash); |
| 889 | } |
| 890 | protected function getEnv(string $name) |
| 891 | { |
| 892 | $value = parent::getEnv($name); |
| 893 | $bag = $this->getParameterBag(); |
| 894 | if (!\is_string($value) || !$bag instanceof EnvPlaceholderParameterBag) { |
| 895 | return $value; |
| 896 | } |
| 897 | $envPlaceholders = $bag->getEnvPlaceholders(); |
| 898 | if (isset($envPlaceholders[$name][$value])) { |
| 899 | $bag = new ParameterBag($bag->all()); |
| 900 | return $bag->unescapeValue($bag->get("env({$name})")); |
| 901 | } |
| 902 | foreach ($envPlaceholders as $env => $placeholders) { |
| 903 | if (isset($placeholders[$value])) { |
| 904 | return $this->getEnv($env); |
| 905 | } |
| 906 | } |
| 907 | $this->resolving["env({$name})"] = \true; |
| 908 | try { |
| 909 | return $bag->unescapeValue($this->resolveEnvPlaceholders($bag->escapeValue($value), \true)); |
| 910 | } finally { |
| 911 | unset($this->resolving["env({$name})"]); |
| 912 | } |
| 913 | } |
| 914 | private function callMethod(object $service, array $call, array &$inlineServices) |
| 915 | { |
| 916 | foreach (self::getServiceConditionals($call[1]) as $s) { |
| 917 | if (!$this->has($s)) { |
| 918 | return $service; |
| 919 | } |
| 920 | } |
| 921 | foreach (self::getInitializedConditionals($call[1]) as $s) { |
| 922 | if (!$this->doGet($s, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE, $inlineServices)) { |
| 923 | return $service; |
| 924 | } |
| 925 | } |
| 926 | $result = $service->{$call[0]}(...$this->doResolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1])), $inlineServices)); |
| 927 | return empty($call[2]) ? $service : $result; |
| 928 | } |
| 929 | private function shareService(Definition $definition, $service, ?string $id, array &$inlineServices) |
| 930 | { |
| 931 | $inlineServices[$id ?? \spl_object_hash($definition)] = $service; |
| 932 | if (null !== $id && $definition->isShared()) { |
| 933 | if ($definition->isPrivate() && $this->isCompiled()) { |
| 934 | $this->privates[$id] = $service; |
| 935 | } else { |
| 936 | $this->services[$id] = $service; |
| 937 | } |
| 938 | unset($this->loading[$id]); |
| 939 | } |
| 940 | } |
| 941 | private function getExpressionLanguage() : ExpressionLanguage |
| 942 | { |
| 943 | if (null === $this->expressionLanguage) { |
| 944 | if (!\class_exists(\MailPoetVendor\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) { |
| 945 | throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); |
| 946 | } |
| 947 | $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders); |
| 948 | } |
| 949 | return $this->expressionLanguage; |
| 950 | } |
| 951 | private function inVendors(string $path) : bool |
| 952 | { |
| 953 | if (null === $this->vendors) { |
| 954 | $this->vendors = (new ComposerResource())->getVendors(); |
| 955 | } |
| 956 | $path = \realpath($path) ?: $path; |
| 957 | foreach ($this->vendors as $vendor) { |
| 958 | if (\str_starts_with($path, $vendor) && \false !== \strpbrk(\substr($path, \strlen($vendor), 1), '/' . \DIRECTORY_SEPARATOR)) { |
| 959 | $this->addResource(new FileResource($vendor . '/composer/installed.json')); |
| 960 | return \true; |
| 961 | } |
| 962 | } |
| 963 | return \false; |
| 964 | } |
| 965 | } |
| 966 |