yii\di\Container::build PHP Метод

build() защищенный Метод

This method will resolve dependencies of the specified class, instantiate them, and inject them into the new instance of the specified class.
protected build ( string $class, array $params, array $config ) : object
$class string the class name
$params array constructor parameters
$config array configurations to be applied to the new instance
Результат object the newly created instance of the specified class
    protected function build($class, $params, $config)
    {
        /* @var $reflection ReflectionClass */
        list($reflection, $dependencies) = $this->getDependencies($class);
        foreach ($params as $index => $param) {
            $dependencies[$index] = $param;
        }
        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        if (!$reflection->isInstantiable()) {
            throw new NotInstantiableException($reflection->name);
        }
        if (empty($config)) {
            return $reflection->newInstanceArgs($dependencies);
        }
        if (!empty($dependencies) && $reflection->implementsInterface('yii\\base\\Configurable')) {
            // set $config as the last parameter (existing one will be overwritten)
            $dependencies[count($dependencies) - 1] = $config;
            return $reflection->newInstanceArgs($dependencies);
        } else {
            $object = $reflection->newInstanceArgs($dependencies);
            foreach ($config as $name => $value) {
                $object->{$name} = $value;
            }
            return $object;
        }
    }