[DI] Top micro benchmarks
This commit is contained in:
parent
4ef0b3e180
commit
3edf5f1528
@ -217,21 +217,18 @@ class Container implements ResettableContainerInterface
|
||||
*/
|
||||
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
|
||||
{
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
// Re-use shared service instance if it exists.
|
||||
if (isset($this->services[$id])) {
|
||||
return $this->services[$id];
|
||||
}
|
||||
if ('service_container' === $id) {
|
||||
return $this;
|
||||
}
|
||||
if (isset($this->factories[$id])) {
|
||||
return $this->factories[$id]();
|
||||
return $this->services[$id]
|
||||
?? $this->services[$id = $this->aliases[$id] ?? $id]
|
||||
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? array($this, 'make'))($id, $invalidBehavior));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a service.
|
||||
*
|
||||
* As a separate method to allow "get()" to use the really fast `??` operator.
|
||||
*/
|
||||
private function make(string $id, int $invalidBehavior)
|
||||
{
|
||||
if (isset($this->loading[$id])) {
|
||||
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
|
||||
}
|
||||
|
Reference in New Issue
Block a user