php yii-di-Instance类(方法)实例源码

下面列出了php yii-di-Instance 类(方法)源码代码实例,从而了解它的用法。

作者:lichunqian    项目:yii2-confi   
public function init()
 {
     $this->db = Instance::ensure($this->db, Connection::className());
     parent::init();
     // Note the default configuration data value will not store to database.
     $this->data = array_merge($this->loadData(), $this->data);
 }

作者:mongosof    项目:yii2-xmlpip   
/**
  * Initializes the action.
  * @throws InvalidConfigException if the xmlpipe document does not exist.
  */
 public function init()
 {
     if ($this->document === null) {
         throw new InvalidConfigException(get_class($this) . '::$document must be set.');
     }
     $this->document = Instance::ensure($this->document, BaseXmlPipe::className());
 }

作者:cdcche    项目:yii-plu   
public function init()
 {
     parent::init();
     if ($this->userConfig !== null) {
         $this->userConfig = Instance::ensure($this->userConfig, UserConfig::className());
     }
 }

作者:cdcche    项目:yii2-wecha   
/**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!empty($this->cache)) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }

作者:hiqde    项目:hipanel-cor   
public function getCache()
 {
     if (!is_object($this->_cache)) {
         $this->_cache = Instance::ensure($this->_cache, Cache::class);
     }
     return $this->_cache;
 }

作者:skamenetski    项目:yii2-car   
/**
  * @return object
  * @throws \yii\base\InvalidConfigException
  */
 protected static function getSession()
 {
     if (is_null(static::$session)) {
         static::$session = Instance::ensure(static::$session, Session::className());
     }
     return static::$session;
 }

作者:axiles8    项目:yii2-viewgri   
public function init()
 {
     parent::init();
     $db = Instance::ensure($this->db, Connection::className());
     $query = new Query();
     $this->ticket = $query->select(['*'])->from($this->table)->createCommand($db)->queryAll();
 }

作者:VampireM    项目:admin-9939-co   
public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     $this->cache->cachePath = Yii::getAlias($this->cachePath) . '/' . $action->getUniqueId();
     if (is_array($this->dependency)) {
         $this->dependency = Yii::createObject($this->dependency);
     }
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     $response = Yii::$app->getResponse();
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         return true;
     } else {
         $data = $this->cache->get($this->calculateCacheKey());
         if (is_array($data)) {
             $this->restoreResponse($response, $data);
         }
         $response->content = ob_get_clean();
         return false;
     }
 }

作者:manyoubaby12    项目:imsho   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->mailer = Instance::ensure($this->mailer, 'im\\users\\components\\UserMailerInterface');
     Event::on(User::className(), User::EVENT_BEFORE_REGISTRATION, [$this, 'beforeUserRegistration']);
     Event::on(User::className(), User::EVENT_AFTER_REGISTRATION, [$this, 'afterUserRegistration']);
 }

作者:thinkwil    项目:yii2-admi   
/**
  * Get user
  * @return User
  */
 public function getUser()
 {
     if (!$this->_user instanceof User) {
         $this->_user = Instance::ensure($this->_user, User::className());
     }
     return $this->_user;
 }

作者:kilyano    项目:yii   
/**
  * Initializes the migration.
  * This method will set [[db]] to be the 'db' application component, if it is `null`.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->db->getSchema()->refresh();
     $this->db->enableSlaves = false;
 }

作者:didwjdgk    项目:yii2-pur-gma   
public function init()
 {
     parent::init();
     $this->i2db = Instance::ensure($this->i2db, Connection::className());
     $this->infodb = Instance::ensure($this->infodb, Connection::className());
     $this->db46 = Instance::ensure($this->db46, Connection::className());
 }

作者:developeru    项目:yii2-db-rba   
public function interception($event)
 {
     if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
         Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
     }
     $route = Yii::$app->getRequest()->resolve();
     //Проверяем права по конфигу
     $this->createRule();
     $user = Instance::ensure(Yii::$app->user, User::className());
     $request = Yii::$app->getRequest();
     $action = $event->action;
     if (!$this->cheсkByRule($action, $user, $request)) {
         //И по AuthManager
         if (!$this->checkPermission($route)) {
             //Если задан $login_url и пользователь не авторизован
             if (Yii::$app->user->isGuest && $this->login_url) {
                 Yii::$app->response->redirect($this->login_url)->send();
                 exit;
             }
             //Если задан $redirect_url
             if ($this->redirect_url) {
                 Yii::$app->response->redirect($this->redirect_url)->send();
                 exit;
             } else {
                 throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
             }
         }
     }
 }

作者:letyi    项目:yii2-rbac-mongod   
/**
  * Initializes the application component.
  * This method overrides the parent implementation by establishing the database connection.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->db->getCollection($this->itemTable)->createIndex(['name' => 1], ['unique' => true]);
     $this->db->getCollection($this->ruleTable)->createIndex(['name' => 1], ['unique' => true]);
 }

作者:bruno-mel    项目:component   
/**
  * Initializes the DB connection component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     if (is_string($this->api)) {
         $this->api = Instance::ensure($this->api, Connection::className());
     }
 }

作者:tebazi    项目:yii2-db-seede   
public function __construct($db = 'db')
 {
     $this->db = Instance::ensure($db, Connection::className());
     $this->generator = new Generator();
     $this->dbHelper = new Migration(['db' => $this->db]);
     $this->generatorConfigurator = new GeneratorConfigurator();
 }

作者:yiisof    项目:yii2-httpclien   
/**
  * @return \yii\httpclient\Client
  */
 public function getHttpClient()
 {
     if (!is_object($this->_httpClient)) {
         $this->_httpClient = Instance::ensure($this->_httpClient, Client::className());
     }
     return $this->_httpClient;
 }

作者:trnt    项目:yii2-command-bu   
/**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     foreach ($this->locators as $k => $config) {
         $this->locators[$k] = Instance::ensure($config, 'trntv\\bus\\interfaces\\HandlerLocator');
     }
     parent::init();
 }

作者:wangpengzhe    项目:we   
/**
  * 初始化方法
  */
 public function init()
 {
     parent::init();
     //获取user实例
     $this->user = Instance::ensure($this->user, User::className());
     $this->user_info = $this->user->identity;
 }

作者:hughcub    项目:apppus   
public function init()
 {
     if (null !== $this->cache) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     parent::init();
 }


问题


面经


文章

微信
公众号

扫码关注公众号