Browse Source

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
tags/3.0.0-alpha1
Carsten Brandt 9 years ago
parent
commit
b503dc9ff2
  1. 2
      composer.json
  2. 2
      framework/BaseYii.php
  3. 4
      framework/base/Component.php
  4. 4
      framework/base/Controller.php
  5. 8
      framework/base/Module.php
  6. 2
      framework/caching/DbCache.php
  7. 2
      framework/caching/MemCache.php
  8. 2
      framework/composer.json
  9. 2
      framework/console/controllers/AssetController.php
  10. 2
      framework/db/Connection.php
  11. 18
      framework/di/Container.php
  12. 6
      framework/di/Instance.php
  13. 12
      framework/di/ServiceLocator.php
  14. 4
      framework/filters/ContentNegotiator.php
  15. 2
      framework/filters/HttpCache.php
  16. 6
      framework/filters/PageCache.php
  17. 4
      framework/grid/ActionColumn.php
  18. 2
      framework/grid/CheckboxColumn.php
  19. 6
      framework/grid/GridView.php
  20. 2
      framework/grid/SerialColumn.php
  21. 8
      framework/helpers/BaseMarkdown.php
  22. 4
      framework/i18n/I18N.php
  23. 4
      framework/log/Dispatcher.php
  24. 4
      framework/log/EmailTarget.php
  25. 4
      framework/mutex/MysqlMutex.php
  26. 4
      framework/mutex/PgsqlMutex.php
  27. 12
      framework/rest/ActiveController.php
  28. 6
      framework/rest/UrlRule.php
  29. 8
      framework/validators/UniqueValidator.php
  30. 4
      framework/validators/Validator.php
  31. 2
      framework/web/CacheSession.php
  32. 2
      framework/web/DbSession.php
  33. 2
      framework/web/JsonResponseFormatter.php
  34. 8
      framework/web/Response.php
  35. 2
      framework/web/UrlRule.php
  36. 2
      framework/widgets/FragmentCache.php

2
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": "*",

2
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' => '',

4
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',
* ]

4
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',
* ],

8
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],
* ]
* ```
*

2
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',
* ]

2
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',

2
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": "*",

2
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',

2
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' => '',

18
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' => '',

6
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);
* }
* }
* ```

12
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',
* ],
* ]

4
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']

2
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();

6
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',
* ]
* ```

4
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

2
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
* ],
* ]

6
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],
* ]
* ```
*

2
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
* ],
* ]

8
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,
],
];

4
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',
];

4
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',

4
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);
}
/**

4
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,
* ],
* ],
* ]

4
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,
* ],
* ],
* ]

12
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,
],
];
}

6
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.

8
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();

4
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,
],

2
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',
* ]
* ```

2
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',
* ]

2
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
* // ...
* ],

8
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,
],
];

2
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', ...],
* // ...
* ]
* ```

2
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',
* ]
* ```

Loading…
Cancel
Save