protected function instantiate( $interface, $class, array $args ) {
		try {
			if ( is_callable( $class ) ) {
				$class = call_user_func_array( $class, $args );
			}

			if ( is_string( $class ) ) {
				if ( null !== $this->injector ) {
					$class = $this->injector->make( $class, $args );
				} else {
					$class = $this->instantiateClass( $class, $args );
				}
			}
		} catch ( Exception $exception ) {
			throw FailedToInstantiateObject::fromFactory(
				$class,
				$interface,
				$exception
			);
		}

		if ( ! is_subclass_of( $class, $interface ) ) {
			throw FailedToInstantiateObject::fromInvalidObject(
				$class,
				$interface
			);
		}

		return $class;
	}
protected function instantiate( $interface, $class, array $args ) {
		try {
			if ( is_callable( $class ) ) {
				$class = call_user_func_array( $class, $args );
			}

			if ( is_string( $class ) ) {
				if ( null !== $this->injector ) {
					$class = $this->injector->make( $class, $args );
				} else {
					$class = $this->instantiateClass( $class, $args );
				}
			}
		} catch ( Exception $exception ) {
			throw FailedToInstantiateObject::fromFactory(
				$class,
				$interface,
				$exception
			);
		}

		if ( ! is_subclass_of( $class, $interface ) ) {
			throw FailedToInstantiateObject::fromInvalidObject(
				$class,
				$interface
			);
		}

		return $class;
	}
protected function instantiate ( $ interface , $ class , array $ args ) { try { if ( is_callable ( $ class ) ) { $ class = call_user_func_array ( $ class , $ args ) ; } if ( is_string ( $ class ) ) { if ( null !== $ this -> injector ) { $ class = $ this -> injector -> make ( $ class , $ args ) ; } else { $ class = $ this -> instantiateClass ( $ class , $ args ) ; } } } catch ( Exception $ exception ) { throw FailedToInstantiateObject :: fromFactory ( $ class , $ interface , $ exception ) ; } if ( ! is_subclass_of ( $ class , $ interface ) ) { throw FailedToInstantiateObject :: fromInvalidObject ( $ class , $ interface ) ; } return $ class ; }
Instantiate a new object through either a class name or a factory method.

@since 0.3.0

@param string          $interface Interface the object needs to
implement.
@param callable|string $class     Fully qualified class name or factory
method.
@param array           $args      Arguments passed to the constructor or
factory method.

@return object Object that implements the interface.
@throws FailedToInstantiateObject If no valid object could be
instantiated.
Instantiate a new object through either a class name or a factory method .