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
f690f0db
Commit
f690f0db
authored
May 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #441: InvalidRequestException should be HttpException
parent
33dbe8fb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
57 deletions
+45
-57
Controller.php
framework/yii/base/Controller.php
+1
-31
InvalidRequestException.php
framework/yii/base/InvalidRequestException.php
+0
-26
Controller.php
framework/yii/web/Controller.php
+44
-0
No files found.
framework/yii/base/Controller.php
View file @
f690f0db
...
...
@@ -151,43 +151,13 @@ class Controller extends Component
/**
* Binds the parameters to the action.
* This method is invoked by [[Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown.
* @param Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with.
* @throws InvalidRequestException if there are missing parameters.
*/
public
function
bindActionParams
(
$action
,
$params
)
{
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
}
$args
=
array
();
$missing
=
array
();
foreach
(
$method
->
getParameters
()
as
$param
)
{
$name
=
$param
->
getName
();
if
(
array_key_exists
(
$name
,
$params
))
{
$args
[]
=
$params
[
$name
];
unset
(
$params
[
$name
]);
}
elseif
(
$param
->
isDefaultValueAvailable
())
{
$args
[]
=
$param
->
getDefaultValue
();
}
else
{
$missing
[]
=
$name
;
}
}
if
(
!
empty
(
$missing
))
{
throw
new
InvalidRequestException
(
Yii
::
t
(
'yii'
,
'Missing required parameters: {params}'
,
array
(
'{params}'
=>
implode
(
', '
,
$missing
),
)));
}
return
$args
;
return
array
();
}
/**
...
...
framework/yii/base/InvalidRequestException.php
deleted
100644 → 0
View file @
33dbe8fb
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\base
;
/**
* InvalidRequestException represents an exception caused by incorrect end user request.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
InvalidRequestException
extends
UserException
{
/**
* @return string the user-friendly name of this exception
*/
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Invalid Request'
);
}
}
framework/yii/web/Controller.php
View file @
f690f0db
...
...
@@ -8,6 +8,8 @@
namespace
yii\web
;
use
Yii
;
use
yii\base\HttpException
;
use
yii\base\InlineAction
;
/**
* Controller is the base class of Web controllers.
...
...
@@ -19,6 +21,48 @@ use Yii;
class
Controller
extends
\yii\base\Controller
{
/**
* Binds the parameters to the action.
* This method is invoked by [[Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown.
* @param \yii\base\Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with.
* @throws HttpException if there are missing parameters.
*/
public
function
bindActionParams
(
$action
,
$params
)
{
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
}
$args
=
array
();
$missing
=
array
();
foreach
(
$method
->
getParameters
()
as
$param
)
{
$name
=
$param
->
getName
();
if
(
array_key_exists
(
$name
,
$params
))
{
$args
[]
=
$params
[
$name
];
unset
(
$params
[
$name
]);
}
elseif
(
$param
->
isDefaultValueAvailable
())
{
$args
[]
=
$param
->
getDefaultValue
();
}
else
{
$missing
[]
=
$name
;
}
}
if
(
!
empty
(
$missing
))
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Missing required parameters: {params}'
,
array
(
'{params}'
=>
implode
(
', '
,
$missing
),
)));
}
return
$args
;
}
/**
* Creates a URL using the given route and parameters.
*
* This method enhances [[UrlManager::createUrl()]] by supporting relative routes.
...
...
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