protected function buildFromConfig($id, array $config)
    {
        if (empty($config['__class'])) {
            $config['__class'] = $id;
        }
        if (empty($config['__class'])) {
            throw new NotInstantiableException(var_export($config, true));
        }
        /* @var $reflection ReflectionClass */
        [$reflection, $dependencies] = $this->getDependencies($config['__class']);
        unset($config['__class']);

        if (isset($config['__construct()'])) {
            foreach (array_values($config['__construct()']) as $index => $param) {
                $dependencies[$index] = $param;
            }
            unset($config['__construct()']);
        }

        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        if (!$reflection->isInstantiable()) {
            throw new NotInstantiableException($reflection->name);
        }

        $object = $reflection->newInstanceArgs($dependencies);

        $config = $this->resolveDependencies($config);

        return static::configure($object, $config);
    }
protected function buildFromConfig($id, array $config)
    {
        if (empty($config['__class'])) {
            $config['__class'] = $id;
        }
        if (empty($config['__class'])) {
            throw new NotInstantiableException(var_export($config, true));
        }
        /* @var $reflection ReflectionClass */
        [$reflection, $dependencies] = $this->getDependencies($config['__class']);
        unset($config['__class']);

        if (isset($config['__construct()'])) {
            foreach (array_values($config['__construct()']) as $index => $param) {
                $dependencies[$index] = $param;
            }
            unset($config['__construct()']);
        }

        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        if (!$reflection->isInstantiable()) {
            throw new NotInstantiableException($reflection->name);
        }

        $object = $reflection->newInstanceArgs($dependencies);

        $config = $this->resolveDependencies($config);

        return static::configure($object, $config);
    }
protected function buildFromConfig ( $ id , array $ config ) { if ( empty ( $ config [ '__class' ] ) ) { $ config [ '__class' ] = $ id ; } if ( empty ( $ config [ '__class' ] ) ) { throw new NotInstantiableException ( var_export ( $ config , true ) ) ; } /* @var $reflection ReflectionClass */ [ $ reflection , $ dependencies ] = $ this -> getDependencies ( $ config [ '__class' ] ) ; unset ( $ config [ '__class' ] ) ; if ( isset ( $ config [ '__construct()' ] ) ) { foreach ( array_values ( $ config [ '__construct()' ] ) as $ index => $ param ) { $ dependencies [ $ index ] = $ param ; } unset ( $ config [ '__construct()' ] ) ; } $ dependencies = $ this -> resolveDependencies ( $ dependencies , $ reflection ) ; if ( ! $ reflection -> isInstantiable ( ) ) { throw new NotInstantiableException ( $ reflection -> name ) ; } $ object = $ reflection -> newInstanceArgs ( $ dependencies ) ; $ config = $ this -> resolveDependencies ( $ config ) ; return static :: configure ( $ object , $ config ) ; }
Creates an instance of the class definition with dependencies resolved
@param string $id the interface name or an alias name (e.g. `foo`) that was previously registered via [[set()]].
@param array $config
@return object the newly created instance of the specified class
@throws InvalidConfigException
@throws NotInstantiableException
Creates an instance of the class definition with dependencies resolved