src/Milky/Binding/UniversalBuilder.php
public static function buildClass( $class, array $parameters = [] )
	{
		if ( !is_string( $class ) )
			throw new BindingException( "Class must be a string" );

		if ( static::building( $class ) )
			throw new BindingException( "The class [" . $class . "] is already being built." );

		static::$buildStack[] = $class;

		try
		{
			$reflector = new \ReflectionClass( $class );

			// If the type is not instantiable, the developer is attempting to resolve
			// an abstract type such as an Interface of Abstract Class and there is
			// no binding registered for the abstractions so we need to bail out.
			if ( !$reflector->isInstantiable() )
				throw new BindingException( "Target [$class] is not instantiable." );

			$constructor = $reflector->getConstructor();

			// If there are no constructors, that means there are no dependencies then
			// we can just resolve the instances of the objects right away.
			if ( is_null( $constructor ) )
				return new $class;

			$dependencies = $constructor->getParameters();

			// Once we have all the constructor's parameters we can create each of the
			// dependency instances and then use the reflection instances to make a
			// new instance of this class, injecting the created dependencies in.
			$parameters = static::keyParametersByArgument( $dependencies, $parameters );

			$instances = static::getDependencies( $dependencies, $parameters, $class );

			array_pop( static::$buildStack );

			/**/

			return $reflector->newInstanceArgs( $instances );
		}
		catch ( \ReflectionException $e )
		{
			array_pop( static::$buildStack );

			throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
		}
	}
public static function buildClass( $class, array $parameters = [] )
	{
		if ( !is_string( $class ) )
			throw new BindingException( "Class must be a string" );

		if ( static::building( $class ) )
			throw new BindingException( "The class [" . $class . "] is already being built." );

		static::$buildStack[] = $class;

		try
		{
			$reflector = new \ReflectionClass( $class );

			// If the type is not instantiable, the developer is attempting to resolve
			// an abstract type such as an Interface of Abstract Class and there is
			// no binding registered for the abstractions so we need to bail out.
			if ( !$reflector->isInstantiable() )
				throw new BindingException( "Target [$class] is not instantiable." );

			$constructor = $reflector->getConstructor();

			// If there are no constructors, that means there are no dependencies then
			// we can just resolve the instances of the objects right away.
			if ( is_null( $constructor ) )
				return new $class;

			$dependencies = $constructor->getParameters();

			// Once we have all the constructor's parameters we can create each of the
			// dependency instances and then use the reflection instances to make a
			// new instance of this class, injecting the created dependencies in.
			$parameters = static::keyParametersByArgument( $dependencies, $parameters );

			$instances = static::getDependencies( $dependencies, $parameters, $class );

			array_pop( static::$buildStack );

			/**/

			return $reflector->newInstanceArgs( $instances );
		}
		catch ( \ReflectionException $e )
		{
			array_pop( static::$buildStack );

			throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
		}
	}
public static function buildClass ( $ class , array $ parameters = [ ] ) { if ( ! is_string ( $ class ) ) throw new BindingException ( "Class must be a string" ) ; if ( static :: building ( $ class ) ) throw new BindingException ( "The class [" . $ class . "] is already being built." ) ; static :: $ buildStack [ ] = $ class ; try { $ reflector = new \ ReflectionClass ( $ class ) ; // If the type is not instantiable, the developer is attempting to resolve // an abstract type such as an Interface of Abstract Class and there is // no binding registered for the abstractions so we need to bail out. if ( ! $ reflector -> isInstantiable ( ) ) throw new BindingException ( "Target [$class] is not instantiable." ) ; $ constructor = $ reflector -> getConstructor ( ) ; // If there are no constructors, that means there are no dependencies then // we can just resolve the instances of the objects right away. if ( is_null ( $ constructor ) ) return new $ class ; $ dependencies = $ constructor -> getParameters ( ) ; // Once we have all the constructor's parameters we can create each of the // dependency instances and then use the reflection instances to make a // new instance of this class, injecting the created dependencies in. $ parameters = static :: keyParametersByArgument ( $ dependencies , $ parameters ) ; $ instances = static :: getDependencies ( $ dependencies , $ parameters , $ class ) ; array_pop ( static :: $ buildStack ) ; /**/ return $ reflector -> newInstanceArgs ( $ instances ) ; } catch ( \ ReflectionException $ e ) { array_pop ( static :: $ buildStack ) ; throw new BindingException ( "Failed to build [$class]: " . $ e -> getMessage ( ) . " in " . $ e -> getFile ( ) . " on line " . $ e -> getLine ( ) ) ; } }
Attempts to construct a class

@param string $class
@param array $parameters

@return object
@throws BindingException
Attempts to construct a class