From 31bff3eae5b3b6f19a9ca4f14edb0939efcecb84 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:48:36 -0800 Subject: [PATCH 01/13] Renames AccessDeniedHttpException to ForbiddenHttpException as in #2103 --- framework/web/ForbiddenHttpException.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/ForbiddenHttpException.php diff --git a/framework/web/ForbiddenHttpException.php b/framework/web/ForbiddenHttpException.php new file mode 100644 index 0000000000..c3ebf7e9d1 --- /dev/null +++ b/framework/web/ForbiddenHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class ForbiddenHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(403, $message, $code, $previous); + } +} From cbe8b2777986dd321400424166478e4dd111f532 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:49:15 -0800 Subject: [PATCH 02/13] Deletes AccessDeniedHttpException --- framework/web/AccessDeniedHttpException.php | 28 --------------------- 1 file changed, 28 deletions(-) delete mode 100644 framework/web/AccessDeniedHttpException.php diff --git a/framework/web/AccessDeniedHttpException.php b/framework/web/AccessDeniedHttpException.php deleted file mode 100644 index d83700bac4..0000000000 --- a/framework/web/AccessDeniedHttpException.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @since 2.0 - */ -class AccessDeniedHttpException extends HttpException -{ - /** - * Constructor. - * @param string $message error message - * @param integer $code error code - * @param \Exception $previous The previous exception used for the exception chaining. - */ - public function __construct($message = null, $code = 0, \Exception $previous = null) - { - parent::__construct(403, $message, $code, $previous); - } -} From 04743b20a2020d733875c9c8da2e4c35d1c570d4 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:52:16 -0800 Subject: [PATCH 03/13] Adds UnauthorizedHttpException class for 401 errors --- framework/web/ForbiddenHttpException.php | 2 +- framework/web/UnauthorizedHttpException.php | 28 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 framework/web/UnauthorizedHttpException.php diff --git a/framework/web/ForbiddenHttpException.php b/framework/web/ForbiddenHttpException.php index c3ebf7e9d1..c05511e8b9 100644 --- a/framework/web/ForbiddenHttpException.php +++ b/framework/web/ForbiddenHttpException.php @@ -10,7 +10,7 @@ namespace yii\web; /** * ForbiddenHttpException represents a "Forbidden" HTTP exception with status code 403. * - * @author Qiang Xue + * @author Dan Schmidt * @since 2.0 */ class ForbiddenHttpException extends HttpException diff --git a/framework/web/UnauthorizedHttpException.php b/framework/web/UnauthorizedHttpException.php new file mode 100644 index 0000000000..50d86dca9b --- /dev/null +++ b/framework/web/UnauthorizedHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class UnauthorizedHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(401, $message, $code, $previous); + } +} From c5252f9284b61f0180dfe4ed6e8aca1c41ba6783 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:54:23 -0800 Subject: [PATCH 04/13] Adds GoneHttpException for 410 http errors --- framework/web/GoneHttpException.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/GoneHttpException.php diff --git a/framework/web/GoneHttpException.php b/framework/web/GoneHttpException.php new file mode 100644 index 0000000000..559374a4db --- /dev/null +++ b/framework/web/GoneHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class GoneHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(410, $message, $code, $previous); + } +} From 8d9c9a34820bbafa9bd773a77ce470c7e644a1f8 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:55:52 -0800 Subject: [PATCH 05/13] Adds NotAcceptableHttpException for 406 Http errors --- framework/web/NotAcceptableHttpException.php | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/NotAcceptableHttpException.php diff --git a/framework/web/NotAcceptableHttpException.php b/framework/web/NotAcceptableHttpException.php new file mode 100644 index 0000000000..4da942b9d1 --- /dev/null +++ b/framework/web/NotAcceptableHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class NotAcceptableHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(406, $message, $code, $previous); + } +} From 87a2b1d6b94049c9841fdaa4bbef7fbf157fd1d3 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:56:50 -0800 Subject: [PATCH 06/13] Adds ConflictHttpException for 409 http errors --- framework/web/ConflictHttpException.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/ConflictHttpException.php diff --git a/framework/web/ConflictHttpException.php b/framework/web/ConflictHttpException.php new file mode 100644 index 0000000000..49e551910a --- /dev/null +++ b/framework/web/ConflictHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class ConflictHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(409, $message, $code, $previous); + } +} From 81f3ce12abfa1e353c7e3cebc73f924a1ac4124c Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:57:31 -0800 Subject: [PATCH 07/13] Adds TooManyRequestsHttpException for 429 http errors --- .../web/TooManyRequestsHttpException.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/TooManyRequestsHttpException.php diff --git a/framework/web/TooManyRequestsHttpException.php b/framework/web/TooManyRequestsHttpException.php new file mode 100644 index 0000000000..cdf9c097fd --- /dev/null +++ b/framework/web/TooManyRequestsHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class TooManyRequestsHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(429, $message, $code, $previous); + } +} From 20e031c8aca95f64bd12850020c5da411b9aca02 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 16:58:29 -0800 Subject: [PATCH 08/13] Adds UnsupportedMediaTypeHttpException for 415 Http errors --- .../web/UnsupportedMediaTypeHttpException.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/web/UnsupportedMediaTypeHttpException.php diff --git a/framework/web/UnsupportedMediaTypeHttpException.php b/framework/web/UnsupportedMediaTypeHttpException.php new file mode 100644 index 0000000000..5038be2a7c --- /dev/null +++ b/framework/web/UnsupportedMediaTypeHttpException.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class UnsupportedMediaTypeHttpException extends HttpException +{ + /** + * Constructor. + * @param string $message error message + * @param integer $code error code + * @param \Exception $previous The previous exception used for the exception chaining. + */ + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + parent::__construct(415, $message, $code, $previous); + } +} From f24454a45862fc1f387855b9b5787eedb97b6ae3 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 21 Jan 2014 17:11:28 -0800 Subject: [PATCH 09/13] Renames AccessDeniedHttpException to ForbiddenHttpException in framework, docs, and extension files --- docs/guide/authorization.md | 2 +- extensions/debug/Module.php | 4 ++-- extensions/gii/Module.php | 4 ++-- framework/classes.php | 2 +- framework/web/AccessControl.php | 4 ++-- framework/web/User.php | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/guide/authorization.md b/docs/guide/authorization.md index df40f2fae4..0e65381786 100644 --- a/docs/guide/authorization.md +++ b/docs/guide/authorization.md @@ -248,7 +248,7 @@ public function editArticle($id) throw new NotFoundHttpException; } if (!\Yii::$app->user->checkAccess('edit_article', ['article' => $article])) { - throw new AccessDeniedHttpException; + throw new ForbiddenHttpException; } // ... } diff --git a/extensions/debug/Module.php b/extensions/debug/Module.php index 06f2b76fbf..c1138433ec 100644 --- a/extensions/debug/Module.php +++ b/extensions/debug/Module.php @@ -10,7 +10,7 @@ namespace yii\debug; use Yii; use yii\base\Application; use yii\web\View; -use yii\web\AccessDeniedHttpException; +use yii\web\ForbiddenHttpException; /** * The Yii Debug Module provides the debug toolbar and debugger @@ -80,7 +80,7 @@ class Module extends \yii\base\Module } elseif ($action->id === 'toolbar') { return false; } else { - throw new AccessDeniedHttpException('You are not allowed to access this page.'); + throw new ForbiddenHttpException('You are not allowed to access this page.'); } } diff --git a/extensions/gii/Module.php b/extensions/gii/Module.php index a7bb3ed43f..30302b5ef7 100644 --- a/extensions/gii/Module.php +++ b/extensions/gii/Module.php @@ -8,7 +8,7 @@ namespace yii\gii; use Yii; -use yii\web\AccessDeniedHttpException; +use yii\web\ForbiddenHttpException; /** * This is the main module class for the Gii module. @@ -110,7 +110,7 @@ class Module extends \yii\base\Module if ($this->checkAccess()) { return parent::beforeAction($action); } else { - throw new AccessDeniedHttpException('You are not allowed to access this page.'); + throw new ForbiddenHttpException('You are not allowed to access this page.'); } } diff --git a/framework/classes.php b/framework/classes.php index ea50822b22..38c6987f1c 100644 --- a/framework/classes.php +++ b/framework/classes.php @@ -196,7 +196,7 @@ return [ '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\AccessDeniedHttpException' => YII_PATH . '/web/AccessDeniedHttpException.php', + 'yii\web\ForbiddenHttpException' => YII_PATH . '/web/ForbiddenHttpException.php', 'yii\web\AccessRule' => YII_PATH . '/web/AccessRule.php', 'yii\web\Application' => YII_PATH . '/web/Application.php', 'yii\web\AssetBundle' => YII_PATH . '/web/AssetBundle.php', diff --git a/framework/web/AccessControl.php b/framework/web/AccessControl.php index b2230a7d6d..4499f5ce81 100644 --- a/framework/web/AccessControl.php +++ b/framework/web/AccessControl.php @@ -130,14 +130,14 @@ class AccessControl extends ActionFilter * The default implementation will redirect the user to the login page if he is a guest; * if the user is already logged, a 403 HTTP exception will be thrown. * @param User $user the current user - * @throws AccessDeniedHttpException if the user is already logged in. + * @throws ForbiddenHttpException if the user is already logged in. */ protected function denyAccess($user) { if ($user->getIsGuest()) { $user->loginRequired(); } else { - throw new AccessDeniedHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); + throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } } diff --git a/framework/web/User.php b/framework/web/User.php index d6948b62c6..b6f3568c9f 100644 --- a/framework/web/User.php +++ b/framework/web/User.php @@ -323,7 +323,7 @@ class User extends Component * Note that when [[loginUrl]] is set, calling this method will NOT terminate the application execution. * * @return Response the redirection response if [[loginUrl]] is set - * @throws AccessDeniedHttpException the "Access Denied" HTTP exception if [[loginUrl]] is not set + * @throws ForbiddenHttpException the "Access Denied" HTTP exception if [[loginUrl]] is not set */ public function loginRequired() { @@ -334,7 +334,7 @@ class User extends Component if ($this->loginUrl !== null) { return Yii::$app->getResponse()->redirect($this->loginUrl); } else { - throw new AccessDeniedHttpException(Yii::t('yii', 'Login Required')); + throw new ForbiddenHttpException(Yii::t('yii', 'Login Required')); } } From 7fef8cf0cfd69e9ad8a0bbbe2382bf0e4ebdbae7 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 22 Jan 2014 19:23:39 -0800 Subject: [PATCH 10/13] Adds docblock comments and HTTP spec links for the new HTTP Exception classes (#2103) --- framework/CHANGELOG.md | 9 ++++ framework/collections/Map.php | 53 +++++++++++++++++++ framework/web/BadRequestHttpException.php | 6 +++ framework/web/ConflictHttpException.php | 3 +- framework/web/ForbiddenHttpException.php | 7 +++ framework/web/GoneHttpException.php | 8 ++- framework/web/NotAcceptableHttpException.php | 7 ++- .../web/TooManyRequestsHttpException.php | 7 ++- framework/web/UnauthorizedHttpException.php | 8 ++- .../web/UnsupportedMediaTypeHttpException.php | 8 ++- 10 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 framework/collections/Map.php diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 69362caa0e..e11f5577e5 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,15 @@ Yii Framework 2 Change Log 2.0.0 beta under development ---------------------------- +- Enh #2103: Added docblock description and link to HTTP spec for BadRequestHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for UnauthorizedHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for ForbiddenHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for NotAcceptableHttpException (danschmidt5189) +- Enh #2103: Added link to HTTP spec for ConflictHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for GoneHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for UnsupportedMediaTypeHttpException (danschmidt5189) +- Enh #2103: Added docblock description and link to HTTP spec for TooManyRequestsHttpException (danschmidt5189) +- Enh #2103: Renames AccessDeniedHttpException to ForbiddenHttpException (danschmidt5189) - Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul) - Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue) - Bug #1446: Logging while logs are processed causes infinite loop (qiangxue) diff --git a/framework/collections/Map.php b/framework/collections/Map.php new file mode 100644 index 0000000000..d5ad27003a --- /dev/null +++ b/framework/collections/Map.php @@ -0,0 +1,53 @@ +copyFrom($data); + } + $this->setReadOnly($readOnly); + } + + /** + * @return boolean whether this map is read-only or not. Defaults to false. + */ + public function getReadOnly() + { + return $this->_readOnly; + } + + /** + * @param boolean $value whether this list is read-only or not + */ + public function setReadOnly($value) + { + $this->_readOnly = $value; + } +} diff --git a/framework/web/BadRequestHttpException.php b/framework/web/BadRequestHttpException.php index 3a6cfbb641..6e596dab1a 100644 --- a/framework/web/BadRequestHttpException.php +++ b/framework/web/BadRequestHttpException.php @@ -10,6 +10,12 @@ namespace yii\web; /** * BadRequestHttpException represents a "Bad Request" HTTP exception with status code 400. * + * Use this exception to represent a generic client error. In many cases, there + * may be an HTTP exception that more precisely describes the error. In that + * case, consider using the more precise exception to provide the user with + * additional information. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1 * @author Qiang Xue * @since 2.0 */ diff --git a/framework/web/ConflictHttpException.php b/framework/web/ConflictHttpException.php index 49e551910a..6fa3f57bab 100644 --- a/framework/web/ConflictHttpException.php +++ b/framework/web/ConflictHttpException.php @@ -8,8 +8,9 @@ namespace yii\web; /** - * ConflictHttpException represents a "Conflict" HTTP exception with status code 409. + * ConflictHttpException represents a "Conflict" HTTP exception with status code 409 * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/ForbiddenHttpException.php b/framework/web/ForbiddenHttpException.php index c05511e8b9..e96c225293 100644 --- a/framework/web/ForbiddenHttpException.php +++ b/framework/web/ForbiddenHttpException.php @@ -10,6 +10,13 @@ namespace yii\web; /** * ForbiddenHttpException represents a "Forbidden" HTTP exception with status code 403. * + * Use this exception when a user has been authenticated but is not allowed to + * perform the requested action. If the user is not authenticated, consider + * using a 401 [[UnauthorizedHttpException]]. If you do not want to + * expose authorization information to the user, it is valid to respond with a + * 404 [[NotFoundHttpException]]. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/GoneHttpException.php b/framework/web/GoneHttpException.php index 559374a4db..b78aa01b59 100644 --- a/framework/web/GoneHttpException.php +++ b/framework/web/GoneHttpException.php @@ -8,8 +8,14 @@ namespace yii\web; /** - * GoneHttpException represents a "Gone" HTTP exception with status code 410. + * GoneHttpException represents a "Gone" HTTP exception with status code 410 * + * Throw a GoneHttpException when a user requests a resource that no longer exists + * at the requested url. For example, after a record is deleted, future requests + * for that record should return a 410 GoneHttpException instead of a 404 + * [[NotFoundHttpException]]. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/NotAcceptableHttpException.php b/framework/web/NotAcceptableHttpException.php index 4da942b9d1..5a749c91e8 100644 --- a/framework/web/NotAcceptableHttpException.php +++ b/framework/web/NotAcceptableHttpException.php @@ -8,8 +8,13 @@ namespace yii\web; /** - * NotAcceptableHttpException represents a "Not Acceptable" HTTP exception with status code 406. + * NotAcceptableHttpException represents a "Not Acceptable" HTTP exception with status code 406 * + * Use this exception when the client requests a Content-Type that your + * application cannot return. Note that, according to the HTTP 1.1 specification, + * you are not required to respond with this status code in this situation. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/TooManyRequestsHttpException.php b/framework/web/TooManyRequestsHttpException.php index cdf9c097fd..b5eb8898a5 100644 --- a/framework/web/TooManyRequestsHttpException.php +++ b/framework/web/TooManyRequestsHttpException.php @@ -8,8 +8,13 @@ namespace yii\web; /** - * TooManyRequestsHttpException represents a "Too Many Requests" HTTP exception with status code 429. + * TooManyRequestsHttpException represents a "Too Many Requests" HTTP exception with status code 429 * + * Use this exception to indicate that a client has made too many requests in a + * given period of time. For example, you would throw this exception when + * 'throttling' an API user. + * + * @link http://tools.ietf.org/search/rfc6585#section-4 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/UnauthorizedHttpException.php b/framework/web/UnauthorizedHttpException.php index 50d86dca9b..0bea209046 100644 --- a/framework/web/UnauthorizedHttpException.php +++ b/framework/web/UnauthorizedHttpException.php @@ -8,8 +8,14 @@ namespace yii\web; /** - * UnauthorizedHttpException represents an "Unauthorized" HTTP exception with status code 401. + * UnauthorizedHttpException represents an "Unauthorized" HTTP exception with status code 401 * + * Use this exception to indicate that a client needs to authenticate or login + * to perform the requested action. If the client is already authenticated and + * is simply not allowed to perform the action, consider using a 403 + * [[ForbiddenHttpException]] or 404 [[NotFoundHttpException]] instead. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2 * @author Dan Schmidt * @since 2.0 */ diff --git a/framework/web/UnsupportedMediaTypeHttpException.php b/framework/web/UnsupportedMediaTypeHttpException.php index 5038be2a7c..715117e0ed 100644 --- a/framework/web/UnsupportedMediaTypeHttpException.php +++ b/framework/web/UnsupportedMediaTypeHttpException.php @@ -8,8 +8,14 @@ namespace yii\web; /** - * UnsupportedMediaTypeHttpException represents an "Unsupported Media Type" HTTP exception with status code 415. + * UnsupportedMediaTypeHttpException represents an "Unsupported Media Type" HTTP exception with status code 415 * + * Use this exception when the client sends data in a format that your + * application does not understand. For example, you would throw this exception + * if the client POSTs XML data to an action or controller that only accepts + * JSON. + * + * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16 * @author Dan Schmidt * @since 2.0 */ From 087943cd145d9d6a226ac5bbd2afed8b31780ed7 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 22 Jan 2014 19:26:47 -0800 Subject: [PATCH 11/13] Removes Map file uploaded accidentally --- framework/collections/Map.php | 53 ----------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 framework/collections/Map.php diff --git a/framework/collections/Map.php b/framework/collections/Map.php deleted file mode 100644 index d5ad27003a..0000000000 --- a/framework/collections/Map.php +++ /dev/null @@ -1,53 +0,0 @@ -copyFrom($data); - } - $this->setReadOnly($readOnly); - } - - /** - * @return boolean whether this map is read-only or not. Defaults to false. - */ - public function getReadOnly() - { - return $this->_readOnly; - } - - /** - * @param boolean $value whether this list is read-only or not - */ - public function setReadOnly($value) - { - $this->_readOnly = $value; - } -} From d03b2add89d95c159d8f7d15a0cb490a1f1dd8d2 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 22 Jan 2014 19:32:56 -0800 Subject: [PATCH 12/13] Condenses changelog notes to 1 line (#2103) --- framework/CHANGELOG.md | 9 +- framework/web/BypassPhpCacheSession.php | 118 ++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 framework/web/BypassPhpCacheSession.php diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 973bf11ac2..d05bbf8526 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,14 +4,7 @@ Yii Framework 2 Change Log 2.0.0 beta under development ---------------------------- -- Enh #2103: Added docblock description and link to HTTP spec for BadRequestHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for UnauthorizedHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for ForbiddenHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for NotAcceptableHttpException (danschmidt5189) -- Enh #2103: Added link to HTTP spec for ConflictHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for GoneHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for UnsupportedMediaTypeHttpException (danschmidt5189) -- Enh #2103: Added docblock description and link to HTTP spec for TooManyRequestsHttpException (danschmidt5189) +- Enh #2103: Adds docblock descriptions and links to HTTP specs for new HTTP exception classes (danschmidt5189) - Enh #2103: Renames AccessDeniedHttpException to ForbiddenHttpException (danschmidt5189) - Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul) - Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue) diff --git a/framework/web/BypassPhpCacheSession.php b/framework/web/BypassPhpCacheSession.php new file mode 100644 index 0000000000..7b4a98d407 --- /dev/null +++ b/framework/web/BypassPhpCacheSession.php @@ -0,0 +1,118 @@ + [ + * 'class' => 'yii\web\CacheSession', + * // 'cache' => 'mycache', + * ] + * ~~~ + * + * @property boolean $useCustomStorage Whether to use custom storage. This property is read-only. + * + * @author Qiang Xue + * @since 2.0 + */ +class CacheSession extends Session +{ + /** + * @var Cache|string the cache object or the application component ID of the cache object. + * The session data will be stored using this cache object. + * + * After the CacheSession object is created, if you want to change this property, + * you should only assign it with a cache object. + */ + public $cache = 'cache'; + + /** + * Initializes the application component. + */ + public function init() + { + if (is_string($this->cache)) { + $this->cache = Yii::$app->getComponent($this->cache); + } + if (!$this->cache instanceof Cache) { + throw new InvalidConfigException('CacheSession::cache must refer to the application component ID of a cache object.'); + } + parent::init(); + } + + /** + * Returns a value indicating whether to use custom session storage. + * This method overrides the parent implementation and always returns true. + * @return boolean whether to use custom storage. + */ + public function getUseCustomStorage() + { + return true; + } + + /** + * Session read handler. + * Do not call this method directly. + * @param string $id session ID + * @return string the session data + */ + public function readSession($id) + { + $data = $this->cache->get($this->calculateKey($id)); + return $data === false ? '' : $data; + } + + /** + * Session write handler. + * Do not call this method directly. + * @param string $id session ID + * @param string $data session data + * @return boolean whether session write is successful + */ + public function writeSession($id, $data) + { + return $this->cache->set($this->calculateKey($id), $data, $this->getTimeout()); + } + + /** + * Session destroy handler. + * Do not call this method directly. + * @param string $id session ID + * @return boolean whether session is destroyed successfully + */ + public function destroySession($id) + { + return $this->cache->delete($this->calculateKey($id)); + } + + /** + * Generates a unique key used for storing session data in cache. + * @param string $id session variable name + * @return mixed a safe cache key associated with the session variable name + */ + protected function calculateKey($id) + { + return [__CLASS__, $id]; + } +} From 041f6aac6cd8515f30d07692e519c3b6d3699c44 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 22 Jan 2014 19:33:39 -0800 Subject: [PATCH 13/13] Removed temp class --- framework/web/BypassPhpCacheSession.php | 118 ------------------------ 1 file changed, 118 deletions(-) delete mode 100644 framework/web/BypassPhpCacheSession.php diff --git a/framework/web/BypassPhpCacheSession.php b/framework/web/BypassPhpCacheSession.php deleted file mode 100644 index 7b4a98d407..0000000000 --- a/framework/web/BypassPhpCacheSession.php +++ /dev/null @@ -1,118 +0,0 @@ - [ - * 'class' => 'yii\web\CacheSession', - * // 'cache' => 'mycache', - * ] - * ~~~ - * - * @property boolean $useCustomStorage Whether to use custom storage. This property is read-only. - * - * @author Qiang Xue - * @since 2.0 - */ -class CacheSession extends Session -{ - /** - * @var Cache|string the cache object or the application component ID of the cache object. - * The session data will be stored using this cache object. - * - * After the CacheSession object is created, if you want to change this property, - * you should only assign it with a cache object. - */ - public $cache = 'cache'; - - /** - * Initializes the application component. - */ - public function init() - { - if (is_string($this->cache)) { - $this->cache = Yii::$app->getComponent($this->cache); - } - if (!$this->cache instanceof Cache) { - throw new InvalidConfigException('CacheSession::cache must refer to the application component ID of a cache object.'); - } - parent::init(); - } - - /** - * Returns a value indicating whether to use custom session storage. - * This method overrides the parent implementation and always returns true. - * @return boolean whether to use custom storage. - */ - public function getUseCustomStorage() - { - return true; - } - - /** - * Session read handler. - * Do not call this method directly. - * @param string $id session ID - * @return string the session data - */ - public function readSession($id) - { - $data = $this->cache->get($this->calculateKey($id)); - return $data === false ? '' : $data; - } - - /** - * Session write handler. - * Do not call this method directly. - * @param string $id session ID - * @param string $data session data - * @return boolean whether session write is successful - */ - public function writeSession($id, $data) - { - return $this->cache->set($this->calculateKey($id), $data, $this->getTimeout()); - } - - /** - * Session destroy handler. - * Do not call this method directly. - * @param string $id session ID - * @return boolean whether session is destroyed successfully - */ - public function destroySession($id) - { - return $this->cache->delete($this->calculateKey($id)); - } - - /** - * Generates a unique key used for storing session data in cache. - * @param string $id session variable name - * @return mixed a safe cache key associated with the session variable name - */ - protected function calculateKey($id) - { - return [__CLASS__, $id]; - } -}