public function attach($name, $resolver = null, $single = false, $override = false)
    {
        if (is_array($name)) {
            $resolver  = current($name);
            $name  = key($name);
            $this->alias($resolver, $name, $override);
        }

        if ($name instanceof Asset) {
            $this->setParam('assets', $name->is(), $name, $override);
        } elseif ($resolver instanceof \Closure && $single) {
            $this->setParam('assets', $name, function($params) use ($resolver) {
                static $obj;

                if ($obj === null) {
                    $obj = $resolver($params, $this);
                }
                return $obj;
            }, $override);

        } elseif ($resolver instanceof \Closure || $resolver instanceof Asset) {
            $this->setParam('assets', $name, $resolver, $override);

        } elseif (is_object($resolver)) {
            $this->setParam('instances', $name, $resolver, $override);

        } elseif (($resolver === null) && $single) {
            $this->setParam('instances', $name, $name, $override);

        } elseif ($single) {
            $this->setParam('instances', $name, $resolver, $override);

        } elseif ($resolver === null) {
            $this->setParam('assets', $name, $name, $override);
        }

        // If we have a singleton, make sure it is only in
        // the *instances* array and not within *aliases*.
        if ($single && isset($this->aliases[$name])) {
            unset($this->aliases[$name]);
        }

        return $this;
    }
public function attach($name, $resolver = null, $single = false, $override = false)
    {
        if (is_array($name)) {
            $resolver  = current($name);
            $name  = key($name);
            $this->alias($resolver, $name, $override);
        }

        if ($name instanceof Asset) {
            $this->setParam('assets', $name->is(), $name, $override);
        } elseif ($resolver instanceof \Closure && $single) {
            $this->setParam('assets', $name, function($params) use ($resolver) {
                static $obj;

                if ($obj === null) {
                    $obj = $resolver($params, $this);
                }
                return $obj;
            }, $override);

        } elseif ($resolver instanceof \Closure || $resolver instanceof Asset) {
            $this->setParam('assets', $name, $resolver, $override);

        } elseif (is_object($resolver)) {
            $this->setParam('instances', $name, $resolver, $override);

        } elseif (($resolver === null) && $single) {
            $this->setParam('instances', $name, $name, $override);

        } elseif ($single) {
            $this->setParam('instances', $name, $resolver, $override);

        } elseif ($resolver === null) {
            $this->setParam('assets', $name, $name, $override);
        }

        // If we have a singleton, make sure it is only in
        // the *instances* array and not within *aliases*.
        if ($single && isset($this->aliases[$name])) {
            unset($this->aliases[$name]);
        }

        return $this;
    }
public function attach ( $ name , $ resolver = null , $ single = false , $ override = false ) { if ( is_array ( $ name ) ) { $ resolver = current ( $ name ) ; $ name = key ( $ name ) ; $ this -> alias ( $ resolver , $ name , $ override ) ; } if ( $ name instanceof Asset ) { $ this -> setParam ( 'assets' , $ name -> is ( ) , $ name , $ override ) ; } elseif ( $ resolver instanceof \ Closure && $ single ) { $ this -> setParam ( 'assets' , $ name , function ( $ params ) use ( $ resolver ) { static $ obj ; if ( $ obj === null ) { $ obj = $ resolver ( $ params , $ this ) ; } return $ obj ; } , $ override ) ; } elseif ( $ resolver instanceof \ Closure || $ resolver instanceof Asset ) { $ this -> setParam ( 'assets' , $ name , $ resolver , $ override ) ; } elseif ( is_object ( $ resolver ) ) { $ this -> setParam ( 'instances' , $ name , $ resolver , $ override ) ; } elseif ( ( $ resolver === null ) && $ single ) { $ this -> setParam ( 'instances' , $ name , $ name , $ override ) ; } elseif ( $ single ) { $ this -> setParam ( 'instances' , $ name , $ resolver , $ override ) ; } elseif ( $ resolver === null ) { $ this -> setParam ( 'assets' , $ name , $ name , $ override ) ; } // If we have a singleton, make sure it is only in // the *instances* array and not within *aliases*. if ( $ single && isset ( $ this -> aliases [ $ name ] ) ) { unset ( $ this -> aliases [ $ name ] ) ; } return $ this ; }
Attach an asset to the service manager if it doesn't already exist.

Assets can be provided by a *type* Asset object, a closure providing
the asst or an actual instance of an object.

Setting the bool $single to true will override any asset provided via a closure
to be wrapped within another closure which will cache the results. This makes
asset return the same instance on each call. (A singleton).

@param string|array $name The name to index the asset by. Also excepts an array so as to alias.
@param Proem\Service\Asset|closure|object $resolver Some means of resolving this asset.
@param bool $single
@param bool $override Optionally override existing (@see override).
Attach an asset to the service manager if it doesn t already exist .