Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated method className() for branch 2.2. #19894

Merged
merged 4 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
if: matrix.php != '8.1'
run: vendor/bin/phpunit --exclude-group $PHPUNIT_EXCLUDE_GROUP --colors=always --verbose


- name: Upload coverage to Codecov.
if: matrix.php == '8.1'
uses: codecov/codecov-action@v3
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions framework/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Upgrade from Yii 2.0.34
public function rules()
{
return [
['attribute', 'each', 'rule' => ['exist', 'targetClass' => static::className(), 'targetAttribute' => 'id']],
['attribute', 'each', 'rule' => ['exist', 'targetClass' => static::class, 'targetAttribute' => 'id']],
];
}
```
Expand Down Expand Up @@ -521,9 +521,8 @@ Upgrade from Yii 2.0.13

* Log targets (like `yii\log\EmailTarget`) are now throwing `yii\log\LogRuntimeException` in case log can not be properly exported.

* You can start preparing your application for Yii 2.1 by doing the following:
* You can start preparing your application for Yii 2.2 by doing the following:

- Replace `::className()` calls with `::class` (if you’re running PHP 5.5+).
- Replace usages of `yii\base\InvalidParamException` with `yii\base\InvalidArgumentException`.
- Replace calls to `Yii::trace()` with `Yii::debug()`.
- Remove calls to `yii\BaseYii::powered()`.
Expand Down
10 changes: 0 additions & 10 deletions framework/base/BaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@
*/
class BaseObject implements Configurable
{
/**
* Returns the fully qualified name of this class.
* @return string the fully qualified name of this class.
* @deprecated since 2.0.14. On PHP >=5.5, use `::class` instead.
*/
public static function className()
{
return get_called_class();
}

/**
* Constructor.
*
Expand Down
4 changes: 2 additions & 2 deletions framework/base/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function __construct($id, $module, $config = [])
public function init()
{
parent::init();
$this->request = Instance::ensure($this->request, Request::className());
$this->response = Instance::ensure($this->response, Response::className());
$this->request = Instance::ensure($this->request, Request::class);
$this->response = Instance::ensure($this->response, Response::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/behaviors/SluggableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected function validateSlug($slug)
/* @var $model BaseActiveRecord */
$validator = Yii::createObject(array_merge(
[
'class' => UniqueValidator::className(),
'class' => UniqueValidator::class,
],
$this->uniqueValidator
));
Expand Down
2 changes: 1 addition & 1 deletion framework/caching/DbCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/caching/DbDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DbDependency extends Dependency
protected function generateDependencyData($cache)
{
/* @var $db Connection */
$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.');
}
Expand Down
2 changes: 1 addition & 1 deletion framework/console/controllers/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ private function isCacheClass($className)
*/
private function canBeFlushed($className)
{
return !is_a($className, ApcCache::className(), true) || PHP_SAPI !== 'cli';
return !is_a($className, ApcCache::class, true) || PHP_SAPI !== 'cli';
}
}
2 changes: 1 addition & 1 deletion framework/console/controllers/FixtureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
$fixtureClassNames = [];

foreach ($fixtures as $fixture) {
$fixtureClassNames[] = $fixture::className();
$fixtureClassNames[] = $fixture::class;

Check warning on line 261 in framework/console/controllers/FixtureController.php

View check run for this annotation

Codecov / codecov/patch

framework/console/controllers/FixtureController.php#L261

Added line #L261 was not covered by tests
}

$this->outputList($fixtureClassNames);
Expand Down
2 changes: 1 addition & 1 deletion framework/console/controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function actionExtract($configFile = null)
}
} elseif ($this->config['format'] === 'db') {
/** @var Connection $db */
$db = Instance::ensure($this->config['db'], Connection::className());
$db = Instance::ensure($this->config['db'], Connection::class);
$sourceMessageTable = isset($this->config['sourceMessageTable']) ? $this->config['sourceMessageTable'] : '{{%source_message}}';
$messageTable = isset($this->config['messageTable']) ? $this->config['messageTable'] : '{{%message}}';
$this->saveMessagesToDb(
Expand Down
4 changes: 2 additions & 2 deletions framework/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->db = Instance::ensure($this->db, Connection::className());
$this->db = Instance::ensure($this->db, Connection::class);
return true;
}

Expand Down Expand Up @@ -471,7 +471,7 @@
if ($relatedColumn === null) {
$relatedColumn = 'id';
try {
$this->db = Instance::ensure($this->db, Connection::className());
$this->db = Instance::ensure($this->db, Connection::class);

Check warning on line 474 in framework/console/controllers/MigrateController.php

View check run for this annotation

Codecov / codecov/patch

framework/console/controllers/MigrateController.php#L474

Added line #L474 was not covered by tests
$relatedTableSchema = $this->db->getTableSchema($relatedTable);
if ($relatedTableSchema !== null) {
$primaryKeyCount = count($relatedTableSchema->primaryKey);
Expand Down
4 changes: 2 additions & 2 deletions framework/data/BaseDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function getPagination()
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';
Expand Down Expand Up @@ -252,7 +252,7 @@ public function getSort()
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';
}
Expand Down
4 changes: 2 additions & 2 deletions framework/data/DataFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
if (!is_object($this->_searchModel) || $this->_searchModel instanceof \Closure) {
$model = Yii::createObject($this->_searchModel);
if (!$model instanceof Model) {
throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.');
throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::class . '` or its DI compatible configuration.');

