Go\Core\Container::get PHP Method

get() public method

Return a service or value from the container
public get ( string $id ) : mixed
$id string Identifier
return mixed
    public function get($id)
    {
        if (!isset($this->values[$id])) {
            throw new \OutOfBoundsException("Value {$id} is not defined in the container");
        }
        if (is_callable($this->values[$id])) {
            return $this->values[$id]($this);
        } else {
            return $this->values[$id];
        }
    }

Usage Example

 /**
  * Magic accessor
  *
  * @param string $name Key name
  *
  * @throws \InvalidArgumentException if referenced value is not an advisor
  * @return Advice
  */
 public function __get($name)
 {
     if ($this->container->has($name)) {
         $advisor = $this->container->get($name);
     } else {
         list(, $advisorName) = explode('.', $name);
         list($aspect) = explode('->', $advisorName);
         $aspectInstance = $this->container->getAspect($aspect);
         $this->loader->loadAndRegister($aspectInstance);
         $advisor = $this->container->get($name);
     }
     if (!$advisor instanceof Advisor) {
         throw new \InvalidArgumentException("Reference {$name} is not an advisor");
     }
     $this->{$name} = $advisor->getAdvice();
     return $this->{$name};
 }