comparison vendor/symfony/dependency-injection/Container.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
12 namespace Symfony\Component\DependencyInjection; 12 namespace Symfony\Component\DependencyInjection;
13 13
14 use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException; 14 use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
15 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; 15 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16 use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException; 16 use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
17 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
17 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; 18 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
18 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
19 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
20 use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; 19 use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
21 use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; 20 use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
21 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
22 22
23 /** 23 /**
24 * Container is a dependency injection container. 24 * Container is a dependency injection container.
25 * 25 *
26 * It gives access to object instances (services). 26 * It gives access to object instances (services).
38 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 38 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
39 */ 39 */
40 class Container implements ResettableContainerInterface 40 class Container implements ResettableContainerInterface
41 { 41 {
42 protected $parameterBag; 42 protected $parameterBag;
43 protected $services = array(); 43 protected $services = [];
44 protected $fileMap = array(); 44 protected $fileMap = [];
45 protected $methodMap = array(); 45 protected $methodMap = [];
46 protected $aliases = array(); 46 protected $aliases = [];
47 protected $loading = array(); 47 protected $loading = [];
48 protected $resolving = array(); 48 protected $resolving = [];
49 protected $syntheticIds = array(); 49 protected $syntheticIds = [];
50 50
51 /** 51 /**
52 * @internal 52 * @internal
53 */ 53 */
54 protected $privates = array(); 54 protected $privates = [];
55 55
56 /** 56 /**
57 * @internal 57 * @internal
58 */ 58 */
59 protected $normalizedIds = array(); 59 protected $normalizedIds = [];
60 60
61 private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_'); 61 private $underscoreMap = ['_' => '', '.' => '_', '\\' => '_'];
62 private $envCache = array(); 62 private $envCache = [];
63 private $compiled = false; 63 private $compiled = false;
64 private $getEnv; 64 private $getEnv;
65 65
66 public function __construct(ParameterBagInterface $parameterBag = null) 66 public function __construct(ParameterBagInterface $parameterBag = null)
67 { 67 {
292 if ('service_container' === $id) { 292 if ('service_container' === $id) {
293 return $this; 293 return $this;
294 } 294 }
295 295
296 if (isset($this->loading[$id])) { 296 if (isset($this->loading[$id])) {
297 throw new ServiceCircularReferenceException($id, array_keys($this->loading)); 297 throw new ServiceCircularReferenceException($id, array_merge(array_keys($this->loading), [$id]));
298 } 298 }
299 299
300 $this->loading[$id] = true; 300 $this->loading[$id] = true;
301 301
302 try { 302 try {
329 if (/* self::EXCEPTION_ON_INVALID_REFERENCE */ 1 === $invalidBehavior) { 329 if (/* self::EXCEPTION_ON_INVALID_REFERENCE */ 1 === $invalidBehavior) {
330 if (!$id) { 330 if (!$id) {
331 throw new ServiceNotFoundException($id); 331 throw new ServiceNotFoundException($id);
332 } 332 }
333 if (isset($this->syntheticIds[$id])) { 333 if (isset($this->syntheticIds[$id])) {
334 throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id)); 334 throw new ServiceNotFoundException($id, null, null, [], sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id));
335 } 335 }
336 if (isset($this->getRemovedIds()[$id])) { 336 if (isset($this->getRemovedIds()[$id])) {
337 throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id)); 337 throw new ServiceNotFoundException($id, null, null, [], sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id));
338 } 338 }
339 339
340 $alternatives = array(); 340 $alternatives = [];
341 foreach ($this->getServiceIds() as $knownId) { 341 foreach ($this->getServiceIds() as $knownId) {
342 $lev = levenshtein($id, $knownId); 342 $lev = levenshtein($id, $knownId);
343 if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) { 343 if ($lev <= \strlen($id) / 3 || false !== strpos($knownId, $id)) {
344 $alternatives[] = $knownId; 344 $alternatives[] = $knownId;
345 } 345 }
346 } 346 }
347 347
348 throw new ServiceNotFoundException($id, null, null, $alternatives); 348 throw new ServiceNotFoundException($id, null, null, $alternatives);
378 /** 378 /**
379 * {@inheritdoc} 379 * {@inheritdoc}
380 */ 380 */
381 public function reset() 381 public function reset()
382 { 382 {
383 $this->services = array(); 383 $this->services = [];
384 } 384 }
385 385
386 /** 386 /**
387 * Gets all service ids. 387 * Gets all service ids.
388 * 388 *
389 * @return array An array of all defined service ids 389 * @return array An array of all defined service ids
390 */ 390 */
391 public function getServiceIds() 391 public function getServiceIds()
392 { 392 {
393 $ids = array(); 393 $ids = [];
394 394
395 if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) { 395 if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) {
396 // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, 396 // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
397 // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) 397 // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
398 @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); 398 @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED);
413 * 413 *
414 * @return array 414 * @return array
415 */ 415 */
416 public function getRemovedIds() 416 public function getRemovedIds()
417 { 417 {
418 return array(); 418 return [];
419 } 419 }
420 420
421 /** 421 /**
422 * Camelizes a string. 422 * Camelizes a string.
423 * 423 *
425 * 425 *
426 * @return string The camelized string 426 * @return string The camelized string
427 */ 427 */
428 public static function camelize($id) 428 public static function camelize($id)
429 { 429 {
430 return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ ', '\\' => '_ '))), array(' ' => '')); 430 return strtr(ucwords(strtr($id, ['_' => ' ', '.' => '_ ', '\\' => '_ '])), [' ' => '']);
431 } 431 }
432 432
433 /** 433 /**
434 * A string to underscore. 434 * A string to underscore.
435 * 435 *
437 * 437 *
438 * @return string The underscored string 438 * @return string The underscored string
439 */ 439 */
440 public static function underscore($id) 440 public static function underscore($id)
441 { 441 {
442 return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id))); 442 return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], str_replace('_', '.', $id)));
443 } 443 }
444 444
445 /** 445 /**
446 * Creates a service by requiring its factory file. 446 * Creates a service by requiring its factory file.
447 * 447 *
468 } 468 }
469 if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) { 469 if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) {
470 return $this->envCache[$name]; 470 return $this->envCache[$name];
471 } 471 }
472 if (!$this->has($id = 'container.env_var_processors_locator')) { 472 if (!$this->has($id = 'container.env_var_processors_locator')) {
473 $this->set($id, new ServiceLocator(array())); 473 $this->set($id, new ServiceLocator([]));
474 } 474 }
475 if (!$this->getEnv) { 475 if (!$this->getEnv) {
476 $this->getEnv = new \ReflectionMethod($this, __FUNCTION__); 476 $this->getEnv = new \ReflectionMethod($this, __FUNCTION__);
477 $this->getEnv->setAccessible(true); 477 $this->getEnv->setAccessible(true);
478 $this->getEnv = $this->getEnv->getClosure($this); 478 $this->getEnv = $this->getEnv->getClosure($this);