Check warning on line 291 in framework/data/DataFilter.php

View check run for this annotation

Codecov / codecov/patch

framework/data/DataFilter.php#L291

Added line #L291 was not covered by tests
}
$this->_searchModel = $model;
}
Expand All @@ -302,7 +302,7 @@
public function setSearchModel($model)
{
if (is_object($model) && !$model instanceof Model && !$model instanceof \Closure) {
throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.');
throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::class . '` or its DI compatible configuration.');
}
$this->_searchModel = $model;
}
Expand Down
2 changes: 1 addition & 1 deletion framework/data/SqlDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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.');
}
Expand Down
2 changes: 1 addition & 1 deletion framework/db/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static function deleteAll($condition = null, $params = [])
*/
public static function find()
{
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
return Yii::createObject(ActiveQuery::class, [get_called_class()]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions framework/db/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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();
$this->db->enableSlaves = false;
}
Expand Down Expand Up @@ -311,15 +311,15 @@ public function delete($table, $condition = '', $params = [])
*
* If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
* put into the generated SQL.
*
*
* Example usage:
* ```php
* class m200000_000000_create_table_fruits extends \yii\db\Migration
* {
* public function safeUp()
* {
* $this->createTable('{{%fruits}}', [
* // ...
* // ...
* 'column_name double precision null default null',
* ```

Expand Down
4 changes: 2 additions & 2 deletions framework/db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function prepare($builder)
public function batch($batchSize = 100, $db = null)
{
return Yii::createObject([
'class' => BatchQueryResult::className(),
'class' => BatchQueryResult::class,
'query' => $this,
'batchSize' => $batchSize,
'db' => $db,
Expand Down Expand Up @@ -226,7 +226,7 @@ public function batch($batchSize = 100, $db = null)
public function each($batchSize = 100, $db = null)
{
return Yii::createObject([
'class' => BatchQueryResult::className(),
'class' => BatchQueryResult::class,
'query' => $this,
'batchSize' => $batchSize,
'db' => $db,
Expand Down
4 changes: 2 additions & 2 deletions framework/db/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);

Check warning on line 316 in framework/db/Schema.php

View check run for this annotation

Codecov / codecov/patch

framework/db/Schema.php#L316

Added line #L316 was not covered by tests
}

/**
Expand All @@ -328,7 +328,7 @@
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]);
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/db/cubrid/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);

Check warning on line 252 in framework/db/cubrid/Schema.php

View check run for this annotation

Codecov / codecov/patch

framework/db/cubrid/Schema.php#L252

Added line #L252 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/db/mssql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function rollBackSavepoint($name)
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);
}

/**
Expand Down Expand Up @@ -811,6 +811,6 @@ public function insert($table, $columns)
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]);
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length, $this->db]);
}
}
4 changes: 2 additions & 2 deletions framework/db/mysql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function loadTableDefaultValues($tableName)
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);
}

/**
Expand Down Expand Up @@ -472,7 +472,7 @@ public function findUniqueIndexes($table)
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]);
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length, $this->db]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/db/oci/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ public function quoteSimpleTableName($name)
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);
}

/**
* {@inheritdoc}
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]);
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/db/pgsql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected function loadTableDefaultValues($tableName)
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/db/sqlite/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected function loadTableDefaultValues($tableName)
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
return Yii::createObject(QueryBuilder::class, [$this->db]);
}

/**
Expand All @@ -216,7 +216,7 @@ public function createQueryBuilder()
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]);
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/filters/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function init()
{
parent::init();
if ($this->user !== false) {
$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)) {
Expand Down
Loading
Loading