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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
82c978f8
Commit
82c978f8
authored
Jun 16, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
draft idea of action based responses
parent
4ef19b2e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
19 deletions
+30
-19
Action.php
framework/yii/base/Action.php
+20
-1
Application.php
framework/yii/base/Application.php
+1
-0
Controller.php
framework/yii/base/Controller.php
+1
-0
InlineAction.php
framework/yii/base/InlineAction.php
+3
-1
Application.php
framework/yii/console/Application.php
+2
-6
Application.php
framework/yii/web/Application.php
+3
-11
No files found.
framework/yii/base/Action.php
View file @
82c978f8
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
namespace
yii\base
;
namespace
yii\base
;
use
Yii
;
/**
/**
* Action is the base class for all controller action classes.
* Action is the base class for all controller action classes.
*
*
...
@@ -40,6 +42,21 @@ class Action extends Component
...
@@ -40,6 +42,21 @@ class Action extends Component
*/
*/
public
$controller
;
public
$controller
;
private
$_response
;
public
function
getResponse
()
{
if
(
$this
->
_response
===
null
)
{
$this
->
_response
=
Yii
::
$app
->
createResponse
();
}
return
$this
->
_response
;
}
public
function
setResponse
(
$response
)
{
$this
->
_response
=
$response
;
}
/**
/**
* Constructor.
* Constructor.
* @param string $id the ID of this action
* @param string $id the ID of this action
...
@@ -75,6 +92,8 @@ class Action extends Component
...
@@ -75,6 +92,8 @@ class Action extends Component
throw
new
InvalidConfigException
(
get_class
(
$this
)
.
' must define a "run()" method.'
);
throw
new
InvalidConfigException
(
get_class
(
$this
)
.
' must define a "run()" method.'
);
}
}
$args
=
$this
->
controller
->
bindActionParams
(
$this
,
$params
);
$args
=
$this
->
controller
->
bindActionParams
(
$this
,
$params
);
return
call_user_func_array
(
array
(
$this
,
'run'
),
$args
);
$response
=
$this
->
getResponse
();
$response
->
result
=
call_user_func_array
(
array
(
$this
,
'run'
),
$args
);
return
$response
;
}
}
}
}
framework/yii/base/Application.php
View file @
82c978f8
...
@@ -155,6 +155,7 @@ abstract class Application extends Module
...
@@ -155,6 +155,7 @@ abstract class Application extends Module
*/
*/
abstract
public
function
handleRequest
(
$request
);
abstract
public
function
handleRequest
(
$request
);
public
abstract
function
createResponse
();
private
$_runtimePath
;
private
$_runtimePath
;
...
...
framework/yii/base/Controller.php
View file @
82c978f8
...
@@ -111,6 +111,7 @@ class Controller extends Component
...
@@ -111,6 +111,7 @@ class Controller extends Component
$oldAction
=
$this
->
action
;
$oldAction
=
$this
->
action
;
$this
->
action
=
$action
;
$this
->
action
=
$action
;
$result
=
null
;
$result
=
null
;
// TODO beforeAction may also create a response somehow.
if
(
$this
->
module
->
beforeAction
(
$action
))
{
if
(
$this
->
module
->
beforeAction
(
$action
))
{
if
(
$this
->
beforeAction
(
$action
))
{
if
(
$this
->
beforeAction
(
$action
))
{
$result
=
$action
->
runWithParams
(
$params
);
$result
=
$action
->
runWithParams
(
$params
);
...
...
framework/yii/base/InlineAction.php
View file @
82c978f8
...
@@ -44,6 +44,8 @@ class InlineAction extends Action
...
@@ -44,6 +44,8 @@ class InlineAction extends Action
public
function
runWithParams
(
$params
)
public
function
runWithParams
(
$params
)
{
{
$args
=
$this
->
controller
->
bindActionParams
(
$this
,
$params
);
$args
=
$this
->
controller
->
bindActionParams
(
$this
,
$params
);
return
call_user_func_array
(
array
(
$this
->
controller
,
$this
->
actionMethod
),
$args
);
$response
=
$this
->
getResponse
();
$response
->
result
=
call_user_func_array
(
array
(
$this
->
controller
,
$this
->
actionMethod
),
$args
);
return
$response
;
}
}
}
}
framework/yii/console/Application.php
View file @
82c978f8
...
@@ -93,22 +93,18 @@ class Application extends \yii\base\Application
...
@@ -93,22 +93,18 @@ class Application extends \yii\base\Application
{
{
list
(
$route
,
$params
)
=
$request
->
resolve
();
list
(
$route
,
$params
)
=
$request
->
resolve
();
$result
=
$this
->
runAction
(
$route
,
$params
);
$result
=
$this
->
runAction
(
$route
,
$params
);
if
(
$result
instanceof
Response
)
{
return
$result
;
}
else
{
$response
=
$this
->
getResponse
();
$response
=
$this
->
getResponse
();
$response
->
exitStatus
=
(
int
)
$result
;
$response
->
exitStatus
=
(
int
)
$result
;
return
$response
;
return
$response
;
}
}
}
/**
/**
* Returns the response component.
* Returns the response component.
* @return Response the response component
* @return Response the response component
*/
*/
public
function
get
Response
()
public
function
create
Response
()
{
{
return
$this
->
getComponent
(
'response'
);
return
new
Response
(
);
}
}
/**
/**
...
...
framework/yii/web/Application.php
View file @
82c978f8
...
@@ -65,16 +65,8 @@ class Application extends \yii\base\Application
...
@@ -65,16 +65,8 @@ class Application extends \yii\base\Application
$params
=
array_splice
(
$this
->
catchAll
,
1
);
$params
=
array_splice
(
$this
->
catchAll
,
1
);
}
}
try
{
try
{
$result
=
$this
->
runAction
(
$route
,
$params
);
$response
=
$this
->
runAction
(
$route
,
$params
);
if
(
$result
instanceof
Response
)
{
return
$result
;
}
else
{
$response
=
$this
->
getResponse
();
if
(
$result
!==
null
)
{
$response
->
setContent
(
$result
);
}
return
$response
;
return
$response
;
}
}
catch
(
InvalidRouteException
$e
)
{
}
catch
(
InvalidRouteException
$e
)
{
throw
new
HttpException
(
404
,
$e
->
getMessage
(),
$e
->
getCode
(),
$e
);
throw
new
HttpException
(
404
,
$e
->
getMessage
(),
$e
->
getCode
(),
$e
);
}
}
...
@@ -119,9 +111,9 @@ class Application extends \yii\base\Application
...
@@ -119,9 +111,9 @@ class Application extends \yii\base\Application
* Returns the response component.
* Returns the response component.
* @return Response the response component
* @return Response the response component
*/
*/
public
function
get
Response
()
public
function
create
Response
()
{
{
return
$this
->
getComponent
(
'response'
);
return
new
Response
(
);
}
}
/**
/**
...
...
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