當前位置: 首頁>>代碼示例>>PHP>>正文


PHP di\Instance類代碼示例

本文整理匯總了PHP中yii\di\Instance的典型用法代碼示例。如果您正苦於以下問題:PHP Instance類的具體用法?PHP Instance怎麽用?PHP Instance使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Instance類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 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);
 }
開發者ID:lichunqiang,項目名稱:yii2-config,代碼行數:7,代碼來源:DbConfig.php

示例2: init

 /**
  * 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());
 }
開發者ID:mongosoft,項目名稱:yii2-xmlpipe,代碼行數:11,代碼來源:Action.php

示例3: init

 public function init()
 {
     parent::init();
     if ($this->userConfig !== null) {
         $this->userConfig = Instance::ensure($this->userConfig, UserConfig::className());
     }
 }
開發者ID:cdcchen,項目名稱:yii-plus,代碼行數:7,代碼來源:User.php

示例4: init

 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!empty($this->cache)) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
開發者ID:cdcchen,項目名稱:yii2-wechat,代碼行數:10,代碼來源:QyClient.php

示例5: getCache

 public function getCache()
 {
     if (!is_object($this->_cache)) {
         $this->_cache = Instance::ensure($this->_cache, Cache::class);
     }
     return $this->_cache;
 }
開發者ID:hiqdev,項目名稱:hipanel-core,代碼行數:7,代碼來源:Controller.php

示例6: getSession

 /**
  * @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;
 }
開發者ID:skamenetskiy,項目名稱:yii2-cart,代碼行數:11,代碼來源:Cart.php

示例7: init

 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();
 }
開發者ID:axiles89,項目名稱:yii2-viewgrid,代碼行數:7,代碼來源:Axiles89Grid.php

示例8: beforeAction

 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;
     }
 }
開發者ID:VampireMe,項目名稱:admin-9939-com,代碼行數:30,代碼來源:PageCacheFilter.php

示例9: init

 /**
  * @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']);
 }
開發者ID:manyoubaby123,項目名稱:imshop,代碼行數:10,代碼來源:UserEventsHandler.php

示例10: getUser

 /**
  * Get user
  * @return User
  */
 public function getUser()
 {
     if (!$this->_user instanceof User) {
         $this->_user = Instance::ensure($this->_user, User::className());
     }
     return $this->_user;
 }
開發者ID:thinkwill,項目名稱:yii2-admin,代碼行數:11,代碼來源:AccessControl.php

示例11: init

 /**
  * 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;
 }
開發者ID:kilyanov,項目名稱:yii2,代碼行數:11,代碼來源:Migration.php

示例12: init

 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());
 }
開發者ID:didwjdgks,項目名稱:yii2-pur-gman,代碼行數:7,代碼來源:Module.php

示例13: interception

 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', 'Недостаточно прав'));
             }
         }
     }
 }
開發者ID:developeruz,項目名稱:yii2-db-rbac,代碼行數:29,代碼來源:AccessBehavior.php

示例14: init

 /**
  * 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]);
 }
開發者ID:letyii,項目名稱:yii2-rbac-mongodb,代碼行數:11,代碼來源:MongodbManager.php

示例15: init

 /**
  * 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());
     }
 }
開發者ID:bruno-melo,項目名稱:components,代碼行數:12,代碼來源:DataProvider.php


注:本文中的yii\di\Instance類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。