当前位置: 首页>>代码示例>>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;未经允许,请勿转载。