final public function create($type, array $args = null, callable $cb = null)
    {
        if (!is_string($type)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s: Type must be a string.',
                    get_called_class()
                )
            );
        }

        if (!isset($args)) {
            $args = $this->arguments();
        }

        $pool = get_called_class();
        if (isset($this->resolved[$pool][$type])) {
            $className = $this->resolved[$pool][$type];
        } else {
            if ($this->isResolvable($type) === false) {
                $defaultClass = $this->defaultClass();
                if ($defaultClass !== '') {
                    $obj = $this->createClass($defaultClass, $args);
                    $this->runCallbacks($obj, $cb);
                    return $obj;
                } else {
                    throw new InvalidArgumentException(
                        sprintf(
                            '%1$s: Type "%2$s" is not a valid type. (Using default class "%3$s")',
                            get_called_class(),
                            $type,
                            $defaultClass
                        )
                    );
                }
            }

            // Create the object from the type's class name.
            $className = $this->resolve($type);
            $this->resolved[$pool][$type] = $className;
        }

        $obj = $this->createClass($className, $args);

        // Ensure base class is respected, if set.
        $baseClass = $this->baseClass();
        if ($baseClass !== '' && !($obj instanceof $baseClass)) {
            throw new Exception(
                sprintf(
                    '%1$s: Class "%2$s" must be an instance of "%3$s"',
                    get_called_class(),
                    $className,
                    $baseClass
                )
            );
        }

        $this->runCallbacks($obj, $cb);

        return $obj;
    }
final public function create($type, array $args = null, callable $cb = null)
    {
        if (!is_string($type)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s: Type must be a string.',
                    get_called_class()
                )
            );
        }

        if (!isset($args)) {
            $args = $this->arguments();
        }

        $pool = get_called_class();
        if (isset($this->resolved[$pool][$type])) {
            $className = $this->resolved[$pool][$type];
        } else {
            if ($this->isResolvable($type) === false) {
                $defaultClass = $this->defaultClass();
                if ($defaultClass !== '') {
                    $obj = $this->createClass($defaultClass, $args);
                    $this->runCallbacks($obj, $cb);
                    return $obj;
                } else {
                    throw new InvalidArgumentException(
                        sprintf(
                            '%1$s: Type "%2$s" is not a valid type. (Using default class "%3$s")',
                            get_called_class(),
                            $type,
                            $defaultClass
                        )
                    );
                }
            }

            // Create the object from the type's class name.
            $className = $this->resolve($type);
            $this->resolved[$pool][$type] = $className;
        }

        $obj = $this->createClass($className, $args);

        // Ensure base class is respected, if set.
        $baseClass = $this->baseClass();
        if ($baseClass !== '' && !($obj instanceof $baseClass)) {
            throw new Exception(
                sprintf(
                    '%1$s: Class "%2$s" must be an instance of "%3$s"',
                    get_called_class(),
                    $className,
                    $baseClass
                )
            );
        }

        $this->runCallbacks($obj, $cb);

        return $obj;
    }
final public function create ( $ type , array $ args = null , callable $ cb = null ) { if ( ! is_string ( $ type ) ) { throw new InvalidArgumentException ( sprintf ( '%s: Type must be a string.' , get_called_class ( ) ) ) ; } if ( ! isset ( $ args ) ) { $ args = $ this -> arguments ( ) ; } $ pool = get_called_class ( ) ; if ( isset ( $ this -> resolved [ $ pool ] [ $ type ] ) ) { $ className = $ this -> resolved [ $ pool ] [ $ type ] ; } else { if ( $ this -> isResolvable ( $ type ) === false ) { $ defaultClass = $ this -> defaultClass ( ) ; if ( $ defaultClass !== '' ) { $ obj = $ this -> createClass ( $ defaultClass , $ args ) ; $ this -> runCallbacks ( $ obj , $ cb ) ; return $ obj ; } else { throw new InvalidArgumentException ( sprintf ( '%1$s: Type "%2$s" is not a valid type. (Using default class "%3$s")' , get_called_class ( ) , $ type , $ defaultClass ) ) ; } } // Create the object from the type's class name. $ className = $ this -> resolve ( $ type ) ; $ this -> resolved [ $ pool ] [ $ type ] = $ className ; } $ obj = $ this -> createClass ( $ className , $ args ) ; // Ensure base class is respected, if set. $ baseClass = $ this -> baseClass ( ) ; if ( $ baseClass !== '' && ! ( $ obj instanceof $ baseClass ) ) { throw new Exception ( sprintf ( '%1$s: Class "%2$s" must be an instance of "%3$s"' , get_called_class ( ) , $ className , $ baseClass ) ) ; } $ this -> runCallbacks ( $ obj , $ cb ) ; return $ obj ; }
Create a new instance of a class, by type.

Unlike `get()`, this method *always* return a new instance of the requested class.

## Object callback
It is possible to pass a callback method that will be executed upon object instanciation.
The callable should have a signature: `function($obj);` where $obj is the newly created object.

@param  string   $type The type (class ident).
@param  array    $args Optional. Constructor arguments
(will override the arguments set on the class from constructor).
@param  callable $cb   Optional. Object callback, called at creation.
Will run in addition to the default callback, if any.
@throws Exception If the base class is set and  the resulting instance is not of the base class.
@throws InvalidArgumentException If type argument is not a string or is not an available type.
@return mixed The instance / object
Create a new instance of a class by type .