Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c7c13a66
Commit
c7c13a66
authored
Nov 29, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added concrete http exception classes.
parent
dd9facce
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
146 additions
and
34 deletions
+146
-34
SiteController.php
apps/advanced/frontend/controllers/SiteController.php
+2
-2
authorization.md
docs/guide/authorization.md
+3
-3
controller.md
docs/guide/controller.md
+1
-1
Module.php
extensions/debug/Module.php
+2
-2
DefaultController.php
extensions/debug/controllers/DefaultController.php
+2
-2
Module.php
extensions/gii/Module.php
+2
-2
DefaultController.php
extensions/gii/controllers/DefaultController.php
+7
-7
controller.php
extensions/gii/generators/crud/templates/controller.php
+3
-3
Application.php
framework/yii/base/Application.php
+2
-2
AccessControl.php
framework/yii/web/AccessControl.php
+2
-2
AccessDeniedHttpException.php
framework/yii/web/AccessDeniedHttpException.php
+28
-0
Application.php
framework/yii/web/Application.php
+2
-2
BadRequestHttpException.php
framework/yii/web/BadRequestHttpException.php
+28
-0
Controller.php
framework/yii/web/Controller.php
+3
-3
MethodNotAllowedHttpException.php
framework/yii/web/MethodNotAllowedHttpException.php
+28
-0
NotFoundHttpException.php
framework/yii/web/NotFoundHttpException.php
+28
-0
Request.php
framework/yii/web/Request.php
+1
-1
User.php
framework/yii/web/User.php
+1
-1
VerbFilter.php
framework/yii/web/VerbFilter.php
+1
-1
No files found.
apps/advanced/frontend/controllers/SiteController.php
View file @
c7c13a66
...
...
@@ -7,7 +7,7 @@ use yii\web\Controller;
use
common\models\LoginForm
;
use
frontend\models\ContactForm
;
use
common\models\User
;
use
yii\web\HttpException
;
use
yii\web\
BadRequest
HttpException
;
use
yii\helpers\Security
;
class
SiteController
extends
Controller
...
...
@@ -132,7 +132,7 @@ class SiteController extends Controller
]);
if
(
!
$model
)
{
throw
new
HttpException
(
400
,
'Wrong password reset token.'
);
throw
new
BadRequestHttpException
(
'Wrong password reset token.'
);
}
$model
->
scenario
=
'resetPassword'
;
...
...
docs/guide/authorization.md
View file @
c7c13a66
...
...
@@ -234,10 +234,10 @@ public function editArticle($id)
{
$article
=
Article
::
find
(
$id
);
if
(
!
$article
)
{
throw
new
HttpException
(
404
)
;
throw
new
NotFoundHttpException
;
}
if
(
!
\Yii
::
$app
->
user
->
checkAccess
(
'edit_article'
,
[
'article'
=>
$article
]))
{
throw
new
HttpException
(
403
)
;
throw
new
AccessDeniedHttpException
;
}
// ...
}
...
...
@@ -250,7 +250,7 @@ public function editArticle($id)
{
$article
=
Article
::
find
([
'id'
=>
$id
,
'author_id'
=>
\Yii
::
$app
->
user
->
id
]);
if
(
!
$article
)
{
throw
new
HttpException
(
404
)
;
throw
new
NotFoundHttpException
;
}
// ...
}
...
...
docs/guide/controller.md
View file @
c7c13a66
...
...
@@ -122,7 +122,7 @@ class BlogController extends Controller
{
$post
=
Post
::
find
(
$id
);
if
(
!
$post
)
{
throw
new
HttpException
(
404
)
;
throw
new
NotFoundHttpException
;
}
if
(
\Yii
::
$app
->
request
->
isPost
))
{
...
...
extensions/debug/Module.php
View file @
c7c13a66
...
...
@@ -10,7 +10,7 @@ namespace yii\debug;
use
Yii
;
use
yii\base\Application
;
use
yii\web\View
;
use
yii\web\HttpException
;
use
yii\web\
AccessDenied
HttpException
;
/**
* The Yii Debug Module provides the debug toolbar and debugger
...
...
@@ -79,7 +79,7 @@ class Module extends \yii\base\Module
}
elseif
(
$action
->
id
===
'toolbar'
)
{
return
false
;
}
else
{
throw
new
HttpException
(
403
,
'You are not allowed to access this page.'
);
throw
new
AccessDeniedHttpException
(
'You are not allowed to access this page.'
);
}
}
...
...
extensions/debug/controllers/DefaultController.php
View file @
c7c13a66
...
...
@@ -9,7 +9,7 @@ namespace yii\debug\controllers;
use
Yii
;
use
yii\web\Controller
;
use
yii\web\HttpException
;
use
yii\web\
NotFound
HttpException
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -99,7 +99,7 @@ class DefaultController extends Controller
}
$this
->
summary
=
$data
[
'summary'
];
}
else
{
throw
new
HttpException
(
404
,
"Unable to find debug data tagged with '
$tag
'."
);
throw
new
NotFoundHttpException
(
"Unable to find debug data tagged with '
$tag
'."
);
}
}
}
extensions/gii/Module.php
View file @
c7c13a66
...
...
@@ -8,7 +8,7 @@
namespace
yii\gii
;
use
Yii
;
use
yii\web\HttpException
;
use
yii\web\
AccessDenied
HttpException
;
/**
* 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
HttpException
(
403
,
'You are not allowed to access this page.'
);
throw
new
AccessDeniedHttpException
(
'You are not allowed to access this page.'
);
}
}
...
...
extensions/gii/controllers/DefaultController.php
View file @
c7c13a66
...
...
@@ -9,7 +9,7 @@ namespace yii\gii\controllers;
use
Yii
;
use
yii\web\Controller
;
use
yii\web\HttpException
;
use
yii\web\
NotFound
HttpException
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -69,7 +69,7 @@ class DefaultController extends Controller
}
}
}
throw
new
HttpException
(
404
,
"Code file not found:
$file
"
);
throw
new
NotFoundHttpException
(
"Code file not found:
$file
"
);
}
public
function
actionDiff
(
$id
,
$file
)
...
...
@@ -84,7 +84,7 @@ class DefaultController extends Controller
}
}
}
throw
new
HttpException
(
404
,
"Code file not found:
$file
"
);
throw
new
NotFoundHttpException
(
"Code file not found:
$file
"
);
}
/**
...
...
@@ -94,7 +94,7 @@ class DefaultController extends Controller
* @param string $id the ID of the generator
* @param string $name the action name
* @return mixed the result of the action.
* @throws HttpException if the action method does not exist.
* @throws
NotFound
HttpException if the action method does not exist.
*/
public
function
actionAction
(
$id
,
$name
)
{
...
...
@@ -103,7 +103,7 @@ class DefaultController extends Controller
if
(
method_exists
(
$generator
,
$method
))
{
return
$generator
->
$method
();
}
else
{
throw
new
HttpException
(
400
,
"Unknown generator action:
$name
"
);
throw
new
NotFoundHttpException
(
"Unknown generator action:
$name
"
);
}
}
...
...
@@ -136,7 +136,7 @@ class DefaultController extends Controller
* Loads the generator with the specified ID.
* @param string $id the ID of the generator to be loaded.
* @return \yii\gii\Generator the loaded generator
* @throws
\yii\web\
HttpException
* @throws
NotFound
HttpException
*/
protected
function
loadGenerator
(
$id
)
{
...
...
@@ -146,7 +146,7 @@ class DefaultController extends Controller
$this
->
generator
->
load
(
$_POST
);
return
$this
->
generator
;
}
else
{
throw
new
HttpException
(
404
,
"Code generator not found:
$id
"
);
throw
new
NotFoundHttpException
(
"Code generator not found:
$id
"
);
}
}
}
extensions/gii/generators/crud/templates/controller.php
View file @
c7c13a66
...
...
@@ -29,7 +29,7 @@ namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>
use
<?=
ltrim
(
$generator
->
modelClass
,
'\\'
)
?>
;
use
<?=
ltrim
(
$generator
->
searchModelClass
,
'\\'
)
?><?php
if
(
isset
(
$searchModelAlias
))
:?>
as
<?=
$searchModelAlias
?><?php
endif
?>
;
use
<?=
ltrim
(
$generator
->
baseControllerClass
,
'\\'
)
?>
;
use yii\web\HttpException;
use yii\web\
NotFound
HttpException;
use yii\web\VerbFilter;
/**
...
...
@@ -130,7 +130,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
* If the model is not found, a 404 HTTP exception will be thrown.
*
<?=
implode
(
"
\n\t
* "
,
$actionParamComments
)
.
"
\n
"
?>
* @return
<?=
$modelClass
?>
the loaded model
* @throws HttpException if the model cannot be found
* @throws
NotFound
HttpException if the model cannot be found
*/
protected function findModel(
<?=
$actionParams
?>
)
{
...
...
@@ -148,7 +148,7 @@ if (count($pks) === 1) {
if (($model =
<?=
$modelClass
?>
::find(
<?=
$condition
?>
)) !== null) {
return $model;
} else {
throw new
HttpException(404,
'The requested page does not exist.');
throw new
NotFoundHttpException(
'The requested page does not exist.');
}
}
}
framework/yii/base/Application.php
View file @
c7c13a66
...
...
@@ -634,9 +634,9 @@ abstract class Application extends Module
{
$category
=
get_class
(
$exception
);
if
(
$exception
instanceof
HttpException
)
{
$category
.=
'\\
'
.
$exception
->
statusCode
;
$category
=
'yii\\web\\HttpException:
'
.
$exception
->
statusCode
;
}
elseif
(
$exception
instanceof
\ErrorException
)
{
$category
.=
'
\\
'
.
$exception
->
getSeverity
();
$category
.=
'
:
'
.
$exception
->
getSeverity
();
}
Yii
::
error
((
string
)
$exception
,
$category
);
}
...
...
framework/yii/web/AccessControl.php
View file @
c7c13a66
...
...
@@ -131,14 +131,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 HttpException if the user is already logged in.
* @throws
AccessDenied
HttpException if the user is already logged in.
*/
protected
function
denyAccess
(
$user
)
{
if
(
$user
->
getIsGuest
())
{
$user
->
loginRequired
();
}
else
{
throw
new
HttpException
(
403
,
Yii
::
t
(
'yii'
,
'You are not allowed to perform this action.'
));
throw
new
AccessDeniedHttpException
(
Yii
::
t
(
'yii'
,
'You are not allowed to perform this action.'
));
}
}
}
framework/yii/web/AccessDeniedHttpException.php
0 → 100644
View file @
c7c13a66
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
/**
* AccessDeniedHttpException represents an "Access Denied" HTTP exception with status code 403.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @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
);
}
}
framework/yii/web/Application.php
View file @
c7c13a66
...
...
@@ -58,7 +58,7 @@ class Application extends \yii\base\Application
* Handles the specified request.
* @param Request $request the request to be handled
* @return Response the resulting response
* @throws HttpException if the requested route is invalid
* @throws
NotFound
HttpException if the requested route is invalid
*/
public
function
handleRequest
(
$request
)
{
...
...
@@ -85,7 +85,7 @@ class Application extends \yii\base\Application
return
$response
;
}
}
catch
(
InvalidRouteException
$e
)
{
throw
new
HttpException
(
404
,
$e
->
getMessage
(),
$e
->
getCode
(),
$e
);
throw
new
NotFoundHttpException
(
$e
->
getMessage
(),
$e
->
getCode
(),
$e
);
}
}
...
...
framework/yii/web/BadRequestHttpException.php
0 → 100644
View file @
c7c13a66
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
/**
* BadRequestHttpException represents a "Bad Request" HTTP exception with status code 400.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
BadRequestHttpException
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
(
400
,
$message
,
$code
,
$previous
);
}
}
framework/yii/web/Controller.php
View file @
c7c13a66
...
...
@@ -62,7 +62,7 @@ class Controller extends \yii\base\Controller
}
elseif
(
!
is_array
(
$params
[
$name
]))
{
$args
[]
=
$actionParams
[
$name
]
=
$params
[
$name
];
}
else
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Invalid data received for parameter "{param}".'
,
[
throw
new
BadRequestHttpException
(
Yii
::
t
(
'yii'
,
'Invalid data received for parameter "{param}".'
,
[
'param'
=>
$name
,
]));
}
...
...
@@ -75,7 +75,7 @@ class Controller extends \yii\base\Controller
}
if
(
!
empty
(
$missing
))
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Missing required parameters: {params}'
,
[
throw
new
BadRequestHttpException
(
Yii
::
t
(
'yii'
,
'Missing required parameters: {params}'
,
[
'params'
=>
implode
(
', '
,
$missing
),
]));
}
...
...
@@ -92,7 +92,7 @@ class Controller extends \yii\base\Controller
{
if
(
parent
::
beforeAction
(
$action
))
{
if
(
$this
->
enableCsrfValidation
&&
Yii
::
$app
->
exception
===
null
&&
!
Yii
::
$app
->
getRequest
()
->
validateCsrfToken
())
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Unable to verify your data submission.'
));
throw
new
BadRequestHttpException
(
Yii
::
t
(
'yii'
,
'Unable to verify your data submission.'
));
}
return
true
;
}
else
{
...
...
framework/yii/web/MethodNotAllowedHttpException.php
0 → 100644
View file @
c7c13a66
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
/**
* MethodNotAllowedHttpException represents a "Method Not Allowed" HTTP exception with status code 405.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
MethodNotAllowedHttpException
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
(
405
,
$message
,
$code
,
$previous
);
}
}
framework/yii/web/NotFoundHttpException.php
0 → 100644
View file @
c7c13a66
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
/**
* NotFoundHttpException represents a "Not Found" HTTP exception with status code 404.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
NotFoundHttpException
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
(
404
,
$message
,
$code
,
$previous
);
}
}
framework/yii/web/Request.php
View file @
c7c13a66
...
...
@@ -139,7 +139,7 @@ class Request extends \yii\base\Request
$_GET
=
array_merge
(
$_GET
,
$params
);
return
[
$route
,
$_GET
];
}
else
{
throw
new
HttpException
(
404
,
Yii
::
t
(
'yii'
,
'Page not found.'
));
throw
new
NotFoundHttpException
(
Yii
::
t
(
'yii'
,
'Page not found.'
));
}
}
...
...
framework/yii/web/User.php
View file @
c7c13a66
...
...
@@ -331,7 +331,7 @@ class User extends Component
Yii
::
$app
->
getResponse
()
->
redirect
(
$this
->
loginUrl
)
->
send
();
exit
();
}
else
{
throw
new
HttpException
(
403
,
Yii
::
t
(
'yii'
,
'Login Required'
));
throw
new
AccessDeniedHttpException
(
Yii
::
t
(
'yii'
,
'Login Required'
));
}
}
...
...
framework/yii/web/VerbFilter.php
View file @
c7c13a66
...
...
@@ -100,7 +100,7 @@ class VerbFilter extends Behavior
$event
->
isValid
=
false
;
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7
Yii
::
$app
->
getResponse
()
->
getHeaders
()
->
set
(
'Allow'
,
implode
(
', '
,
$allowed
));
throw
new
HttpException
(
405
,
Yii
::
t
(
'yii'
,
'Method Not Allowed. This url can only handle the following request methods: {methods}.'
,
[
throw
new
MethodNotAllowedHttpException
(
Yii
::
t
(
'yii'
,
'Method Not Allowed. This url can only handle the following request methods: {methods}.'
,
[
'methods'
=>
implode
(
', '
,
$allowed
),
]));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment