public function register($name, $closure)
    {
        if (isset($this->services[$name])) {
            throw new DuplicateServiceException('A service is already registered under '. $name);
        }

        $this->services[$name] = function () use ($closure) {
            static $instance;
            if (null === $instance) {
                $instance = $closure();
            }

            return $instance;
        };
    }
public function register($name, $closure)
    {
        if (isset($this->services[$name])) {
            throw new DuplicateServiceException('A service is already registered under '. $name);
        }

        $this->services[$name] = function () use ($closure) {
            static $instance;
            if (null === $instance) {
                $instance = $closure();
            }

            return $instance;
        };
    }
public function register ( $ name , $ closure ) { if ( isset ( $ this -> services [ $ name ] ) ) { throw new DuplicateServiceException ( 'A service is already registered under ' . $ name ) ; } $ this -> services [ $ name ] = function ( ) use ( $ closure ) { static $ instance ; if ( null === $ instance ) { $ instance = $ closure ( ) ; } return $ instance ; } ; }
Register a lazy service

@param string $name                  The name of the service
@param callable $closure             The callable function to execute when requesting our service
@throws DuplicateServiceException    If an attempt is made to register two services with the same name
@return mixed
Register a lazy service