src/Container.php
public function get(string $typeName, ?bool $nullable = false, ?string $target = null): ?object
    {
        if ($typeName === Settings::class) {
            return ($target === null) ? $this->settings : $this->settings->getConfig($target);
        }
        
        if (isset($this->shared[$typeName])) {
            return $this->shared[$typeName];
        }
        
        if (isset($this->underConstruction[$typeName])) {
            $cycle = \implode(' < ', \array_keys($this->underConstruction)) . ' < ' . $typeName;
            
            throw new ContainerException(\sprintf('Cyclic dependency detected: %s', $cycle));
        }
        
        $definition = $this->definitions[$typeName] ?? null;
        
        if ($definition === null || $definition->instantiator === null || $definition->instantiator == $typeName) {
            $object = $this->createObject($typeName, $nullable);
        } elseif ($definition->instantiator instanceof Instance) {
            return $this->shared[$typeName] = $definition->instantiator->object;
        } elseif ($definition->instantiator instanceof Factory) {
            $object = $this->createObjectUsingFactory($typeName, $definition->instantiator, $nullable);
        } else {
            if (!($object = $this->shared[$definition->instantiator] ?? null)) {
                $object = $this->get($definition->instantiator, $nullable, $target);
            }
            
            if ($object === null) {
                return null;
            }
            
            if (!$object instanceof $typeName) {
                throw new ContainerException(\sprintf('%s is not an instance of %s', $definition->instantiator, $typeName));
            }
            
            return $object;
        }
        
        if ($object === null) {
            return null;
        }
        
        $object = $this->applyInitializers($object);
        $def = $this->definitions[\get_class($object)] ?? null;
        
        if ($def !== null && $def->decorators) {
            foreach ($def->decorators as $decorator) {
                $decorated = $decorator($object, $typeName, $this, $target);
                
                if ($decorated !== $object) {
                    $object = $this->applyInitializers($decorated);
                } else {
                    $object = $decorated;
                }
            }
        }
        
        if ($definition !== null && $definition->decorators) {
            foreach ($definition->decorators as $decorator) {
                $decorated = $decorator($object, $typeName, $this, $target);
                
                if ($decorated !== $object) {
                    $object = $this->applyInitializers($decorated);
                } else {
                    $object = $decorated;
                }
            }
        }
        
        if ($definition->shared ?? true) {
            $this->shared[$typeName] = $object;
        }
        
        return $object;
    }
public function get(string $typeName, ?bool $nullable = false, ?string $target = null): ?object
    {
        if ($typeName === Settings::class) {
            return ($target === null) ? $this->settings : $this->settings->getConfig($target);
        }
        
        if (isset($this->shared[$typeName])) {
            return $this->shared[$typeName];
        }
        
        if (isset($this->underConstruction[$typeName])) {
            $cycle = \implode(' < ', \array_keys($this->underConstruction)) . ' < ' . $typeName;
            
            throw new ContainerException(\sprintf('Cyclic dependency detected: %s', $cycle));
        }
        
        $definition = $this->definitions[$typeName] ?? null;
        
        if ($definition === null || $definition->instantiator === null || $definition->instantiator == $typeName) {
            $object = $this->createObject($typeName, $nullable);
        } elseif ($definition->instantiator instanceof Instance) {
            return $this->shared[$typeName] = $definition->instantiator->object;
        } elseif ($definition->instantiator instanceof Factory) {
            $object = $this->createObjectUsingFactory($typeName, $definition->instantiator, $nullable);
        } else {
            if (!($object = $this->shared[$definition->instantiator] ?? null)) {
                $object = $this->get($definition->instantiator, $nullable, $target);
            }
            
            if ($object === null) {
                return null;
            }
            
            if (!$object instanceof $typeName) {
                throw new ContainerException(\sprintf('%s is not an instance of %s', $definition->instantiator, $typeName));
            }
            
            return $object;
        }
        
        if ($object === null) {
            return null;
        }
        
        $object = $this->applyInitializers($object);
        $def = $this->definitions[\get_class($object)] ?? null;
        
        if ($def !== null && $def->decorators) {
            foreach ($def->decorators as $decorator) {
                $decorated = $decorator($object, $typeName, $this, $target);
                
                if ($decorated !== $object) {
                    $object = $this->applyInitializers($decorated);
                } else {
                    $object = $decorated;
                }
            }
        }
        
        if ($definition !== null && $definition->decorators) {
            foreach ($definition->decorators as $decorator) {
                $decorated = $decorator($object, $typeName, $this, $target);
                
                if ($decorated !== $object) {
                    $object = $this->applyInitializers($decorated);
                } else {
                    $object = $decorated;
                }
            }
        }
        
        if ($definition->shared ?? true) {
            $this->shared[$typeName] = $object;
        }
        
        return $object;
    }
Grab an object instance of the given type from the DI container.

@param string $typeName Fully-qualified name of the bound type.
@param bool $nullable Allow null in case of missing dependency.
@param string $target The target type that receives the created object.
@return object An instance of the requested type.