From 88a4f4ae9ff3649c68e18e205277ac99f1f73089 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 1 May 2016 03:09:38 +0200 Subject: [PATCH] Use ::class instead of ::className() - shorter syntax - native PHP feature, so it does not depend on yii\base\Object - Does not trigger autoloading anymore --- framework/base/Event.php | 2 +- framework/base/Object.php | 2 ++ framework/behaviors/AttributeBehavior.php | 2 +- framework/behaviors/BlameableBehavior.php | 4 ++-- framework/behaviors/SluggableBehavior.php | 6 +++--- framework/behaviors/TimestampBehavior.php | 4 ++-- framework/caching/DbCache.php | 2 +- framework/caching/DbDependency.php | 2 +- framework/captcha/Captcha.php | 2 +- framework/console/controllers/CacheController.php | 2 +- framework/console/controllers/MigrateController.php | 2 +- framework/data/ActiveDataProvider.php | 2 +- framework/data/BaseDataProvider.php | 4 ++-- framework/data/SqlDataProvider.php | 2 +- framework/db/ActiveQuery.php | 4 ++-- framework/db/ActiveRecord.php | 2 +- framework/db/ActiveRelationTrait.php | 6 +++--- framework/db/BaseActiveRecord.php | 4 ++-- framework/db/Migration.php | 2 +- framework/db/Query.php | 4 ++-- framework/di/Instance.php | 4 ++-- framework/filters/AccessControl.php | 4 ++-- framework/filters/Cors.php | 4 ++-- framework/filters/PageCache.php | 2 +- framework/filters/RateLimiter.php | 2 +- framework/filters/VerbFilter.php | 2 +- framework/filters/auth/CompositeAuth.php | 6 +++--- framework/filters/auth/HttpBasicAuth.php | 2 +- framework/filters/auth/HttpBearerAuth.php | 2 +- framework/grid/ActionColumn.php | 2 +- framework/grid/GridView.php | 10 +++++----- framework/i18n/DbMessageSource.php | 4 ++-- framework/log/DbTarget.php | 2 +- framework/mail/BaseMailer.php | 2 +- framework/mutex/DbMutex.php | 2 +- framework/rbac/DbManager.php | 6 +++--- framework/rbac/PhpManager.php | 2 +- framework/rest/Controller.php | 8 ++++---- framework/test/DbFixture.php | 2 +- framework/test/FixtureTrait.php | 6 +++--- framework/validators/UniqueValidator.php | 2 +- framework/web/AssetManager.php | 4 ++-- framework/web/CacheSession.php | 2 +- framework/web/DbSession.php | 2 +- framework/widgets/ActiveField.php | 2 +- framework/widgets/BaseListView.php | 4 ++-- framework/widgets/FragmentCache.php | 2 +- framework/widgets/MaskedInput.php | 2 +- 48 files changed, 78 insertions(+), 76 deletions(-) diff --git a/framework/base/Event.php b/framework/base/Event.php index a57e027..c4ce573 100644 --- a/framework/base/Event.php +++ b/framework/base/Event.php @@ -64,7 +64,7 @@ class Event extends Object * `afterInsert` event: * * ```php - * Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function ($event) { + * Event::on(ActiveRecord::class, ActiveRecord::EVENT_AFTER_INSERT, function ($event) { * Yii::trace(get_class($event->sender) . ' is inserted.'); * }); * ``` diff --git a/framework/base/Object.php b/framework/base/Object.php index 220ab3e..4484b4a 100644 --- a/framework/base/Object.php +++ b/framework/base/Object.php @@ -79,6 +79,8 @@ class Object implements Configurable /** * Returns the fully qualified name of this class. * @return string the fully qualified name of this class. + * @deprecated since version 2.1. PHPs `::class` syntax should be used instead. + * For object instances, use `get_class()`. */ public static function className() { diff --git a/framework/behaviors/AttributeBehavior.php b/framework/behaviors/AttributeBehavior.php index f24d306..025af2d 100644 --- a/framework/behaviors/AttributeBehavior.php +++ b/framework/behaviors/AttributeBehavior.php @@ -29,7 +29,7 @@ use yii\db\ActiveRecord; * { * return [ * [ - * 'class' => AttributeBehavior::className(), + * 'class' => AttributeBehavior::class, * 'attributes' => [ * ActiveRecord::EVENT_BEFORE_INSERT => 'attribute1', * ActiveRecord::EVENT_BEFORE_UPDATE => 'attribute2', diff --git a/framework/behaviors/BlameableBehavior.php b/framework/behaviors/BlameableBehavior.php index 76574e7..de59b7a 100644 --- a/framework/behaviors/BlameableBehavior.php +++ b/framework/behaviors/BlameableBehavior.php @@ -21,7 +21,7 @@ use yii\db\BaseActiveRecord; * public function behaviors() * { * return [ - * BlameableBehavior::className(), + * BlameableBehavior::class, * ]; * } * ``` @@ -36,7 +36,7 @@ use yii\db\BaseActiveRecord; * { * return [ * [ - * 'class' => BlameableBehavior::className(), + * 'class' => BlameableBehavior::class, * 'createdByAttribute' => 'author_id', * 'updatedByAttribute' => 'updater_id', * ], diff --git a/framework/behaviors/SluggableBehavior.php b/framework/behaviors/SluggableBehavior.php index 3b91e1a..0294f71 100644 --- a/framework/behaviors/SluggableBehavior.php +++ b/framework/behaviors/SluggableBehavior.php @@ -25,7 +25,7 @@ use Yii; * { * return [ * [ - * 'class' => SluggableBehavior::className(), + * 'class' => SluggableBehavior::class, * 'attribute' => 'title', * // 'slugAttribute' => 'slug', * ], @@ -42,7 +42,7 @@ use Yii; * { * return [ * [ - * 'class' => SluggableBehavior::className(), + * 'class' => SluggableBehavior::class, * 'slugAttribute' => 'alias', * ], * ]; @@ -219,7 +219,7 @@ class SluggableBehavior extends AttributeBehavior /* @var $model BaseActiveRecord */ $validator = Yii::createObject(array_merge( [ - 'class' => UniqueValidator::className() + 'class' => UniqueValidator::class ], $this->uniqueValidator )); diff --git a/framework/behaviors/TimestampBehavior.php b/framework/behaviors/TimestampBehavior.php index e8d7817..f4470ac 100644 --- a/framework/behaviors/TimestampBehavior.php +++ b/framework/behaviors/TimestampBehavior.php @@ -21,7 +21,7 @@ use yii\db\BaseActiveRecord; * public function behaviors() * { * return [ - * TimestampBehavior::className(), + * TimestampBehavior::class, * ]; * } * ``` @@ -42,7 +42,7 @@ use yii\db\BaseActiveRecord; * { * return [ * [ - * 'class' => TimestampBehavior::className(), + * 'class' => TimestampBehavior::class, * 'createdAtAttribute' => 'create_time', * 'updatedAtAttribute' => 'update_time', * 'value' => new Expression('NOW()'), diff --git a/framework/caching/DbCache.php b/framework/caching/DbCache.php index 8c1fcbb..7641644 100644 --- a/framework/caching/DbCache.php +++ b/framework/caching/DbCache.php @@ -82,7 +82,7 @@ class DbCache extends Cache public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/framework/caching/DbDependency.php b/framework/caching/DbDependency.php index 3488b21..86e3702 100644 --- a/framework/caching/DbDependency.php +++ b/framework/caching/DbDependency.php @@ -47,7 +47,7 @@ class DbDependency extends Dependency */ protected function generateDependencyData($cache) { - $db = Instance::ensure($this->db, Connection::className()); + $db = Instance::ensure($this->db, Connection::class); if ($this->sql === null) { throw new InvalidConfigException('DbDependency::sql must be set.'); } diff --git a/framework/captcha/Captcha.php b/framework/captcha/Captcha.php index 58a74cc..592ad89 100644 --- a/framework/captcha/Captcha.php +++ b/framework/captcha/Captcha.php @@ -50,7 +50,7 @@ use yii\widgets\InputWidget; * method, for example like this: * * ```php - * field($model, 'captcha')->widget(\yii\captcha\Captcha::classname(), [ + * field($model, 'captcha')->widget(\yii\captcha\Captcha::class, [ * // configure additional widget properties here * ]) ?> * ``` diff --git a/framework/console/controllers/CacheController.php b/framework/console/controllers/CacheController.php index 9079eec..588d5a8 100644 --- a/framework/console/controllers/CacheController.php +++ b/framework/console/controllers/CacheController.php @@ -273,6 +273,6 @@ class CacheController extends Controller */ private function isCacheClass($className) { - return is_subclass_of($className, Cache::className()); + return is_subclass_of($className, Cache::class); } } diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index 11f5960..db5e055 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -149,7 +149,7 @@ class MigrateController extends BaseMigrateController { if (parent::beforeAction($action)) { if ($action->id !== 'create') { - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } return true; } else { diff --git a/framework/data/ActiveDataProvider.php b/framework/data/ActiveDataProvider.php index 17bb3de..82870c1 100644 --- a/framework/data/ActiveDataProvider.php +++ b/framework/data/ActiveDataProvider.php @@ -88,7 +88,7 @@ class ActiveDataProvider extends BaseDataProvider { parent::init(); if (is_string($this->db)) { - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } } diff --git a/framework/data/BaseDataProvider.php b/framework/data/BaseDataProvider.php index 01ea42b..fef7eeb 100644 --- a/framework/data/BaseDataProvider.php +++ b/framework/data/BaseDataProvider.php @@ -189,7 +189,7 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa public function setPagination($value) { if (is_array($value)) { - $config = ['class' => Pagination::className()]; + $config = ['class' => Pagination::class]; if ($this->id !== null) { $config['pageParam'] = $this->id . '-page'; $config['pageSizeParam'] = $this->id . '-per-page'; @@ -229,7 +229,7 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa public function setSort($value) { if (is_array($value)) { - $config = ['class' => Sort::className()]; + $config = ['class' => Sort::class]; if ($this->id !== null) { $config['sortParam'] = $this->id . '-sort'; } diff --git a/framework/data/SqlDataProvider.php b/framework/data/SqlDataProvider.php index f36b8c4..44fb5bf 100644 --- a/framework/data/SqlDataProvider.php +++ b/framework/data/SqlDataProvider.php @@ -93,7 +93,7 @@ class SqlDataProvider extends BaseDataProvider public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->sql === null) { throw new InvalidConfigException('The "sql" property must be set.'); } diff --git a/framework/db/ActiveQuery.php b/framework/db/ActiveQuery.php index 49211a6..d6aaeac 100644 --- a/framework/db/ActiveQuery.php +++ b/framework/db/ActiveQuery.php @@ -660,7 +660,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface * ```php * public function getActiveUsers() * { - * return $this->hasMany(User::className(), ['id' => 'user_id']) + * return $this->hasMany(User::class, ['id' => 'user_id']) * ->onCondition(['active' => true]); * } * ``` @@ -730,7 +730,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface * ```php * public function getItems() * { - * return $this->hasMany(Item::className(), ['id' => 'item_id']) + * return $this->hasMany(Item::class, ['id' => 'item_id']) * ->viaTable('order_item', ['order_id' => 'id']); * } * ``` diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php index e3270f5..fe919a4 100644 --- a/framework/db/ActiveRecord.php +++ b/framework/db/ActiveRecord.php @@ -268,7 +268,7 @@ class ActiveRecord extends BaseActiveRecord */ public static function find() { - return Yii::createObject(ActiveQuery::className(), [get_called_class()]); + return Yii::createObject(ActiveQuery::class, [get_called_class()]); } /** diff --git a/framework/db/ActiveRelationTrait.php b/framework/db/ActiveRelationTrait.php index 0a31031..859310b 100644 --- a/framework/db/ActiveRelationTrait.php +++ b/framework/db/ActiveRelationTrait.php @@ -85,12 +85,12 @@ trait ActiveRelationTrait * ```php * public function getOrders() * { - * return $this->hasOne(Order::className(), ['id' => 'order_id']); + * return $this->hasOne(Order::class, ['id' => 'order_id']); * } * * public function getOrderItems() * { - * return $this->hasMany(Item::className(), ['id' => 'item_id']) + * return $this->hasMany(Item::class, ['id' => 'item_id']) * ->via('orders'); * } * ``` @@ -123,7 +123,7 @@ trait ActiveRelationTrait * ```php * public function getOrders() * { - * return $this->hasMany(Order::className(), ['customer_id' => 'id'])->inverseOf('customer'); + * return $this->hasMany(Order::class, ['customer_id' => 'id'])->inverseOf('customer'); * } * ``` * diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 75272f1..a6648c7 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -319,7 +319,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface * ```php * public function getCountry() * { - * return $this->hasOne(Country::className(), ['id' => 'country_id']); + * return $this->hasOne(Country::class, ['id' => 'country_id']); * } * ``` * @@ -360,7 +360,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface * ```php * public function getOrders() * { - * return $this->hasMany(Order::className(), ['customer_id' => 'id']); + * return $this->hasMany(Order::class, ['customer_id' => 'id']); * } * ``` * diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 58bf2ca..a87e998 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -67,7 +67,7 @@ class Migration extends Component implements MigrationInterface public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); $this->db->getSchema()->refresh(); } diff --git a/framework/db/Query.php b/framework/db/Query.php index 2c099c0..eef911d 100644 --- a/framework/db/Query.php +++ b/framework/db/Query.php @@ -164,7 +164,7 @@ class Query extends Component implements QueryInterface public function batch($batchSize = 100, $db = null) { return Yii::createObject([ - 'class' => BatchQueryResult::className(), + 'class' => BatchQueryResult::class, 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, @@ -191,7 +191,7 @@ class Query extends Component implements QueryInterface public function each($batchSize = 100, $db = null) { return Yii::createObject([ - 'class' => BatchQueryResult::className(), + 'class' => BatchQueryResult::class, 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, diff --git a/framework/di/Instance.php b/framework/di/Instance.php index f51e0f2..7d756b5 100644 --- a/framework/di/Instance.php +++ b/framework/di/Instance.php @@ -91,9 +91,9 @@ class Instance * use yii\db\Connection; * * // returns Yii::$app->db - * $db = Instance::ensure('db', Connection::className()); + * $db = Instance::ensure('db', Connection::class); * // returns an instance of Connection using the given configuration - * $db = Instance::ensure(['dsn' => 'sqlite:path/to/my.db'], Connection::className()); + * $db = Instance::ensure(['dsn' => 'sqlite:path/to/my.db'], Connection::class); * ``` * * @param object|string|array|static $reference an object or a reference to the desired object. diff --git a/framework/filters/AccessControl.php b/framework/filters/AccessControl.php index 5c1ce9a..dca9990 100644 --- a/framework/filters/AccessControl.php +++ b/framework/filters/AccessControl.php @@ -31,7 +31,7 @@ use yii\web\ForbiddenHttpException; * { * return [ * 'access' => [ - * 'class' => \yii\filters\AccessControl::className(), + * 'class' => \yii\filters\AccessControl::class, * 'only' => ['create', 'update'], * 'rules' => [ * // deny all POST requests @@ -95,7 +95,7 @@ class AccessControl extends ActionFilter public function init() { parent::init(); - $this->user = Instance::ensure($this->user, User::className()); + $this->user = Instance::ensure($this->user, User::class); foreach ($this->rules as $i => $rule) { if (is_array($rule)) { $this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule)); diff --git a/framework/filters/Cors.php b/framework/filters/Cors.php index 2d8fbee..3c71aca 100644 --- a/framework/filters/Cors.php +++ b/framework/filters/Cors.php @@ -24,7 +24,7 @@ use yii\web\Response; * { * return [ * 'corsFilter' => [ - * 'class' => \yii\filters\Cors::className(), + * 'class' => \yii\filters\Cors::class, * ], * ]; * } @@ -38,7 +38,7 @@ use yii\web\Response; * { * return [ * 'corsFilter' => [ - * 'class' => \yii\filters\Cors::className(), + * 'class' => \yii\filters\Cors::class, * 'cors' => [ * // restrict access to * 'Origin' => ['http://www.myserver.com', 'https://www.myserver.com'], diff --git a/framework/filters/PageCache.php b/framework/filters/PageCache.php index cac3bb4..81287b7 100644 --- a/framework/filters/PageCache.php +++ b/framework/filters/PageCache.php @@ -148,7 +148,7 @@ class PageCache extends ActionFilter return true; } - $this->cache = Instance::ensure($this->cache, Cache::className()); + $this->cache = Instance::ensure($this->cache, Cache::class); if (is_array($this->dependency)) { $this->dependency = Yii::createObject($this->dependency); diff --git a/framework/filters/RateLimiter.php b/framework/filters/RateLimiter.php index d55ca78..e4750e3 100644 --- a/framework/filters/RateLimiter.php +++ b/framework/filters/RateLimiter.php @@ -23,7 +23,7 @@ use yii\web\TooManyRequestsHttpException; * { * return [ * 'rateLimiter' => [ - * 'class' => \yii\filters\RateLimiter::className(), + * 'class' => \yii\filters\RateLimiter::class, * ], * ]; * } diff --git a/framework/filters/VerbFilter.php b/framework/filters/VerbFilter.php index 4acda1e..61e835c 100644 --- a/framework/filters/VerbFilter.php +++ b/framework/filters/VerbFilter.php @@ -28,7 +28,7 @@ use yii\web\MethodNotAllowedHttpException; * { * return [ * 'verbs' => [ - * 'class' => \yii\filters\VerbFilter::className(), + * 'class' => \yii\filters\VerbFilter::class, * 'actions' => [ * 'index' => ['get'], * 'view' => ['get'], diff --git a/framework/filters/auth/CompositeAuth.php b/framework/filters/auth/CompositeAuth.php index 0465723..a907d4a 100644 --- a/framework/filters/auth/CompositeAuth.php +++ b/framework/filters/auth/CompositeAuth.php @@ -23,10 +23,10 @@ use yii\base\InvalidConfigException; * { * return [ * 'compositeAuth' => [ - * 'class' => \yii\filters\auth\CompositeAuth::className(), + * 'class' => \yii\filters\auth\CompositeAuth::class, * 'authMethods' => [ - * \yii\filters\auth\HttpBasicAuth::className(), - * \yii\filters\auth\QueryParamAuth::className(), + * \yii\filters\auth\HttpBasicAuth::class, + * \yii\filters\auth\QueryParamAuth::class, * ], * ], * ]; diff --git a/framework/filters/auth/HttpBasicAuth.php b/framework/filters/auth/HttpBasicAuth.php index a8795e1..a11463b 100644 --- a/framework/filters/auth/HttpBasicAuth.php +++ b/framework/filters/auth/HttpBasicAuth.php @@ -17,7 +17,7 @@ namespace yii\filters\auth; * { * return [ * 'basicAuth' => [ - * 'class' => \yii\filters\auth\HttpBasicAuth::className(), + * 'class' => \yii\filters\auth\HttpBasicAuth::class, * ], * ]; * } diff --git a/framework/filters/auth/HttpBearerAuth.php b/framework/filters/auth/HttpBearerAuth.php index 9155c94..e6f8379 100644 --- a/framework/filters/auth/HttpBearerAuth.php +++ b/framework/filters/auth/HttpBearerAuth.php @@ -17,7 +17,7 @@ namespace yii\filters\auth; * { * return [ * 'bearerAuth' => [ - * 'class' => \yii\filters\auth\HttpBearerAuth::className(), + * 'class' => \yii\filters\auth\HttpBearerAuth::class, * ], * ]; * } diff --git a/framework/grid/ActionColumn.php b/framework/grid/ActionColumn.php index 6e5e3fd..8951cc0 100644 --- a/framework/grid/ActionColumn.php +++ b/framework/grid/ActionColumn.php @@ -21,7 +21,7 @@ use yii\helpers\Url; * 'columns' => [ * // ... * [ - * 'class' => ActionColumn::className(), + * 'class' => ActionColumn::class, * // you may configure additional properties here * ], * ] diff --git a/framework/grid/GridView.php b/framework/grid/GridView.php index b2bca6c..5d39f36 100644 --- a/framework/grid/GridView.php +++ b/framework/grid/GridView.php @@ -141,14 +141,14 @@ class GridView extends BaseListView * * ```php * [ - * ['class' => SerialColumn::className()], + * ['class' => SerialColumn::class], * [ - * 'class' => DataColumn::className(), // this line is optional + * 'class' => DataColumn::class, // this line is optional * 'attribute' => 'name', * 'format' => 'text', * 'label' => 'Name', * ], - * ['class' => CheckboxColumn::className()], + * ['class' => CheckboxColumn::class], * ] * ``` * @@ -526,7 +526,7 @@ class GridView extends BaseListView $column = $this->createDataColumn($column); } else { $column = Yii::createObject(array_merge([ - 'class' => $this->dataColumnClass ? : DataColumn::className(), + 'class' => $this->dataColumnClass ? : DataColumn::class, 'grid' => $this, ], $column)); } @@ -551,7 +551,7 @@ class GridView extends BaseListView } return Yii::createObject([ - 'class' => $this->dataColumnClass ? : DataColumn::className(), + 'class' => $this->dataColumnClass ? : DataColumn::class, 'grid' => $this, 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', diff --git a/framework/i18n/DbMessageSource.php b/framework/i18n/DbMessageSource.php index f6ac442..ca60a1c 100644 --- a/framework/i18n/DbMessageSource.php +++ b/framework/i18n/DbMessageSource.php @@ -90,9 +90,9 @@ class DbMessageSource extends MessageSource public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->enableCaching) { - $this->cache = Instance::ensure($this->cache, Cache::className()); + $this->cache = Instance::ensure($this->cache, Cache::class); } } diff --git a/framework/log/DbTarget.php b/framework/log/DbTarget.php index d77f6e9..5eee2c2 100644 --- a/framework/log/DbTarget.php +++ b/framework/log/DbTarget.php @@ -52,7 +52,7 @@ class DbTarget extends Target public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/framework/mail/BaseMailer.php b/framework/mail/BaseMailer.php index 913a97b..52be574 100644 --- a/framework/mail/BaseMailer.php +++ b/framework/mail/BaseMailer.php @@ -140,7 +140,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont protected function createView(array $config) { if (!array_key_exists('class', $config)) { - $config['class'] = View::className(); + $config['class'] = View::class; } return Yii::createObject($config); diff --git a/framework/mutex/DbMutex.php b/framework/mutex/DbMutex.php index 237975f..7bc5913 100644 --- a/framework/mutex/DbMutex.php +++ b/framework/mutex/DbMutex.php @@ -38,6 +38,6 @@ abstract class DbMutex extends Mutex public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } } diff --git a/framework/rbac/DbManager.php b/framework/rbac/DbManager.php index cc80e8a..2ee35eb 100644 --- a/framework/rbac/DbManager.php +++ b/framework/rbac/DbManager.php @@ -107,9 +107,9 @@ class DbManager extends BaseManager public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->cache !== null) { - $this->cache = Instance::ensure($this->cache, Cache::className()); + $this->cache = Instance::ensure($this->cache, Cache::class); } } @@ -431,7 +431,7 @@ class DbManager extends BaseManager */ protected function populateItem($row) { - $class = $row['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className(); + $class = $row['type'] == Item::TYPE_PERMISSION ? Permission::class : Role::class; if (!isset($row['data']) || ($data = @unserialize($row['data'])) === false) { $data = null; diff --git a/framework/rbac/PhpManager.php b/framework/rbac/PhpManager.php index 62e9dec..5740e38 100644 --- a/framework/rbac/PhpManager.php +++ b/framework/rbac/PhpManager.php @@ -691,7 +691,7 @@ class PhpManager extends BaseManager $rules = $this->loadFromFile($this->ruleFile); foreach ($items as $name => $item) { - $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className(); + $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::class : Role::class; $this->items[$name] = new $class([ 'name' => $name, diff --git a/framework/rest/Controller.php b/framework/rest/Controller.php index 7802636..17ca04b 100644 --- a/framework/rest/Controller.php +++ b/framework/rest/Controller.php @@ -47,21 +47,21 @@ class Controller extends \yii\web\Controller { return [ 'contentNegotiator' => [ - 'class' => ContentNegotiator::className(), + 'class' => ContentNegotiator::class, 'formats' => [ 'application/json' => Response::FORMAT_JSON, 'application/xml' => Response::FORMAT_XML, ], ], 'verbFilter' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => $this->verbs(), ], 'authenticator' => [ - 'class' => CompositeAuth::className(), + 'class' => CompositeAuth::class, ], 'rateLimiter' => [ - 'class' => RateLimiter::className(), + 'class' => RateLimiter::class, ], ]; } diff --git a/framework/test/DbFixture.php b/framework/test/DbFixture.php index 97b956e..a8f0033 100644 --- a/framework/test/DbFixture.php +++ b/framework/test/DbFixture.php @@ -37,6 +37,6 @@ abstract class DbFixture extends Fixture public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Object::className()); + $this->db = Instance::ensure($this->db, Object::class); } } diff --git a/framework/test/FixtureTrait.php b/framework/test/FixtureTrait.php index 463cc56..4357c75 100644 --- a/framework/test/FixtureTrait.php +++ b/framework/test/FixtureTrait.php @@ -40,12 +40,12 @@ trait FixtureTrait * ```php * [ * // anonymous fixture - * PostFixture::className(), + * PostFixture::class, * // "users" fixture - * 'users' => UserFixture::className(), + * 'users' => UserFixture::class, * // "cache" fixture with configuration * 'cache' => [ - * 'class' => CacheFixture::className(), + * 'class' => CacheFixture::class, * 'host' => 'xxx', * ], * ] diff --git a/framework/validators/UniqueValidator.php b/framework/validators/UniqueValidator.php index b0f415e..576b1fe 100644 --- a/framework/validators/UniqueValidator.php +++ b/framework/validators/UniqueValidator.php @@ -106,7 +106,7 @@ class UniqueValidator extends Validator $query->andWhere($this->filter); } - if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || $model->className() !== $targetClass::className()) { + if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || get_class($model) !== $targetClass::class) { // if current $model isn't in the database yet then it's OK just to call exists() // also there's no need to run check based on primary keys, when $targetClass is not the same as $model's class $exists = $query->exists(); diff --git a/framework/web/AssetManager.php b/framework/web/AssetManager.php index a18710b..faa2632 100644 --- a/framework/web/AssetManager.php +++ b/framework/web/AssetManager.php @@ -371,10 +371,10 @@ class AssetManager extends Component public function getConverter() { if ($this->_converter === null) { - $this->_converter = Yii::createObject(AssetConverter::className()); + $this->_converter = Yii::createObject(AssetConverter::class); } elseif (is_array($this->_converter) || is_string($this->_converter)) { if (is_array($this->_converter) && !isset($this->_converter['class'])) { - $this->_converter['class'] = AssetConverter::className(); + $this->_converter['class'] = AssetConverter::class; } $this->_converter = Yii::createObject($this->_converter); } diff --git a/framework/web/CacheSession.php b/framework/web/CacheSession.php index acbf03e..6f69c4c 100644 --- a/framework/web/CacheSession.php +++ b/framework/web/CacheSession.php @@ -56,7 +56,7 @@ class CacheSession extends Session public function init() { parent::init(); - $this->cache = Instance::ensure($this->cache, Cache::className()); + $this->cache = Instance::ensure($this->cache, Cache::class); } /** diff --git a/framework/web/DbSession.php b/framework/web/DbSession.php index 108e94b..4ba3a9a 100644 --- a/framework/web/DbSession.php +++ b/framework/web/DbSession.php @@ -83,7 +83,7 @@ class DbSession extends MultiFieldSession public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/framework/widgets/ActiveField.php b/framework/widgets/ActiveField.php index 6a67bab..2a7fcb3 100644 --- a/framework/widgets/ActiveField.php +++ b/framework/widgets/ActiveField.php @@ -653,7 +653,7 @@ class ActiveField extends Component * the following code, assuming that `$form` is your [[ActiveForm]] instance: * * ```php - * $form->field($model, 'date')->widget(\yii\widgets\MaskedInput::className(), [ + * $form->field($model, 'date')->widget(\yii\widgets\MaskedInput::class, [ * 'mask' => '99/99/9999', * ]); * ``` diff --git a/framework/widgets/BaseListView.php b/framework/widgets/BaseListView.php index 7b2b541..c212b5a 100644 --- a/framework/widgets/BaseListView.php +++ b/framework/widgets/BaseListView.php @@ -237,7 +237,7 @@ abstract class BaseListView extends Widget } /* @var $class LinkPager */ $pager = $this->pager; - $class = ArrayHelper::remove($pager, 'class', LinkPager::className()); + $class = ArrayHelper::remove($pager, 'class', LinkPager::class); $pager['pagination'] = $pagination; $pager['view'] = $this->getView(); @@ -256,7 +256,7 @@ abstract class BaseListView extends Widget } /* @var $class LinkSorter */ $sorter = $this->sorter; - $class = ArrayHelper::remove($sorter, 'class', LinkSorter::className()); + $class = ArrayHelper::remove($sorter, 'class', LinkSorter::class); $sorter['sort'] = $sort; $sorter['view'] = $this->getView(); diff --git a/framework/widgets/FragmentCache.php b/framework/widgets/FragmentCache.php index d9e4fe6..5818fe9 100644 --- a/framework/widgets/FragmentCache.php +++ b/framework/widgets/FragmentCache.php @@ -84,7 +84,7 @@ class FragmentCache extends Widget { parent::init(); - $this->cache = $this->enabled ? Instance::ensure($this->cache, Cache::className()) : null; + $this->cache = $this->enabled ? Instance::ensure($this->cache, Cache::class) : null; if ($this->cache instanceof Cache && $this->getCachedContent() === false) { $this->getView()->cacheStack[] = $this; diff --git a/framework/widgets/MaskedInput.php b/framework/widgets/MaskedInput.php index c162f20..95a70a4 100644 --- a/framework/widgets/MaskedInput.php +++ b/framework/widgets/MaskedInput.php @@ -33,7 +33,7 @@ use yii\web\View; * method, for example like this: * * ```php - * field($model, 'from_date')->widget(\yii\widgets\MaskedInput::className(), [ + * field($model, 'from_date')->widget(\yii\widgets\MaskedInput::class, [ * 'mask' => '999-999-9999', * ]) ?> * ```