public function build($id, array $config = [])
    {
        $id = $this->dereference($id);

        if (isset($this->building[$id])) {
            throw new CircularReferenceException(sprintf(
                'Circular reference to "%s" detected while building: %s; dereferencing: %s',
                $id,
                implode(',', array_keys($this->building)),
                implode(',', array_keys($this->dereferencing))
            ));
        }
        $this->building[$id] = 1;

        $this->registerProviderIfDeferredFor($id);

        $object = isset($this->definitions[$id])
            ? $this->buildWithDefinition($id, $config, $this->definitions[$id])
            : $this->buildWithoutDefinition($id, $config)
        ;

        unset($this->building[$id]);

        return $object;
    }
public function build($id, array $config = [])
    {
        $id = $this->dereference($id);

        if (isset($this->building[$id])) {
            throw new CircularReferenceException(sprintf(
                'Circular reference to "%s" detected while building: %s; dereferencing: %s',
                $id,
                implode(',', array_keys($this->building)),
                implode(',', array_keys($this->dereferencing))
            ));
        }
        $this->building[$id] = 1;

        $this->registerProviderIfDeferredFor($id);

        $object = isset($this->definitions[$id])
            ? $this->buildWithDefinition($id, $config, $this->definitions[$id])
            : $this->buildWithoutDefinition($id, $config)
        ;

        unset($this->building[$id]);

        return $object;
    }
public function build ( $ id , array $ config = [ ] ) { $ id = $ this -> dereference ( $ id ) ; if ( isset ( $ this -> building [ $ id ] ) ) { throw new CircularReferenceException ( sprintf ( 'Circular reference to "%s" detected while building: %s; dereferencing: %s' , $ id , implode ( ',' , array_keys ( $ this -> building ) ) , implode ( ',' , array_keys ( $ this -> dereferencing ) ) ) ) ; } $ this -> building [ $ id ] = 1 ; $ this -> registerProviderIfDeferredFor ( $ id ) ; $ object = isset ( $ this -> definitions [ $ id ] ) ? $ this -> buildWithDefinition ( $ id , $ config , $ this -> definitions [ $ id ] ) : $ this -> buildWithoutDefinition ( $ id , $ config ) ; unset ( $ this -> building [ $ id ] ) ; return $ object ; }
Creates new instance by either interface name or alias.

@param string $id the interface name or an alias name (e.g. `foo`) that was previously registered via [[set()]].
@param array $config
@return object new built instance of the specified class.
@throws CircularReferenceException
@throws InvalidConfigException
@throws NotFoundException if there is nothing registered with alias or interface specified
@throws NotInstantiableException
Creates new instance by either interface name or alias .