src/Vectorface/SnappyRouter/Di/Di.php
public function get($element, $useCache = true)
    {
        if ($useCache && isset($this->elements[$element])) {
            // return the cached version
            return $this->elements[$element];
        }

        if (isset($this->elementMap[$element])) {
            if (is_callable($this->elementMap[$element])) {
                // if we have callback, invoke it and cache the result
                $this->elements[$element] = call_user_func(
                    $this->elementMap[$element],
                    $this
                );
            } else {
                // otherwise simply cache the result and return it
                $this->elements[$element] = $this->elementMap[$element];
            }
            return $this->elements[$element];
        }

        throw new Exception('No element registered for key: '.$element);
    }
public function get($element, $useCache = true)
    {
        if ($useCache && isset($this->elements[$element])) {
            // return the cached version
            return $this->elements[$element];
        }

        if (isset($this->elementMap[$element])) {
            if (is_callable($this->elementMap[$element])) {
                // if we have callback, invoke it and cache the result
                $this->elements[$element] = call_user_func(
                    $this->elementMap[$element],
                    $this
                );
            } else {
                // otherwise simply cache the result and return it
                $this->elements[$element] = $this->elementMap[$element];
            }
            return $this->elements[$element];
        }

        throw new Exception('No element registered for key: '.$element);
    }
public function get ( $ element , $ useCache = true ) { if ( $ useCache && isset ( $ this -> elements [ $ element ] ) ) { // return the cached version return $ this -> elements [ $ element ] ; } if ( isset ( $ this -> elementMap [ $ element ] ) ) { if ( is_callable ( $ this -> elementMap [ $ element ] ) ) { // if we have callback, invoke it and cache the result $ this -> elements [ $ element ] = call_user_func ( $ this -> elementMap [ $ element ] , $ this ) ; } else { // otherwise simply cache the result and return it $ this -> elements [ $ element ] = $ this -> elementMap [ $ element ] ; } return $ this -> elements [ $ element ] ; } throw new Exception ( 'No element registered for key: ' . $ element ) ; }
Returns the element associated with the specified key.
@param string $element The key for the element.
@param boolean $useCache An optional flag for whether we can use the
cached version of the element (defaults to true).
@return Returns the associated element.
@throws \Exception Throws an exception if no element is registered for
the given key.
Returns the element associated with the specified key .