diff --git a/apps/advanced/backend/controllers/SiteController.php b/apps/advanced/backend/controllers/SiteController.php index 2999218ab3..db3259a752 100644 --- a/apps/advanced/backend/controllers/SiteController.php +++ b/apps/advanced/backend/controllers/SiteController.php @@ -2,10 +2,10 @@ namespace backend\controllers; use Yii; -use yii\web\AccessControl; +use yii\filters\AccessControl; use yii\web\Controller; use common\models\LoginForm; -use yii\web\VerbFilter; +use yii\filters\VerbFilter; /** * Site controller diff --git a/apps/advanced/frontend/controllers/SiteController.php b/apps/advanced/frontend/controllers/SiteController.php index 5f58b584a2..1aae6fc37b 100644 --- a/apps/advanced/frontend/controllers/SiteController.php +++ b/apps/advanced/frontend/controllers/SiteController.php @@ -1,6 +1,7 @@ [ - 'class' => \yii\web\AccessControl::className(), + 'class' => AccessControl::className(), 'only' => ['logout', 'signup'], 'rules' => [ [ diff --git a/apps/basic/controllers/SiteController.php b/apps/basic/controllers/SiteController.php index ebecd28e60..f95994160e 100644 --- a/apps/basic/controllers/SiteController.php +++ b/apps/basic/controllers/SiteController.php @@ -3,9 +3,9 @@ namespace app\controllers; use Yii; -use yii\web\AccessControl; +use yii\filters\AccessControl; use yii\web\Controller; -use yii\web\VerbFilter; +use yii\filters\VerbFilter; use app\models\LoginForm; use app\models\ContactForm; diff --git a/docs/guide/authorization.md b/docs/guide/authorization.md index 982ded0e78..91c943c771 100644 --- a/docs/guide/authorization.md +++ b/docs/guide/authorization.md @@ -7,7 +7,7 @@ of controlling it. Access control basics --------------------- -Basic access control is very simple to implement using [[yii\web\AccessControl]]: +Basic access control is very simple to implement using [[yii\filters\AccessControl]]: ```php class SiteController extends Controller @@ -16,7 +16,7 @@ class SiteController extends Controller { return [ 'access' => [ - 'class' => \yii\web\AccessControl::className(), + 'class' => \yii\filters\AccessControl::className(), 'only' => ['login', 'logout', 'signup'], 'rules' => [ [ @@ -38,7 +38,7 @@ class SiteController extends Controller In the code above we're attaching access control behavior to a controller. Since there's `only` option specified, it will be applied to 'login', 'logout' and 'signup' actions only. A set of rules that are basically options for -[[yii\web\AccessRule]] reads as follows: +[[yii\filters\AccessRule]] reads as follows: - Allow all guest (not yet authenticated) users to access 'login' and 'signup' actions. - Allow authenticated users to access 'logout' action. @@ -46,7 +46,7 @@ will be applied to 'login', 'logout' and 'signup' actions only. A set of rules t Rules are checked one by one from top to bottom. If rule matches, action takes place immediately. If not, next rule is checked. If no rules matched access is denied. -[[yii\web\AccessRule]] is quite flexible and allows additionally to what was demonstrated checking IPs and request method +[[yii\filters\AccessRule]] is quite flexible and allows additionally to what was demonstrated checking IPs and request method (i.e. POST, GET). If it's not enough you can specify your own check via anonymous function: ```php @@ -56,7 +56,7 @@ class SiteController extends Controller { return [ 'access' => [ - 'class' => \yii\web\AccessControl::className(), + 'class' => \yii\filters\AccessControl::className(), 'only' => ['special-callback'], 'rules' => [ [ @@ -219,7 +219,7 @@ public function behaviors() { return [ 'access' => [ - 'class' => 'yii\web\AccessControl', + 'class' => 'yii\filters\AccessControl', 'except' => ['something'], 'rules' => [ [ diff --git a/docs/guide/controller.md b/docs/guide/controller.md index 634e936962..12ac39d193 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -199,7 +199,7 @@ public function behaviors() { return [ 'httpCache' => [ - 'class' => \yii\web\HttpCache::className(), + 'class' => \yii\filters\HttpCache::className(), 'only' => ['index'], 'lastModified' => function ($action, $params) { $q = new \yii\db\Query(); @@ -225,8 +225,8 @@ The return value of [[yii\base\ActionFilter::beforeAction()|beforeAction()]] det an action should be executed or not. If `beforeAction()` of a filter returns false, the filters after this one will be skipped and the action will not be executed. -The [authorization](authorization.md) section of this guide shows how to use the [[yii\web\AccessControl]] filter, -and the [caching](caching.md) section gives more details about the [[yii\web\PageCache]] and [[yii\web\HttpCache]] filters. +The [authorization](authorization.md) section of this guide shows how to use the [[yii\filters\AccessControl]] filter, +and the [caching](caching.md) section gives more details about the [[yii\filters\PageCache]] and [[yii\filters\HttpCache]] filters. These built-in filters are also good references when you learn to create your own filters. diff --git a/docs/guide/performance.md b/docs/guide/performance.md index c659a8550e..04c60d5ebb 100644 --- a/docs/guide/performance.md +++ b/docs/guide/performance.md @@ -137,7 +137,7 @@ sending either `ETag` or `Last-Modified` header in your application response. If HTTP specification (most browsers are), content will be fetched only if it is different from what it was prevously. Forming proper headers is time consuming task so Yii provides a shortcut in form of controller filter -[[yii\web\HttpCache]]. Using it is very easy. In a controller you need to implement `behaviors` method like +[[yii\filters\HttpCache]]. Using it is very easy. In a controller you need to implement `behaviors` method like the following: ```php @@ -145,7 +145,7 @@ public function behaviors() { return [ 'httpCache' => [ - 'class' => \yii\web\HttpCache::className(), + 'class' => \yii\filters\HttpCache::className(), 'only' => ['list'], 'lastModified' => function ($action, $params) { $q = new Query(); diff --git a/docs/guide/rest.md b/docs/guide/rest.md index 6b434482b0..efc1005b10 100644 --- a/docs/guide/rest.md +++ b/docs/guide/rest.md @@ -13,7 +13,7 @@ In particular, Yii provides support for the following aspects regarding RESTful * Authentication; * Authorization; * Support for HATEOAS; -* Caching via `yii\web\HttpCache`; +* Caching via `yii\filters\HttpCache`; * Rate limiting; * Searching and filtering: TBD * Testing: TBD @@ -783,7 +783,7 @@ Accept: application/vnd.company.myapp-v1+json ``` Both methods have pros and cons, and there are a lot of debates about them. Below we describe a practical strategy -of API versioning that is a kind of mix of these two methods: +of API versioning that is kind of a mix of these two methods: * Put each major version of API implementation in a separate module whose ID is the major version number (e.g. `v1`, `v2`). Naturally, the API URLs will contain major version numbers. @@ -793,7 +793,9 @@ of API versioning that is a kind of mix of these two methods: For each module serving a major version, it should include the resource classes and the controller classes serving for that specific version. To better separate code responsibility, you may keep a common set of base resource and controller classes, and subclass them in each individual version module. Within the subclasses, -implement the concrete code such as `Model::fields()`. As a result, your code may be organized like the following: +implement the concrete code such as `Model::fields()`. + +Your code may be organized like the following: ``` api/ diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index 56bc699d09..ceba3b050c 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -318,7 +318,7 @@ Action Filters Action filters are implemented via behaviors now. You should extend from [[yii\base\ActionFilter]] to define a new filter. To use a filter, you should attach the filter class to the controller -as a behavior. For example, to use the [[yii\web\AccessControl]] filter, you should have the following +as a behavior. For example, to use the [[yii\filters\AccessControl]] filter, you should have the following code in a controller: ```php @@ -326,7 +326,7 @@ public function behaviors() { return [ 'access' => [ - 'class' => 'yii\web\AccessControl', + 'class' => 'yii\filters\AccessControl', 'rules' => [ ['allow' => true, 'actions' => ['admin'], 'roles' => ['@']], ], diff --git a/docs/guide/url.md b/docs/guide/url.md index f0c8b9d70f..40817caf5e 100644 --- a/docs/guide/url.md +++ b/docs/guide/url.md @@ -232,7 +232,7 @@ return [ ### Handling REST requests TBD: -- RESTful routing: [[yii\web\VerbFilter]], [[yii\web\UrlManager::$rules]] +- RESTful routing: [[yii\filters\VerbFilter]], [[yii\filters\UrlManager::$rules]] - Json API: - response: [[yii\web\Response::format]] - request: [[yii\web\Request::$parsers]], [[yii\web\JsonParser]] diff --git a/extensions/gii/generators/crud/default/controller.php b/extensions/gii/generators/crud/default/controller.php index 0ad80c96e1..0a00eb49b6 100644 --- a/extensions/gii/generators/crud/default/controller.php +++ b/extensions/gii/generators/crud/default/controller.php @@ -34,7 +34,7 @@ use modelClass, '\\') ?>; use searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>; use baseControllerClass, '\\') ?>; use yii\web\NotFoundHttpException; -use yii\web\VerbFilter; +use yii\filters\VerbFilter; /** * implements the CRUD actions for model. diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 9048645c05..536ada9e7b 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -274,6 +274,7 @@ Yii Framework 2 Change Log - Chg: `Yii::$objectConfig` is removed. You should use `Yii::$container->set()` to configure default settings of classes. (qiangxue) - Chg: Removed `yii\grid\Column::getDataCellContent()` and renamed `yii\grid\DataColumn::getDataCellContent()` to `yii\grid\DataColumn::getDataCellValue()` (cebe) - Chg: `yii\log\Logger` is split into `yii\log\Logger` and `yii\log\Dispatcher`. (qiangxue) +- Chg: Moved all filter classes to namespace `yii\filters` (qiangxue) - New #66: [Auth client library](https://github.com/yiisoft/yii2-authclient) OpenId, OAuth1, OAuth2 clients (klimov-paul) - New #303: Added built-in support for REST API (qiangxue) - New #503: Added `yii\di\Container` and `yii\di\ServiceLocator` (qiangxue) diff --git a/framework/base/ActionFilter.php b/framework/base/ActionFilter.php index 72fed31a1e..060bfaf56a 100644 --- a/framework/base/ActionFilter.php +++ b/framework/base/ActionFilter.php @@ -13,7 +13,7 @@ namespace yii\base; * An action filter will participate in the action execution workflow by responding to * the `beforeAction` and `afterAction` events triggered by modules and controllers. * - * Check implementation of [[\yii\web\AccessControl]], [[\yii\web\PageCache]] and [[\yii\web\HttpCache]] as examples on how to use it. + * Check implementation of [[\yii\filters\AccessControl]], [[\yii\filters\PageCache]] and [[\yii\filters\HttpCache]] as examples on how to use it. * * @author Qiang Xue * @since 2.0 diff --git a/framework/classes.php b/framework/classes.php index 0cd806d51d..68a61bb238 100644 --- a/framework/classes.php +++ b/framework/classes.php @@ -227,8 +227,8 @@ return [ 'yii\validators\UrlValidator' => YII_PATH . '/validators/UrlValidator.php', 'yii\validators\ValidationAsset' => YII_PATH . '/validators/ValidationAsset.php', 'yii\validators\Validator' => YII_PATH . '/validators/Validator.php', - 'yii\web\AccessControl' => YII_PATH . '/web/AccessControl.php', - 'yii\web\AccessRule' => YII_PATH . '/web/AccessRule.php', + 'yii\filters\AccessControl' => YII_PATH . '/filters/AccessControl.php', + 'yii\filters\AccessRule' => YII_PATH . '/filters/AccessRule.php', 'yii\web\Application' => YII_PATH . '/web/Application.php', 'yii\web\AssetBundle' => YII_PATH . '/web/AssetBundle.php', 'yii\web\AssetConverter' => YII_PATH . '/web/AssetConverter.php', @@ -246,7 +246,7 @@ return [ 'yii\web\ForbiddenHttpException' => YII_PATH . '/web/ForbiddenHttpException.php', 'yii\web\GoneHttpException' => YII_PATH . '/web/GoneHttpException.php', 'yii\web\HeaderCollection' => YII_PATH . '/web/HeaderCollection.php', - 'yii\web\HttpCache' => YII_PATH . '/web/HttpCache.php', + 'yii\filters\HttpCache' => YII_PATH . '/filters/HttpCache.php', 'yii\web\HttpException' => YII_PATH . '/web/HttpException.php', 'yii\web\IdentityInterface' => YII_PATH . '/web/IdentityInterface.php', 'yii\web\JqueryAsset' => YII_PATH . '/web/JqueryAsset.php', @@ -257,7 +257,7 @@ return [ 'yii\web\MethodNotAllowedHttpException' => YII_PATH . '/web/MethodNotAllowedHttpException.php', 'yii\web\NotAcceptableHttpException' => YII_PATH . '/web/NotAcceptableHttpException.php', 'yii\web\NotFoundHttpException' => YII_PATH . '/web/NotFoundHttpException.php', - 'yii\web\PageCache' => YII_PATH . '/web/PageCache.php', + 'yii\filters\PageCache' => YII_PATH . '/filters/PageCache.php', 'yii\web\PrefixUrlRule' => YII_PATH . '/web/PrefixUrlRule.php', 'yii\web\Request' => YII_PATH . '/web/Request.php', 'yii\web\RequestParserInterface' => YII_PATH . '/web/RequestParserInterface.php', @@ -274,7 +274,7 @@ return [ 'yii\web\UrlRuleInterface' => YII_PATH . '/web/UrlRuleInterface.php', 'yii\web\User' => YII_PATH . '/web/User.php', 'yii\web\UserEvent' => YII_PATH . '/web/UserEvent.php', - 'yii\web\VerbFilter' => YII_PATH . '/web/VerbFilter.php', + 'yii\filters\VerbFilter' => YII_PATH . '/filters/VerbFilter.php', 'yii\web\View' => YII_PATH . '/web/View.php', 'yii\web\XmlResponseFormatter' => YII_PATH . '/web/XmlResponseFormatter.php', 'yii\web\YiiAsset' => YII_PATH . '/web/YiiAsset.php', diff --git a/framework/web/AccessControl.php b/framework/filters/AccessControl.php similarity index 95% rename from framework/web/AccessControl.php rename to framework/filters/AccessControl.php index da3d63b11f..e75b0125dc 100644 --- a/framework/web/AccessControl.php +++ b/framework/filters/AccessControl.php @@ -5,11 +5,13 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\web; +namespace yii\filters; use Yii; use yii\base\Action; use yii\base\ActionFilter; +use yii\web\User; +use yii\web\ForbiddenHttpException; /** * AccessControl provides simple access control based on a set of rules. @@ -28,7 +30,7 @@ use yii\base\ActionFilter; * { * return [ * 'access' => [ - * 'class' => \yii\web\AccessControl::className(), + * 'class' => \yii\filters\AccessControl::className(), * 'only' => ['create', 'update'], * 'rules' => [ * // deny all POST requests @@ -71,7 +73,7 @@ class AccessControl extends ActionFilter * @var array the default configuration of access rules. Individual rule configurations * specified via [[rules]] will take precedence when the same property of the rule is configured. */ - public $ruleConfig = ['class' => 'yii\web\AccessRule']; + public $ruleConfig = ['class' => 'yii\filters\AccessRule']; /** * @var array a list of access rule objects or configuration arrays for creating the rule objects. * If a rule is specified via a configuration array, it will be merged with [[ruleConfig]] first diff --git a/framework/web/AccessRule.php b/framework/filters/AccessRule.php similarity index 98% rename from framework/web/AccessRule.php rename to framework/filters/AccessRule.php index 50a074acd4..316d396505 100644 --- a/framework/web/AccessRule.php +++ b/framework/filters/AccessRule.php @@ -5,10 +5,13 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\web; +namespace yii\filters; use yii\base\Component; use yii\base\Action; +use yii\web\User; +use yii\web\Request; +use yii\web\Controller; /** * This class represents an access rule defined by the [[AccessControl]] action filter diff --git a/framework/web/HttpCache.php b/framework/filters/HttpCache.php similarity index 98% rename from framework/web/HttpCache.php rename to framework/filters/HttpCache.php index 8e85e7a3bc..5268144799 100644 --- a/framework/web/HttpCache.php +++ b/framework/filters/HttpCache.php @@ -5,7 +5,7 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\web; +namespace yii\filters; use Yii; use yii\base\ActionFilter; @@ -25,7 +25,7 @@ use yii\base\Action; * { * return [ * 'httpCache' => [ - * 'class' => \yii\web\HttpCache::className(), + * 'class' => \yii\filters\HttpCache::className(), * 'only' => ['index'], * 'lastModified' => function ($action, $params) { * $q = new \yii\db\Query(); diff --git a/framework/web/PageCache.php b/framework/filters/PageCache.php similarity index 98% rename from framework/web/PageCache.php rename to framework/filters/PageCache.php index 633b4034fd..039fc89902 100644 --- a/framework/web/PageCache.php +++ b/framework/filters/PageCache.php @@ -5,7 +5,7 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\web; +namespace yii\filters; use Yii; use yii\base\ActionFilter; @@ -28,7 +28,7 @@ use yii\caching\Dependency; * { * return [ * 'pageCache' => [ - * 'class' => \yii\web\PageCache::className(), + * 'class' => \yii\filters\PageCache::className(), * 'only' => ['list'], * 'duration' => 60, * 'dependency' => [ diff --git a/framework/web/VerbFilter.php b/framework/filters/VerbFilter.php similarity index 94% rename from framework/web/VerbFilter.php rename to framework/filters/VerbFilter.php index 06e13ba010..d2f3a65878 100644 --- a/framework/web/VerbFilter.php +++ b/framework/filters/VerbFilter.php @@ -5,11 +5,14 @@ * @license http://www.yiiframework.com/license/ */ -namespace yii\web; +namespace yii\filters; use Yii; use yii\base\ActionEvent; use yii\base\Behavior; +use yii\web\Controller; +use yii\web\HttpException; +use yii\web\MethodNotAllowedHttpException; /** * VerbFilter is an action filter that filters by HTTP request methods. @@ -26,7 +29,7 @@ use yii\base\Behavior; * { * return [ * 'verbs' => [ - * 'class' => \yii\web\VerbFilter::className(), + * 'class' => \yii\filters\VerbFilter::className(), * 'actions' => [ * 'index' => ['get'], * 'view' => ['get'], diff --git a/framework/rest/Controller.php b/framework/rest/Controller.php index 12c5ff2a89..8cdd1d689d 100644 --- a/framework/rest/Controller.php +++ b/framework/rest/Controller.php @@ -13,7 +13,7 @@ use yii\web\Response; use yii\web\UnauthorizedHttpException; use yii\web\UnsupportedMediaTypeHttpException; use yii\web\TooManyRequestsHttpException; -use yii\web\VerbFilter; +use yii\filters\VerbFilter; use yii\web\ForbiddenHttpException; /**