public function init() { if (!defined('APPLICATION_PATH') || !file_exists(APPLICATION_PATH)) { throw new InvalidParamException("The param: 'APPLICATION_PATH' is invalid"); } $this->components = array_merge($this->defaultComponents(), $this->config('components')->all()); Container::getInstance()->setApp($this); }
function service($service) { return Container::getInstance()->getApp()->get($service); }
/** * Returns the actual object referenced by this Instance object. * @param ServiceLocator|Container $container the container used to locate the referenced object. * If null, the method will first try `Yii::$app` then `Yii::$container`. * @return object the actual object referenced by this Instance object. */ public function get($container = null) { if ($container) { return $container->get($this->id); } if (app() && app()->has($this->id)) { return app()->get($this->id); } else { return Container::getInstance()->get($this->id); } }
/** * Get a service by it's id. * * @param $id * @return mixed */ public function get($id) { return Container::getInstance()->get($id); }