public function resolve($name, $params = [])
    {
        // Allow hot resolving. eg; pass a closure to the resolve() method.
        if (isset($params['resolver']) && $params['resolver'] instanceof \Closure) {
            return $params['resolver']();
        }

        // Allow custom reflection resolutions.
        if (isset($params['reflector']) && $params['reflector'] instanceof \Closure) {
            $reflection = new \ReflectionClass($name);
            if ($reflection->isInstantiable()) {
                return $params['reflector']($reflection, $name);
            }
        }

        // Assets are simple.
        if (isset($this->assets[$name])) {
            if ($this->assets[$name] instanceof Asset || $this->assets[$name] instanceof \Closure) {
                return $this->assets[$name]($params, $this);
            }
        }

        // Singletons are more complex if they haven't been instantiated as yet.
        if (isset($this->instances[$name])) {
            // If we have a resolver (closure or asset) that hasn't been
            // instantiated into an actual instance of our asset yet, do so.
            if ($this->instances[$name] instanceof Asset || $this->instances[$name] instanceof \Closure) {
                $object = $this->instances[$name]($params, $this);
                $this->setParam('instances', $name, $object, true);

            // If we have an instance, return it.
            } else if (is_object($this->instances[$name])) {
                return $this->instances[$name];

            // Do what ever we can to resolve this asset.
            } else {
                try {
                    // Attempt to resolve by name.
                    $object = $this->autoResolve($name, $params);
                    $this->setParam('instances', $name, $object, true);
                    return $this->resolve($name);
                } catch (\LogicException $e) {
                    try {
                        $object = $this->autoResolve($this->instances[$name], $params);
                        $this->setParam('instances', $name, $object, true);
                        return $this->resolve($name);
                    } catch (\LogicException $e) {
                        throw $e;
                    }
                }
            }
        }

        // Recurse back through resolve().
        // This allows complex alias mappings.
        if (isset($this->aliases[$name])) {
            return $this->resolve($this->aliases[$name]);
        }

        // At this point, we still haven't resolved anything.
        // Try resolving by name alone.
        return $this->autoResolve($name, $params);
    }
public function resolve($name, $params = [])
    {
        // Allow hot resolving. eg; pass a closure to the resolve() method.
        if (isset($params['resolver']) && $params['resolver'] instanceof \Closure) {
            return $params['resolver']();
        }

        // Allow custom reflection resolutions.
        if (isset($params['reflector']) && $params['reflector'] instanceof \Closure) {
            $reflection = new \ReflectionClass($name);
            if ($reflection->isInstantiable()) {
                return $params['reflector']($reflection, $name);
            }
        }

        // Assets are simple.
        if (isset($this->assets[$name])) {
            if ($this->assets[$name] instanceof Asset || $this->assets[$name] instanceof \Closure) {
                return $this->assets[$name]($params, $this);
            }
        }

        // Singletons are more complex if they haven't been instantiated as yet.
        if (isset($this->instances[$name])) {
            // If we have a resolver (closure or asset) that hasn't been
            // instantiated into an actual instance of our asset yet, do so.
            if ($this->instances[$name] instanceof Asset || $this->instances[$name] instanceof \Closure) {
                $object = $this->instances[$name]($params, $this);
                $this->setParam('instances', $name, $object, true);

            // If we have an instance, return it.
            } else if (is_object($this->instances[$name])) {
                return $this->instances[$name];

            // Do what ever we can to resolve this asset.
            } else {
                try {
                    // Attempt to resolve by name.
                    $object = $this->autoResolve($name, $params);
                    $this->setParam('instances', $name, $object, true);
                    return $this->resolve($name);
                } catch (\LogicException $e) {
                    try {
                        $object = $this->autoResolve($this->instances[$name], $params);
                        $this->setParam('instances', $name, $object, true);
                        return $this->resolve($name);
                    } catch (\LogicException $e) {
                        throw $e;
                    }
                }
            }
        }

        // Recurse back through resolve().
        // This allows complex alias mappings.
        if (isset($this->aliases[$name])) {
            return $this->resolve($this->aliases[$name]);
        }

        // At this point, we still haven't resolved anything.
        // Try resolving by name alone.
        return $this->autoResolve($name, $params);
    }
public function resolve ( $ name , $ params = [ ] ) { // Allow hot resolving. eg; pass a closure to the resolve() method. if ( isset ( $ params [ 'resolver' ] ) && $ params [ 'resolver' ] instanceof \ Closure ) { return $ params [ 'resolver' ] ( ) ; } // Allow custom reflection resolutions. if ( isset ( $ params [ 'reflector' ] ) && $ params [ 'reflector' ] instanceof \ Closure ) { $ reflection = new \ ReflectionClass ( $ name ) ; if ( $ reflection -> isInstantiable ( ) ) { return $ params [ 'reflector' ] ( $ reflection , $ name ) ; } } // Assets are simple. if ( isset ( $ this -> assets [ $ name ] ) ) { if ( $ this -> assets [ $ name ] instanceof Asset || $ this -> assets [ $ name ] instanceof \ Closure ) { return $ this -> assets [ $ name ] ( $ params , $ this ) ; } } // Singletons are more complex if they haven't been instantiated as yet. if ( isset ( $ this -> instances [ $ name ] ) ) { // If we have a resolver (closure or asset) that hasn't been // instantiated into an actual instance of our asset yet, do so. if ( $ this -> instances [ $ name ] instanceof Asset || $ this -> instances [ $ name ] instanceof \ Closure ) { $ object = $ this -> instances [ $ name ] ( $ params , $ this ) ; $ this -> setParam ( 'instances' , $ name , $ object , true ) ; // If we have an instance, return it. } else if ( is_object ( $ this -> instances [ $ name ] ) ) { return $ this -> instances [ $ name ] ; // Do what ever we can to resolve this asset. } else { try { // Attempt to resolve by name. $ object = $ this -> autoResolve ( $ name , $ params ) ; $ this -> setParam ( 'instances' , $ name , $ object , true ) ; return $ this -> resolve ( $ name ) ; } catch ( \ LogicException $ e ) { try { $ object = $ this -> autoResolve ( $ this -> instances [ $ name ] , $ params ) ; $ this -> setParam ( 'instances' , $ name , $ object , true ) ; return $ this -> resolve ( $ name ) ; } catch ( \ LogicException $ e ) { throw $ e ; } } } } // Recurse back through resolve(). // This allows complex alias mappings. if ( isset ( $ this -> aliases [ $ name ] ) ) { return $ this -> resolve ( $ this -> aliases [ $ name ] ) ; } // At this point, we still haven't resolved anything. // Try resolving by name alone. return $ this -> autoResolve ( $ name , $ params ) ; }
Return an asset by index.

First, if we have a closure as a second argument, use it to resolve our asset (or at least return
whatever it returns).

Otherwise if we have an asset stored under  this index, return it. Failing that, check for
an instance at this index and return that. Failing that, resolve any aliases recursively.

If all of the above fails, we start the auto resolve process. This attempts to resolve to
instantiate the requested object and any dependencies that it may require to do so.

@param string $name
@param array $params Any extra paremeters to pass along to a closure|Asset|object
Return an asset by index .