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
d1611e66
Commit
d1611e66
authored
Apr 30, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
1db738ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
48 deletions
+39
-48
Action.php
framework/base/Action.php
+16
-12
ActionFilter.php
framework/base/ActionFilter.php
+10
-11
Controller.php
framework/base/Controller.php
+3
-5
InlineAction.php
framework/base/InlineAction.php
+10
-20
No files found.
framework/base/Action.php
View file @
d1611e66
...
...
@@ -15,10 +15,10 @@ namespace yii\base;
* Action provides a way to divide a complex controller into
* smaller actions in separate class files.
*
* Derived classes must implement
{@link run()} which is invoked by
* controller when the action is requested.
*
*
An action instance can access its controller via {@link getController controller} property
.
* Derived classes must implement
a method named `run()`. This method
*
will be invoked by the
controller when the action is requested.
*
The `run()` method can have parameters which will be filled up
*
automatically according to their names
.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
@@ -35,17 +35,21 @@ class Action extends Component
public
$controller
;
/**
* Extracts the input parameters according to the signature of the "run()" method.
* This method is invoked by controller when it attempts to run the action
* with the user supplied parameters.
* @param array $params the parameters in name-value pairs
* @return array|boolean the extracted parameters in the order as declared in the "run()" method.
* False is returned if the input parameters do not follow the method declaration.
* Runs the action with the supplied parameters.
* This method is invoked by the controller.
* @param array $params the input parameters in terms of name-value pairs.
* @return boolean whether the input parameters are valid
*/
public
function
normalize
Params
(
$params
)
public
function
runWith
Params
(
$params
)
{
$method
=
new
\ReflectionMethod
(
$this
,
'run'
);
return
$this
->
normalizeParamsByMethod
(
$method
,
$params
);
$params
=
$this
->
normalizeParamsByMethod
(
$method
,
$params
);
if
(
$params
!==
false
)
{
call_user_func_array
(
array
(
$this
,
'run'
),
$params
);
return
true
;
}
else
{
return
false
;
}
}
/**
...
...
framework/base/ActionFilter.php
View file @
d1611e66
<?php
/**
*
C
Filter class file.
*
Action
Filter class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\base
;
/**
*
C
Filter is the base class for all filters.
*
Action
Filter is the base class for all filters.
*
* A filter can be applied before and after an action is executed.
* It can modify the context that the action is to run or decorate the result that the
...
...
@@ -19,11 +20,9 @@
* before the action, and {@link postFilter()} for filtering logic after the action.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.web.filters
* @since 1.0
* @since 2.0
*/
class
C
Filter
extends
CComponent
implements
IFilter
class
Action
Filter
extends
CComponent
implements
IFilter
{
/**
* Performs the filtering.
...
...
@@ -32,7 +31,7 @@ class CFilter extends CComponent implements IFilter
* child classes. If a child class needs to override this method,
* make sure it calls <code>$filterChain->run()</code>
* if the action should be executed.
* @param
C
FilterChain $filterChain the filter chain that the filter is on.
* @param
Action
FilterChain $filterChain the filter chain that the filter is on.
*/
public
function
filter
(
$filterChain
)
{
...
...
@@ -56,7 +55,7 @@ class CFilter extends CComponent implements IFilter
/**
* Performs the pre-action filtering.
* @param
C
FilterChain $filterChain the filter chain that the filter is on.
* @param
Action
FilterChain $filterChain the filter chain that the filter is on.
* @return boolean whether the filtering process should continue and the action
* should be executed.
*/
...
...
@@ -67,7 +66,7 @@ class CFilter extends CComponent implements IFilter
/**
* Performs the post-action filtering.
* @param
C
FilterChain $filterChain the filter chain that the filter is on.
* @param
Action
FilterChain $filterChain the filter chain that the filter is on.
*/
protected
function
postFilter
(
$filterChain
)
{
...
...
framework/base/Controller.php
View file @
d1611e66
...
...
@@ -252,12 +252,10 @@ abstract class Controller extends Component implements Initable
$priorAction
=
$this
->
_action
;
$this
->
_action
=
$action
;
if
(
$this
->
beforeAction
(
$action
))
{
$params
=
$action
->
normalizeParams
(
$this
->
getActionParams
());
if
(
$params
===
false
)
{
$this
->
invalidActionParams
(
$action
);
}
else
{
call_user_func_array
(
array
(
$action
,
'run'
),
$params
);
if
(
$action
->
runWithParams
(
$this
->
getActionParams
()))
{
$this
->
afterAction
(
$action
);
}
else
{
$this
->
invalidActionParams
(
$action
);
}
}
$this
->
_action
=
$priorAction
;
...
...
framework/base/InlineAction.php
View file @
d1611e66
...
...
@@ -12,7 +12,8 @@ namespace yii\base;
/**
* InlineAction represents an action that is defined as a controller method.
*
* The method name is like 'actionXYZ' where 'XYZ' stands for the action name.
* The name of the controller method should be in the format of `actionXyz`
* where `Xyz` stands for the action ID (e.g. `actionIndex`).
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
@@ -20,29 +21,18 @@ namespace yii\base;
class
InlineAction
extends
Action
{
/**
* Runs the action.
* This method is invoked by the controller to run the action.
* @param array $params the input parameters
* Runs the action with the supplied parameters.
* This method is invoked by the controller.
* @param array $params the input parameters in terms of name-value pairs.
* @return boolean whether the input parameters are valid
*/
public
function
run
(
$params
)
{
call_user_func_array
(
array
(
$this
->
controller
,
'action'
.
$this
->
id
),
$params
);
}
/**
* Extracts the input parameters according to the signature of the controller action method.
* This method is invoked by controller when it attempts to run the action
* with the user supplied parameters.
* @param array $params the parameters in name-value pairs
* @return array|boolean the extracted parameters in the order as declared in the controller action method.
* False is returned if the input parameters do not follow the method declaration.
*/
public
function
normalizeParams
(
$params
)
public
function
runWithParams
(
$params
)
{
$method
=
new
\ReflectionMethod
(
$this
->
controller
,
'action'
.
$this
->
id
);
$params
=
$this
->
normalizeParams
(
$method
,
$params
);
$params
=
$this
->
normalizeParams
ByMethod
(
$method
,
$params
);
if
(
$params
!==
false
)
{
return
array
(
$params
);
call_user_func_array
(
array
(
$this
->
controller
,
'action'
.
$this
->
id
),
$params
);
return
true
;
}
else
{
return
false
;
}
...
...
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