src/ServiceLocator.php
public function build($classNameOrSpecification, $serviceName = '')
    {
        /*
         * Builds uses static factory method
         */
        if (false !== strpos($classNameOrSpecification, '::')) {
            $specification = explode('::', $classNameOrSpecification);
            $className     = $specification[0];
            $factoryMethod = $specification[1];
            if (! class_exists($className, true)) {
                throw new RuntimeException(
                    sprintf(
                        'Factory "%s" not found.',
                        $className
                    )
                );
            }
            if (! is_callable([$className, $factoryMethod])) {
                throw new RuntimeException(
                    sprintf(
                        'Factory method "%s" of class "%s" is not callable.',
                        $factoryMethod,
                        $className
                    )
                );
            }
            if (count($specification) > 2) {
                /*
                 * The special case of factory specification.
                 * Abstract Factory takes the service name as an argument.
                 *
                 * Abstract factory method specification
                 * as 'FactoryClassName::methodName::'
                 */
                $instance = call_user_func(
                    [$className, $factoryMethod],
                    (string) $serviceName
                );
            } else {
                /*
                 * Calls the factory method.
                 *
                 * Factory method specification
                 * as 'FactoryClassName::methodName'
                 */
                $instance = call_user_func([$className, $factoryMethod]);
            }

        /*
         * Builds uses "new" operator
         */
        } else {
            $className = $classNameOrSpecification;
            if (! class_exists($className, true)) {
                throw new RuntimeException(
                    sprintf(
                        'Class "%s" not found.',
                        $className
                    )
                );
            }
            $instance = new $className();
        }

        return $instance;
    }
public function build($classNameOrSpecification, $serviceName = '')
    {
        /*
         * Builds uses static factory method
         */
        if (false !== strpos($classNameOrSpecification, '::')) {
            $specification = explode('::', $classNameOrSpecification);
            $className     = $specification[0];
            $factoryMethod = $specification[1];
            if (! class_exists($className, true)) {
                throw new RuntimeException(
                    sprintf(
                        'Factory "%s" not found.',
                        $className
                    )
                );
            }
            if (! is_callable([$className, $factoryMethod])) {
                throw new RuntimeException(
                    sprintf(
                        'Factory method "%s" of class "%s" is not callable.',
                        $factoryMethod,
                        $className
                    )
                );
            }
            if (count($specification) > 2) {
                /*
                 * The special case of factory specification.
                 * Abstract Factory takes the service name as an argument.
                 *
                 * Abstract factory method specification
                 * as 'FactoryClassName::methodName::'
                 */
                $instance = call_user_func(
                    [$className, $factoryMethod],
                    (string) $serviceName
                );
            } else {
                /*
                 * Calls the factory method.
                 *
                 * Factory method specification
                 * as 'FactoryClassName::methodName'
                 */
                $instance = call_user_func([$className, $factoryMethod]);
            }

        /*
         * Builds uses "new" operator
         */
        } else {
            $className = $classNameOrSpecification;
            if (! class_exists($className, true)) {
                throw new RuntimeException(
                    sprintf(
                        'Class "%s" not found.',
                        $className
                    )
                );
            }
            $instance = new $className();
        }

        return $instance;
    }
public function build ( $ classNameOrSpecification , $ serviceName = '' ) { /*
         * Builds uses static factory method
         */ if ( false !== strpos ( $ classNameOrSpecification , '::' ) ) { $ specification = explode ( '::' , $ classNameOrSpecification ) ; $ className = $ specification [ 0 ] ; $ factoryMethod = $ specification [ 1 ] ; if ( ! class_exists ( $ className , true ) ) { throw new RuntimeException ( sprintf ( 'Factory "%s" not found.' , $ className ) ) ; } if ( ! is_callable ( [ $ className , $ factoryMethod ] ) ) { throw new RuntimeException ( sprintf ( 'Factory method "%s" of class "%s" is not callable.' , $ factoryMethod , $ className ) ) ; } if ( count ( $ specification ) > 2 ) { /*
                 * The special case of factory specification.
                 * Abstract Factory takes the service name as an argument.
                 *
                 * Abstract factory method specification
                 * as 'FactoryClassName::methodName::'
                 */ $ instance = call_user_func ( [ $ className , $ factoryMethod ] , ( string ) $ serviceName ) ; } else { /*
                 * Calls the factory method.
                 *
                 * Factory method specification
                 * as 'FactoryClassName::methodName'
                 */ $ instance = call_user_func ( [ $ className , $ factoryMethod ] ) ; } /*
         * Builds uses "new" operator
         */ } else { $ className = $ classNameOrSpecification ; if ( ! class_exists ( $ className , true ) ) { throw new RuntimeException ( sprintf ( 'Class "%s" not found.' , $ className ) ) ; } $ instance = new $ className ( ) ; } return $ instance ; }
Builds an object.

@param string $classNameOrSpecification The class of service or the
service specification
@param string $serviceName              Optional; a abstract factory
takes the service name as an
argument

@throws \RuntimeException If unable build an object

@return object New object
Builds an object .