public function build($id, array $arguments = null)
    {
        // Load a fresh instance of {id}
        #if (false === $instance = self::loadFromCacheById($id)) {

            // Check if all required dependencies are set [Doozr_Di_Factory, Doozr_Di_Map, ...]
            if (!$this->requirementsFulfilled()) {
                throw new Doozr_Di_Exception(
                    'Error building an instance. Requirements not fulfilled. Provide all required dependencies.'
                );
            }

            // Receive recipe for requested Id as well as name of class ...
            $recipe = $this->getMap()->getCollection()->getRecipeById($id);

            // Check for arguments override
            if (null === $arguments) {
                $arguments = (null !== $recipe['arguments']) ? $recipe['arguments'] : [];
            }

            // Check if className could be retrieved
            if (null === $recipe['className']) {
                throw new Doozr_Di_Exception(
                    sprintf(
                        'Please provide a configuration for the Id "%s". Or did you mean: "%s"?',
                        $id,
                        $this->getSimilar($id)
                    )
                );
            }

            // Build the requested instance ...
            $instance = $this->getFactory()->build(
                $recipe,
                $arguments
            );

            // Store in cache!
            #self::addInstanceToCache($id, $instance);
        #}

        // ... and return it
        return $instance;
    }
public function build($id, array $arguments = null)
    {
        // Load a fresh instance of {id}
        #if (false === $instance = self::loadFromCacheById($id)) {

            // Check if all required dependencies are set [Doozr_Di_Factory, Doozr_Di_Map, ...]
            if (!$this->requirementsFulfilled()) {
                throw new Doozr_Di_Exception(
                    'Error building an instance. Requirements not fulfilled. Provide all required dependencies.'
                );
            }

            // Receive recipe for requested Id as well as name of class ...
            $recipe = $this->getMap()->getCollection()->getRecipeById($id);

            // Check for arguments override
            if (null === $arguments) {
                $arguments = (null !== $recipe['arguments']) ? $recipe['arguments'] : [];
            }

            // Check if className could be retrieved
            if (null === $recipe['className']) {
                throw new Doozr_Di_Exception(
                    sprintf(
                        'Please provide a configuration for the Id "%s". Or did you mean: "%s"?',
                        $id,
                        $this->getSimilar($id)
                    )
                );
            }

            // Build the requested instance ...
            $instance = $this->getFactory()->build(
                $recipe,
                $arguments
            );

            // Store in cache!
            #self::addInstanceToCache($id, $instance);
        #}

        // ... and return it
        return $instance;
    }
public function build ( $ id , array $ arguments = null ) { // Load a fresh instance of {id} #if (false === $instance = self::loadFromCacheById($id)) { // Check if all required dependencies are set [Doozr_Di_Factory, Doozr_Di_Map, ...] if ( ! $ this -> requirementsFulfilled ( ) ) { throw new Doozr_Di_Exception ( 'Error building an instance. Requirements not fulfilled. Provide all required dependencies.' ) ; } // Receive recipe for requested Id as well as name of class ... $ recipe = $ this -> getMap ( ) -> getCollection ( ) -> getRecipeById ( $ id ) ; // Check for arguments override if ( null === $ arguments ) { $ arguments = ( null !== $ recipe [ 'arguments' ] ) ? $ recipe [ 'arguments' ] : [ ] ; } // Check if className could be retrieved if ( null === $ recipe [ 'className' ] ) { throw new Doozr_Di_Exception ( sprintf ( 'Please provide a configuration for the Id "%s". Or did you mean: "%s"?' , $ id , $ this -> getSimilar ( $ id ) ) ) ; } // Build the requested instance ... $ instance = $ this -> getFactory ( ) -> build ( $ recipe , $ arguments ) ; // Store in cache! #self::addInstanceToCache($id, $instance); #} // ... and return it return $ instance ; }
Builds an instance of requested Id with all dependencies from recipe in one single call.

@param string $id        Id of class to build
@param array  $arguments Arguments to pass to class (works only in dynamic mode)

@author Benjamin Carl <opensource@clickalicious.de>

@return object|mixed Instance of the given class

@throws Doozr_Di_Exception
Builds an instance of requested Id with all dependencies from recipe in one single call .