src/Container.php
protected function createObjectUsingFactory(string $typeName, Factory $factory, ?bool $nullable = false): ?object
    {
        $this->underConstruction[$typeName] = true;
        
        try {
            // Assemble arguments and scope config objects to the bound type:
            $object = ($factory->callback)(...$this->populateArguments($factory->getReflection(), null, $typeName));
            
            if (!$object instanceof $typeName) {
                if ($object === null && $nullable) {
                    return null;
                }
                
                $type = \is_object($object) ? \get_class($object) : \gettype($object);
                
                throw new ContainerException(\sprintf('Factory must return an instance of %s, returned value is %s', $typeName, $type));
            }
        } finally {
            unset($this->underConstruction[$typeName]);
        }
        
        return $object;
    }
protected function createObjectUsingFactory(string $typeName, Factory $factory, ?bool $nullable = false): ?object
    {
        $this->underConstruction[$typeName] = true;
        
        try {
            // Assemble arguments and scope config objects to the bound type:
            $object = ($factory->callback)(...$this->populateArguments($factory->getReflection(), null, $typeName));
            
            if (!$object instanceof $typeName) {
                if ($object === null && $nullable) {
                    return null;
                }
                
                $type = \is_object($object) ? \get_class($object) : \gettype($object);
                
                throw new ContainerException(\sprintf('Factory must return an instance of %s, returned value is %s', $typeName, $type));
            }
        } finally {
            unset($this->underConstruction[$typeName]);
        }
        
        return $object;
    }
Create a new object instance using a pre-configured factory callback.

@param string $typeName Fully-qualified name of the bound type.
@param array $factory Definition of the factory (callable and reflection).
@param string $nullable Allow returning null in case of a missing dependency?
@return object