From b503dc9ff2d2b528d156b00bffca8c65e30ba148 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 1 May 2016 03:45:47 +0200 Subject: [PATCH] use ::class also in documentation and configs - shorter syntax - native PHP feature, so it does not depend on yii\base\Object - Does not trigger autoloading anymore --- composer.json | 2 +- framework/BaseYii.php | 2 +- framework/base/Component.php | 4 ++-- framework/base/Controller.php | 4 ++-- framework/base/Module.php | 8 ++++---- framework/caching/DbCache.php | 2 +- framework/caching/MemCache.php | 2 +- framework/composer.json | 2 +- framework/console/controllers/AssetController.php | 2 +- framework/db/Connection.php | 2 +- framework/di/Container.php | 18 +++++++++--------- framework/di/Instance.php | 6 +++--- framework/di/ServiceLocator.php | 12 ++++++------ framework/filters/ContentNegotiator.php | 4 ++-- framework/filters/HttpCache.php | 2 +- framework/filters/PageCache.php | 6 +++--- framework/grid/ActionColumn.php | 4 ++-- framework/grid/CheckboxColumn.php | 2 +- framework/grid/GridView.php | 6 +++--- framework/grid/SerialColumn.php | 2 +- framework/helpers/BaseMarkdown.php | 8 ++++---- framework/i18n/I18N.php | 4 ++-- framework/log/Dispatcher.php | 4 ++-- framework/log/EmailTarget.php | 4 ++-- framework/mutex/MysqlMutex.php | 4 ++-- framework/mutex/PgsqlMutex.php | 4 ++-- framework/rest/ActiveController.php | 12 ++++++------ framework/rest/UrlRule.php | 6 +++--- framework/validators/UniqueValidator.php | 8 ++++++-- framework/validators/Validator.php | 4 ++-- framework/web/CacheSession.php | 2 +- framework/web/DbSession.php | 2 +- framework/web/JsonResponseFormatter.php | 2 +- framework/web/Response.php | 8 ++++---- framework/web/UrlRule.php | 2 +- framework/widgets/FragmentCache.php | 2 +- 36 files changed, 86 insertions(+), 82 deletions(-) diff --git a/composer.json b/composer.json index 8e5cce7..a137b36 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "yiisoft/yii2": "self.version" }, "require": { - "php": ">=5.6.0", + "php": ">=5.5.0", "ext-mbstring": "*", "ext-ctype": "*", "lib-pcre": "*", diff --git a/framework/BaseYii.php b/framework/BaseYii.php index 0f99597..10ade3b 100644 --- a/framework/BaseYii.php +++ b/framework/BaseYii.php @@ -307,7 +307,7 @@ class BaseYii * * // create an object using a configuration array * $object = Yii::createObject([ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'username' => 'root', * 'password' => '', diff --git a/framework/base/Component.php b/framework/base/Component.php index a7721e1..b29ed87 100644 --- a/framework/base/Component.php +++ b/framework/base/Component.php @@ -82,7 +82,7 @@ use Yii; * ```php * [ * 'as tree' => [ - * 'class' => 'Tree', + * 'class' => Tree::class, * ], * ] * ``` @@ -413,7 +413,7 @@ class Component extends Object * * ```php * 'behaviorName' => [ - * 'class' => 'BehaviorClass', + * 'class' => BehaviorClass::class, * 'property1' => 'value1', * 'property2' => 'value2', * ] diff --git a/framework/base/Controller.php b/framework/base/Controller.php index 0dba943..ced58be 100644 --- a/framework/base/Controller.php +++ b/framework/base/Controller.php @@ -92,9 +92,9 @@ class Controller extends Component implements ViewContextInterface * * ```php * return [ - * 'action1' => 'app\components\Action1', + * 'action1' => \app\components\Action1::class, * 'action2' => [ - * 'class' => 'app\components\Action2', + * 'class' => \app\components\Action2::class, * 'property1' => 'value1', * 'property2' => 'value2', * ], diff --git a/framework/base/Module.php b/framework/base/Module.php index 8657848..b85508f 100644 --- a/framework/base/Module.php +++ b/framework/base/Module.php @@ -76,9 +76,9 @@ class Module extends ServiceLocator * * ```php * [ - * 'account' => 'app\controllers\UserController', + * 'account' => \app\controllers\UserController::class, * 'article' => [ - * 'class' => 'app\controllers\PostController', + * 'class' => \app\controllers\PostController::class, * 'pageTitle' => 'something new', * ], * ] @@ -417,10 +417,10 @@ class Module extends ServiceLocator * ```php * [ * 'comment' => [ - * 'class' => 'app\modules\comment\CommentModule', + * 'class' => \app\modules\comment\CommentModule::class, * 'db' => 'db', * ], - * 'booking' => ['class' => 'app\modules\booking\BookingModule'], + * 'booking' => ['class' => \app\modules\booking\BookingModule::class], * ] * ``` * diff --git a/framework/caching/DbCache.php b/framework/caching/DbCache.php index 7641644..c37c29b 100644 --- a/framework/caching/DbCache.php +++ b/framework/caching/DbCache.php @@ -25,7 +25,7 @@ use yii\di\Instance; * * ```php * 'cache' => [ - * 'class' => 'yii\caching\DbCache', + * 'class' => \yii\caching\DbCache::class, * // 'db' => 'mydb', * // 'cacheTable' => 'my_cache', * ] diff --git a/framework/caching/MemCache.php b/framework/caching/MemCache.php index 6a1207a..a0d3ce3 100644 --- a/framework/caching/MemCache.php +++ b/framework/caching/MemCache.php @@ -32,7 +32,7 @@ use yii\base\InvalidConfigException; * [ * 'components' => [ * 'cache' => [ - * 'class' => 'yii\caching\MemCache', + * 'class' => \yii\caching\MemCache::class, * 'servers' => [ * [ * 'host' => 'server1', diff --git a/framework/composer.json b/framework/composer.json index 2dc4d87..ee4c741 100644 --- a/framework/composer.json +++ b/framework/composer.json @@ -57,7 +57,7 @@ "source": "https://github.com/yiisoft/yii2" }, "require": { - "php": ">=5.6.0", + "php": ">=5.5.0", "ext-mbstring": "*", "ext-ctype": "*", "lib-pcre": "*", diff --git a/framework/console/controllers/AssetController.php b/framework/console/controllers/AssetController.php index 841fc70..fd6e916 100644 --- a/framework/console/controllers/AssetController.php +++ b/framework/console/controllers/AssetController.php @@ -692,7 +692,7 @@ return [ // Asset bundle for compression output: 'targets' => [ 'all' => [ - 'class' => 'yii\web\AssetBundle', + 'class' => \yii\web\AssetBundle::class, 'basePath' => '@webroot/assets', 'baseUrl' => '@web/assets', 'js' => 'js/all-{hash}.js', diff --git a/framework/db/Connection.php b/framework/db/Connection.php index efa1e63..3ddcfc2 100644 --- a/framework/db/Connection.php +++ b/framework/db/Connection.php @@ -101,7 +101,7 @@ use yii\caching\Cache; * ```php * 'components' => [ * 'db' => [ - * 'class' => '\yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'username' => 'root', * 'password' => '', diff --git a/framework/di/Container.php b/framework/di/Container.php index c312937..03f78e2 100644 --- a/framework/di/Container.php +++ b/framework/di/Container.php @@ -72,13 +72,13 @@ use yii\helpers\ArrayHelper; * } * * $container = new Container; - * $container->set('yii\db\Connection', [ + * $container->set(\yii\db\Connection::class, [ * 'dsn' => '...', * ]); - * $container->set('app\models\UserFinderInterface', [ - * 'class' => 'app\models\UserFinder', + * $container->set(\app\models\UserFinderInterface::class, [ + * 'class' => \app\models\UserFinder::class, * ]); - * $container->set('userLister', 'app\models\UserLister'); + * $container->set('userLister', \app\models\UserLister::class); * * $lister = $container->get('userLister'); * @@ -191,20 +191,20 @@ class Container extends Component * * ```php * // register a class name as is. This can be skipped. - * $container->set('yii\db\Connection'); + * $container->set(\yii\db\Connection::class); * * // register an interface * // When a class depends on the interface, the corresponding class * // will be instantiated as the dependent object - * $container->set('yii\mail\MailInterface', 'yii\swiftmailer\Mailer'); + * $container->set(\yii\mail\MailInterface::class, \yii\swiftmailer\Mailer::class); * * // register an alias name. You can use $container->get('foo') * // to create an instance of Connection - * $container->set('foo', 'yii\db\Connection'); + * $container->set('foo', \yii\db\Connection::class); * * // register a class with configuration. The configuration * // will be applied when the class is instantiated by get() - * $container->set('yii\db\Connection', [ + * $container->set(\yii\db\Connection::class, [ * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'username' => 'root', * 'password' => '', @@ -214,7 +214,7 @@ class Container extends Component * // register an alias name with class configuration * // In this case, a "class" element is required to specify the class * $container->set('db', [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'username' => 'root', * 'password' => '', diff --git a/framework/di/Instance.php b/framework/di/Instance.php index 7d756b5..bfa18eb 100644 --- a/framework/di/Instance.php +++ b/framework/di/Instance.php @@ -25,9 +25,9 @@ use yii\base\InvalidConfigException; * * ```php * $container = new \yii\di\Container; - * $container->set('cache', 'yii\caching\DbCache', Instance::of('db')); + * $container->set('cache', \yii\caching\DbCache::class, Instance::of('db')); * $container->set('db', [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'sqlite:path/to/file.db', * ]); * ``` @@ -42,7 +42,7 @@ use yii\base\InvalidConfigException; * public function init() * { * parent::init(); - * $this->db = Instance::ensure($this->db, 'yii\db\Connection'); + * $this->db = Instance::ensure($this->db, \yii\db\Connection::class); * } * } * ``` diff --git a/framework/di/ServiceLocator.php b/framework/di/ServiceLocator.php index f4c28df..756ad37 100644 --- a/framework/di/ServiceLocator.php +++ b/framework/di/ServiceLocator.php @@ -26,11 +26,11 @@ use yii\base\InvalidConfigException; * $locator = new \yii\di\ServiceLocator; * $locator->setComponents([ * 'db' => [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'sqlite:path/to/file.db', * ], * 'cache' => [ - * 'class' => 'yii\caching\DbCache', + * 'class' => \yii\caching\DbCache::class, * 'db' => 'db', * ], * ]); @@ -146,11 +146,11 @@ class ServiceLocator extends Component * * ```php * // a class name - * $locator->set('cache', 'yii\caching\FileCache'); + * $locator->set('cache', \yii\caching\FileCache::class); * * // a configuration array * $locator->set('db', [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'username' => 'root', * 'password' => '', @@ -240,11 +240,11 @@ class ServiceLocator extends Component * ```php * [ * 'db' => [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'sqlite:path/to/file.db', * ], * 'cache' => [ - * 'class' => 'yii\caching\DbCache', + * 'class' => \yii\caching\DbCache::class, * 'db' => 'db', * ], * ] diff --git a/framework/filters/ContentNegotiator.php b/framework/filters/ContentNegotiator.php index 7d2bfc5..7be7c7b 100644 --- a/framework/filters/ContentNegotiator.php +++ b/framework/filters/ContentNegotiator.php @@ -39,7 +39,7 @@ use yii\web\UnsupportedMediaTypeHttpException; * return [ * 'bootstrap' => [ * [ - * 'class' => 'yii\filters\ContentNegotiator', + * 'class' => \yii\filters\ContentNegotiator::class, * 'formats' => [ * 'application/json' => Response::FORMAT_JSON, * 'application/xml' => Response::FORMAT_XML, @@ -64,7 +64,7 @@ use yii\web\UnsupportedMediaTypeHttpException; * { * return [ * [ - * 'class' => 'yii\filters\ContentNegotiator', + * 'class' => \yii\filters\ContentNegotiator::class, * 'only' => ['view', 'index'], // in a controller * // if in a module, use the following IDs for user actions * // 'only' => ['user/view', 'user/index'] diff --git a/framework/filters/HttpCache.php b/framework/filters/HttpCache.php index 8df842f..f60cad7 100644 --- a/framework/filters/HttpCache.php +++ b/framework/filters/HttpCache.php @@ -25,7 +25,7 @@ use yii\base\Action; * { * return [ * [ - * 'class' => 'yii\filters\HttpCache', + * 'class' => \yii\filters\HttpCache::class, * 'only' => ['index'], * 'lastModified' => function ($action, $params) { * $q = new \yii\db\Query(); diff --git a/framework/filters/PageCache.php b/framework/filters/PageCache.php index 81287b7..afd9711 100644 --- a/framework/filters/PageCache.php +++ b/framework/filters/PageCache.php @@ -30,11 +30,11 @@ use yii\web\Response; * { * return [ * 'pageCache' => [ - * 'class' => 'yii\filters\PageCache', + * 'class' => \yii\filters\PageCache::class, * 'only' => ['index'], * 'duration' => 60, * 'dependency' => [ - * 'class' => 'yii\caching\DbDependency', + * 'class' => \yii\caching\DbDependency::class, * 'sql' => 'SELECT COUNT(*) FROM post', * ], * 'variations' => [ @@ -74,7 +74,7 @@ class PageCache extends ActionFilter * * ```php * [ - * 'class' => 'yii\caching\DbDependency', + * 'class' => \yii\caching\DbDependency::class, * 'sql' => 'SELECT MAX(updated_at) FROM post', * ] * ``` diff --git a/framework/grid/ActionColumn.php b/framework/grid/ActionColumn.php index 8951cc0..3b15d62 100644 --- a/framework/grid/ActionColumn.php +++ b/framework/grid/ActionColumn.php @@ -21,7 +21,7 @@ use yii\helpers\Url; * 'columns' => [ * // ... * [ - * 'class' => ActionColumn::class, + * 'class' => \yii\grid\ActionColumn::class, * // you may configure additional properties here * ], * ] @@ -53,7 +53,7 @@ class ActionColumn extends Column * As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows: * * ```php - * ['class' => 'yii\grid\ActionColumn', 'template' => '{view} {update}'], + * ['class' => \yii\grid\ActionColumn::class, 'template' => '{view} {update}'], * ``` * * @see buttons diff --git a/framework/grid/CheckboxColumn.php b/framework/grid/CheckboxColumn.php index 9b5a17d..ad5f6c8 100644 --- a/framework/grid/CheckboxColumn.php +++ b/framework/grid/CheckboxColumn.php @@ -21,7 +21,7 @@ use yii\helpers\Json; * 'columns' => [ * // ... * [ - * 'class' => 'yii\grid\CheckboxColumn', + * 'class' => \yii\grid\CheckboxColumn::class, * // you may configure additional properties here * ], * ] diff --git a/framework/grid/GridView.php b/framework/grid/GridView.php index 5d39f36..30e0380 100644 --- a/framework/grid/GridView.php +++ b/framework/grid/GridView.php @@ -141,14 +141,14 @@ class GridView extends BaseListView * * ```php * [ - * ['class' => SerialColumn::class], + * ['class' => \yii\grid\SerialColumn::class], * [ - * 'class' => DataColumn::class, // this line is optional + * 'class' => \yii\grid\DataColumn::class, // this line is optional * 'attribute' => 'name', * 'format' => 'text', * 'label' => 'Name', * ], - * ['class' => CheckboxColumn::class], + * ['class' => \yii\grid\CheckboxColumn::class], * ] * ``` * diff --git a/framework/grid/SerialColumn.php b/framework/grid/SerialColumn.php index 78155b2..ca9ca7d 100644 --- a/framework/grid/SerialColumn.php +++ b/framework/grid/SerialColumn.php @@ -16,7 +16,7 @@ namespace yii\grid; * 'columns' => [ * // ... * [ - * 'class' => 'yii\grid\SerialColumn', + * 'class' => \yii\grid\SerialColumn::class, * // you may configure additional properties here * ], * ] diff --git a/framework/helpers/BaseMarkdown.php b/framework/helpers/BaseMarkdown.php index 07ed299..4409b75 100644 --- a/framework/helpers/BaseMarkdown.php +++ b/framework/helpers/BaseMarkdown.php @@ -25,20 +25,20 @@ class BaseMarkdown */ public static $flavors = [ 'original' => [ - 'class' => 'cebe\markdown\Markdown', + 'class' => \cebe\markdown\Markdown::class, 'html5' => true, ], 'gfm' => [ - 'class' => 'cebe\markdown\GithubMarkdown', + 'class' => \cebe\markdown\GithubMarkdown::class, 'html5' => true, ], 'gfm-comment' => [ - 'class' => 'cebe\markdown\GithubMarkdown', + 'class' => \cebe\markdown\GithubMarkdown::class, 'html5' => true, 'enableNewlines' => true, ], 'extra' => [ - 'class' => 'cebe\markdown\MarkdownExtra', + 'class' => \cebe\markdown\MarkdownExtra::class, 'html5' => true, ], ]; diff --git a/framework/i18n/I18N.php b/framework/i18n/I18N.php index 9ae858c..6b916e3 100644 --- a/framework/i18n/I18N.php +++ b/framework/i18n/I18N.php @@ -57,14 +57,14 @@ class I18N extends Component parent::init(); if (!isset($this->translations['yii']) && !isset($this->translations['yii*'])) { $this->translations['yii'] = [ - 'class' => 'yii\i18n\PhpMessageSource', + 'class' => PhpMessageSource::class, 'sourceLanguage' => 'en-US', 'basePath' => '@yii/messages', ]; } if (!isset($this->translations['app']) && !isset($this->translations['app*'])) { $this->translations['app'] = [ - 'class' => 'yii\i18n\PhpMessageSource', + 'class' => PhpMessageSource::class, 'sourceLanguage' => Yii::$app->sourceLanguage, 'basePath' => '@app/messages', ]; diff --git a/framework/log/Dispatcher.php b/framework/log/Dispatcher.php index 3caf8f5..58e422b 100644 --- a/framework/log/Dispatcher.php +++ b/framework/log/Dispatcher.php @@ -27,12 +27,12 @@ use yii\base\ErrorHandler; * 'log' => [ * 'targets' => [ * 'file' => [ - * 'class' => 'yii\log\FileTarget', + * 'class' => \yii\log\FileTarget::class, * 'levels' => ['trace', 'info'], * 'categories' => ['yii\*'], * ], * 'email' => [ - * 'class' => 'yii\log\EmailTarget', + * 'class' => \yii\log\EmailTarget::class, * 'levels' => ['error', 'warning'], * 'message' => [ * 'to' => 'admin@example.com', diff --git a/framework/log/EmailTarget.php b/framework/log/EmailTarget.php index 659c645..f432dc0 100644 --- a/framework/log/EmailTarget.php +++ b/framework/log/EmailTarget.php @@ -23,7 +23,7 @@ use yii\mail\MailerInterface; * 'log' => [ * 'targets' => [ * [ - * 'class' => 'yii\log\EmailTarget', + * 'class' => \yii\log\EmailTarget::class, * 'mailer' => 'mailer', * 'levels' => ['error', 'warning'], * 'message' => [ @@ -67,7 +67,7 @@ class EmailTarget extends Target if (empty($this->message['to'])) { throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.'); } - $this->mailer = Instance::ensure($this->mailer, 'yii\mail\MailerInterface'); + $this->mailer = Instance::ensure($this->mailer, MailerInterface::class); } /** diff --git a/framework/mutex/MysqlMutex.php b/framework/mutex/MysqlMutex.php index e47a71b..9a2e47e 100644 --- a/framework/mutex/MysqlMutex.php +++ b/framework/mutex/MysqlMutex.php @@ -19,11 +19,11 @@ use yii\base\InvalidConfigException; * [ * 'components' => [ * 'db' => [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * ] * 'mutex' => [ - * 'class' => 'yii\mutex\MysqlMutex', + * 'class' => \yii\mutex\MysqlMutex::class, * ], * ], * ] diff --git a/framework/mutex/PgsqlMutex.php b/framework/mutex/PgsqlMutex.php index aa0d9be..88bc512 100644 --- a/framework/mutex/PgsqlMutex.php +++ b/framework/mutex/PgsqlMutex.php @@ -20,11 +20,11 @@ use yii\base\InvalidParamException; * [ * 'components' => [ * 'db' => [ - * 'class' => 'yii\db\Connection', + * 'class' => \yii\db\Connection::class, * 'dsn' => 'pgsql:host=127.0.0.1;dbname=demo', * ] * 'mutex' => [ - * 'class' => 'yii\mutex\PgsqlMutex', + * 'class' => \yii\mutex\PgsqlMutex::class, * ], * ], * ] diff --git a/framework/rest/ActiveController.php b/framework/rest/ActiveController.php index bdef9ea..800923e 100644 --- a/framework/rest/ActiveController.php +++ b/framework/rest/ActiveController.php @@ -71,34 +71,34 @@ class ActiveController extends Controller { return [ 'index' => [ - 'class' => 'yii\rest\IndexAction', + 'class' => IndexAction::class, 'modelClass' => $this->modelClass, 'checkAccess' => [$this, 'checkAccess'], ], 'view' => [ - 'class' => 'yii\rest\ViewAction', + 'class' => ViewAction::class, 'modelClass' => $this->modelClass, 'checkAccess' => [$this, 'checkAccess'], ], 'create' => [ - 'class' => 'yii\rest\CreateAction', + 'class' => CreateAction::class, 'modelClass' => $this->modelClass, 'checkAccess' => [$this, 'checkAccess'], 'scenario' => $this->createScenario, ], 'update' => [ - 'class' => 'yii\rest\UpdateAction', + 'class' => UpdateAction::class, 'modelClass' => $this->modelClass, 'checkAccess' => [$this, 'checkAccess'], 'scenario' => $this->updateScenario, ], 'delete' => [ - 'class' => 'yii\rest\DeleteAction', + 'class' => DeleteAction::class, 'modelClass' => $this->modelClass, 'checkAccess' => [$this, 'checkAccess'], ], 'options' => [ - 'class' => 'yii\rest\OptionsAction', + 'class' => OptionsAction::class, ], ]; } diff --git a/framework/rest/UrlRule.php b/framework/rest/UrlRule.php index 83b3783..b4dcf54 100644 --- a/framework/rest/UrlRule.php +++ b/framework/rest/UrlRule.php @@ -19,7 +19,7 @@ use yii\web\CompositeUrlRule; * * ```php * [ - * 'class' => 'yii\rest\UrlRule', + * 'class' => \yii\rest\UrlRule::class, * 'controller' => 'user', * ] * ``` @@ -41,7 +41,7 @@ use yii\web\CompositeUrlRule; * * ```php * [ - * 'class' => 'yii\rest\UrlRule', + * 'class' => \yii\rest\UrlRule::class, * 'controller' => ['user', 'post'], * 'except' => ['delete'], * ] @@ -125,7 +125,7 @@ class UrlRule extends CompositeUrlRule * @var array the default configuration for creating each URL rule contained by this rule. */ public $ruleConfig = [ - 'class' => 'yii\web\UrlRule', + 'class' => \yii\web\UrlRule::class, ]; /** * @var boolean whether to automatically pluralize the URL names for controllers. diff --git a/framework/validators/UniqueValidator.php b/framework/validators/UniqueValidator.php index 576b1fe..545496a 100644 --- a/framework/validators/UniqueValidator.php +++ b/framework/validators/UniqueValidator.php @@ -38,7 +38,11 @@ class UniqueValidator extends Validator { /** * @var string the name of the ActiveRecord class that should be used to validate the uniqueness - * of the current attribute value. If not set, it will use the ActiveRecord class of the attribute being validated. + * of the current attribute value. + * This must be a fully qualified class name. + * + * If not set, it will use the ActiveRecord class of the attribute being validated. + * * @see targetAttribute */ public $targetClass; @@ -106,7 +110,7 @@ class UniqueValidator extends Validator $query->andWhere($this->filter); } - if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || get_class($model) !== $targetClass::class) { + if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || get_class($model) !== $targetClass) { // 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/validators/Validator.php b/framework/validators/Validator.php index 34bd088..5fbbf3d 100644 --- a/framework/validators/Validator.php +++ b/framework/validators/Validator.php @@ -67,7 +67,7 @@ class Validator extends Component 'image' => 'yii\validators\ImageValidator', 'in' => 'yii\validators\RangeValidator', 'integer' => [ - 'class' => 'yii\validators\NumberValidator', + 'class' => NumberValidator::class, 'integerOnly' => true, ], 'match' => 'yii\validators\RegularExpressionValidator', @@ -76,7 +76,7 @@ class Validator extends Component 'safe' => 'yii\validators\SafeValidator', 'string' => 'yii\validators\StringValidator', 'trim' => [ - 'class' => 'yii\validators\FilterValidator', + 'class' => FilterValidator::class, 'filter' => 'trim', 'skipOnArray' => true, ], diff --git a/framework/web/CacheSession.php b/framework/web/CacheSession.php index 6f69c4c..019161e 100644 --- a/framework/web/CacheSession.php +++ b/framework/web/CacheSession.php @@ -26,7 +26,7 @@ use yii\di\Instance; * * ```php * 'session' => [ - * 'class' => 'yii\web\CacheSession', + * 'class' => \yii\web\CacheSession::class, * // 'cache' => 'mycache', * ] * ``` diff --git a/framework/web/DbSession.php b/framework/web/DbSession.php index 4ba3a9a..9bd1139 100644 --- a/framework/web/DbSession.php +++ b/framework/web/DbSession.php @@ -24,7 +24,7 @@ use yii\di\Instance; * * ```php * 'session' => [ - * 'class' => 'yii\web\DbSession', + * 'class' => \yii\web\DbSession::class, * // 'db' => 'mydb', * // 'sessionTable' => 'my_session', * ] diff --git a/framework/web/JsonResponseFormatter.php b/framework/web/JsonResponseFormatter.php index 13fb993..8780f0a 100644 --- a/framework/web/JsonResponseFormatter.php +++ b/framework/web/JsonResponseFormatter.php @@ -24,7 +24,7 @@ use yii\helpers\Json; * // ... * 'formatters' => [ * \yii\web\Response::FORMAT_JSON => [ - * 'class' => 'yii\web\JsonResponseFormatter', + * 'class' => \yii\web\JsonResponseFormatter::class, * 'prettyPrint' => YII_DEBUG, // use "pretty" output in debug mode * // ... * ], diff --git a/framework/web/Response.php b/framework/web/Response.php index 63f842f..cb8aff0 100644 --- a/framework/web/Response.php +++ b/framework/web/Response.php @@ -917,11 +917,11 @@ class Response extends \yii\base\Response protected function defaultFormatters() { return [ - self::FORMAT_HTML => 'yii\web\HtmlResponseFormatter', - self::FORMAT_XML => 'yii\web\XmlResponseFormatter', - self::FORMAT_JSON => 'yii\web\JsonResponseFormatter', + self::FORMAT_HTML => HtmlResponseFormatter::class, + self::FORMAT_XML => XmlResponseFormatter::class, + self::FORMAT_JSON => JsonResponseFormatter::class, self::FORMAT_JSONP => [ - 'class' => 'yii\web\JsonResponseFormatter', + 'class' => JsonResponseFormatter::class, 'useJsonp' => true, ], ]; diff --git a/framework/web/UrlRule.php b/framework/web/UrlRule.php index 73aabce..41b82ac 100644 --- a/framework/web/UrlRule.php +++ b/framework/web/UrlRule.php @@ -19,7 +19,7 @@ use yii\base\InvalidConfigException; * * ```php * 'rules' => [ - * ['class' => 'MyUrlRule', 'pattern' => '...', 'route' => 'site/index', ...], + * ['class' => MyUrlRule::class, 'pattern' => '...', 'route' => 'site/index', ...], * // ... * ] * ``` diff --git a/framework/widgets/FragmentCache.php b/framework/widgets/FragmentCache.php index 5818fe9..1d007e7 100644 --- a/framework/widgets/FragmentCache.php +++ b/framework/widgets/FragmentCache.php @@ -43,7 +43,7 @@ class FragmentCache extends Widget * * ```php * [ - * 'class' => 'yii\caching\DbDependency', + * 'class' => \yii\caching\DbDependency::class, * 'sql' => 'SELECT MAX(updated_at) FROM post', * ] * ```