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
9806563f
Commit
9806563f
authored
Jun 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring.
parent
3fc19008
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
16 deletions
+49
-16
Application.php
framework/yii/base/Application.php
+1
-1
HttpException.php
framework/yii/base/HttpException.php
+3
-2
Response.php
framework/yii/base/Response.php
+26
-6
Response.php
framework/yii/web/Response.php
+19
-7
No files found.
framework/yii/base/Application.php
View file @
9806563f
...
...
@@ -137,7 +137,6 @@ class Application extends Module
// Allocating twice more than required to display memory exhausted error
// in case of trying to allocate last 1 byte while all memory is taken.
$this
->
_memoryReserve
=
str_repeat
(
'x'
,
1024
*
256
);
register_shutdown_function
(
array
(
$this
,
'end'
),
0
,
false
);
register_shutdown_function
(
array
(
$this
,
'handleFatalError'
));
}
}
...
...
@@ -172,6 +171,7 @@ class Application extends Module
$this
->
beforeRun
();
$response
=
$this
->
getResponse
();
$response
->
begin
();
register_shutdown_function
(
array
(
$this
,
'end'
),
0
,
false
);
$status
=
$this
->
processRequest
();
$response
->
end
();
$this
->
afterRun
();
...
...
framework/yii/base/HttpException.php
View file @
9806563f
...
...
@@ -7,6 +7,7 @@
namespace
yii\base
;
use
yii\web\Response
;
/**
* HttpException represents an exception caused by an improper request of the end-user.
...
...
@@ -43,8 +44,8 @@ class HttpException extends UserException
*/
public
function
getName
()
{
if
(
isset
(
\yii\web\Response
::
$statusText
s
[
$this
->
statusCode
]))
{
return
\yii\web\Response
::
$statusText
s
[
$this
->
statusCode
];
if
(
isset
(
Response
::
$httpStatuse
s
[
$this
->
statusCode
]))
{
return
Response
::
$httpStatuse
s
[
$this
->
statusCode
];
}
else
{
return
'Error'
;
}
...
...
framework/yii/base/Response.php
View file @
9806563f
...
...
@@ -13,23 +13,29 @@ namespace yii\base;
*/
class
Response
extends
Component
{
/**
* @event Event an event raised when the application begins to generate the response.
*/
const
EVENT_BEGIN_RESPONSE
=
'beginResponse'
;
/**
* @event Event an event raised when the generation of the response finishes.
*/
const
EVENT_END_RESPONSE
=
'endResponse'
;
/**
* Starts output buffering
*/
public
function
begin
Output
()
public
function
begin
Buffer
()
{
ob_start
();
ob_implicit_flush
(
false
);
}
/**
* Returns contents of the output buffer and
discards it
* Returns contents of the output buffer and
stops the buffer.
* @return string output buffer contents
*/
public
function
end
Output
()
public
function
end
Buffer
()
{
return
ob_get_clean
();
}
...
...
@@ -38,16 +44,16 @@ class Response extends Component
* Returns contents of the output buffer
* @return string output buffer contents
*/
public
function
get
Output
()
public
function
get
Buffer
()
{
return
ob_get_contents
();
}
/**
* Discards the output buffer
* @param boolean $all if true
recursively discards all output buffers used
* @param boolean $all if true
, it will discards all output buffers.
*/
public
function
clean
Output
(
$all
=
true
)
public
function
clean
Buffer
(
$all
=
true
)
{
if
(
$all
)
{
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
...
...
@@ -60,11 +66,25 @@ class Response extends Component
}
}
/**
* Begins generating the response.
* This method is called at the beginning of [[Application::run()]].
* The default implementation will trigger the [[EVENT_BEGIN_RESPONSE]] event.
* If you overwrite this method, make sure you call the parent implementation so that
* the event can be triggered.
*/
public
function
begin
()
{
$this
->
trigger
(
self
::
EVENT_BEGIN_RESPONSE
);
}
/**
* Ends generating the response.
* This method is called at the end of [[Application::run()]].
* The default implementation will trigger the [[EVENT_END_RESPONSE]] event.
* If you overwrite this method, make sure you call the parent implementation so that
* the event can be triggered.
*/
public
function
end
()
{
$this
->
trigger
(
self
::
EVENT_END_RESPONSE
);
...
...
framework/yii/web/Response.php
View file @
9806563f
...
...
@@ -46,11 +46,10 @@ class Response extends \yii\base\Response
* @var string the version of the HTTP protocol to use
*/
public
$version
=
'1.0'
;
/**
* @var array list of HTTP status codes and the corresponding texts
*/
public
static
$
statusText
s
=
array
(
public
static
$
httpStatuse
s
=
array
(
100
=>
'Continue'
,
101
=>
'Switching Protocols'
,
102
=>
'Processing'
,
...
...
@@ -135,12 +134,12 @@ class Response extends \yii\base\Response
public
function
begin
()
{
parent
::
begin
();
$this
->
begin
Output
();
$this
->
begin
Buffer
();
}
public
function
end
()
{
$this
->
content
.=
$this
->
end
Output
();
$this
->
content
.=
$this
->
end
Buffer
();
$this
->
send
();
parent
::
end
();
}
...
...
@@ -157,7 +156,7 @@ class Response extends \yii\base\Response
throw
new
InvalidParamException
(
"The HTTP status code is invalid:
$value
"
);
}
if
(
$text
===
null
)
{
$this
->
statusText
=
isset
(
self
::
$
statusTexts
[
$this
->
_statusCode
])
?
self
::
$statusText
s
[
$this
->
_statusCode
]
:
''
;
$this
->
statusText
=
isset
(
self
::
$
httpStatuses
[
$this
->
_statusCode
])
?
self
::
$httpStatuse
s
[
$this
->
_statusCode
]
:
''
;
}
else
{
$this
->
statusText
=
$text
;
}
...
...
@@ -178,15 +177,17 @@ class Response extends \yii\base\Response
public
function
renderJson
(
$data
)
{
$this
->
getHeaders
()
->
set
(
'
content-t
ype'
,
'application/json'
);
$this
->
getHeaders
()
->
set
(
'
Content-T
ype'
,
'application/json'
);
$this
->
content
=
Json
::
encode
(
$data
);
$this
->
send
();
}
public
function
renderJsonp
(
$data
,
$callbackName
)
{
$this
->
getHeaders
()
->
set
(
'
content-t
ype'
,
'text/javascript'
);
$this
->
getHeaders
()
->
set
(
'
Content-T
ype'
,
'text/javascript'
);
$data
=
Json
::
encode
(
$data
);
$this
->
content
=
"
$callbackName
(
$data
);"
;
$this
->
send
();
}
/**
...
...
@@ -197,6 +198,17 @@ class Response extends \yii\base\Response
{
$this
->
sendHeaders
();
$this
->
sendContent
();
if
(
function_exists
(
'fastcgi_finish_request'
))
{
fastcgi_finish_request
();
}
else
{
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
if
(
!@
ob_end_flush
())
{
ob_clean
();
}
}
flush
();
}
}
public
function
reset
()
...
...
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