src/Container/Builder.php
public static function create(ContainerInterface $container, string $class, array $map = [], array $params = null)
    {
        if (!\class_exists($class)) {
            throw new \InvalidArgumentException("unable to create component: {$class} (autoloading failed)");
        }

        if (\method_exists($class, 'getInstance')) {
            return $class::getInstance();
        }

        if ($params === null) {
            $reflection = new \ReflectionClass($class);

            if (!$reflection->isInstantiable()) {
                throw new \InvalidArgumentException("unable to create instance of abstract class: {$class}");
            }

            $constructor = $reflection->getConstructor();

            if ($constructor && ($params = $constructor->getParameters()) !== []) {
                $params = static::resolve($container, $params, $map, false);
            } else {
                $params = [];
            }

            return $reflection->newInstanceArgs($params);
        }

        if ($params !== []) {
            $params = static::resolve($container, $params, $map, false);
        }

        return new $class(...$params);
    }
public static function create(ContainerInterface $container, string $class, array $map = [], array $params = null)
    {
        if (!\class_exists($class)) {
            throw new \InvalidArgumentException("unable to create component: {$class} (autoloading failed)");
        }

        if (\method_exists($class, 'getInstance')) {
            return $class::getInstance();
        }

        if ($params === null) {
            $reflection = new \ReflectionClass($class);

            if (!$reflection->isInstantiable()) {
                throw new \InvalidArgumentException("unable to create instance of abstract class: {$class}");
            }

            $constructor = $reflection->getConstructor();

            if ($constructor && ($params = $constructor->getParameters()) !== []) {
                $params = static::resolve($container, $params, $map, false);
            } else {
                $params = [];
            }

            return $reflection->newInstanceArgs($params);
        }

        if ($params !== []) {
            $params = static::resolve($container, $params, $map, false);
        }

        return new $class(...$params);
    }
public static function create ( ContainerInterface $ container , string $ class , array $ map = [ ] , array $ params = null ) { if ( ! \ class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( "unable to create component: {$class} (autoloading failed)" ) ; } if ( \ method_exists ( $ class , 'getInstance' ) ) { return $ class :: getInstance ( ) ; } if ( $ params === null ) { $ reflection = new \ ReflectionClass ( $ class ) ; if ( ! $ reflection -> isInstantiable ( ) ) { throw new \ InvalidArgumentException ( "unable to create instance of abstract class: {$class}" ) ; } $ constructor = $ reflection -> getConstructor ( ) ; if ( $ constructor && ( $ params = $ constructor -> getParameters ( ) ) !== [ ] ) { $ params = static :: resolve ( $ container , $ params , $ map , false ) ; } else { $ params = [ ] ; } return $ reflection -> newInstanceArgs ( $ params ) ; } if ( $ params !== [ ] ) { $ params = static :: resolve ( $ container , $ params , $ map , false ) ; } return new $ class ( ... $ params ) ; }
Create an instance of a given class.

@noinspection PhpDocMissingThrowsInspection

@param ContainerInterface                  $container
@param string                              $class fully-qualified class-name
@param mixed[]                             $map   mixed list/map of parameter values (and/or boxed values)
@param \ReflectionParameter[]|array[]|null $params

@return mixed

@throws \InvalidArgumentException
Create an instance of a given class .