本文整理汇总了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);
}
示例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());
}
示例3: init
public function init()
{
parent::init();
if ($this->userConfig !== null) {
$this->userConfig = Instance::ensure($this->userConfig, UserConfig::className());
}
}
示例4: init
/**
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
parent::init();
if (!empty($this->cache)) {
$this->cache = Instance::ensure($this->cache, Cache::className());
}
}
示例5: getCache
public function getCache()
{
if (!is_object($this->_cache)) {
$this->_cache = Instance::ensure($this->_cache, Cache::class);
}
return $this->_cache;
}
示例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;
}
示例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();
}
示例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;
}
}
示例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']);
}
示例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;
}
示例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;
}
示例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());
}
示例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', 'Недостаточно прав'));
}
}
}
}
示例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]);
}
示例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());
}
}