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
Hide 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
...
@@ -137,7 +137,6 @@ class Application extends Module
// Allocating twice more than required to display memory exhausted error
// Allocating twice more than required to display memory exhausted error
// in case of trying to allocate last 1 byte while all memory is taken.
// in case of trying to allocate last 1 byte while all memory is taken.
$this
->
_memoryReserve
=
str_repeat
(
'x'
,
1024
*
256
);
$this
->
_memoryReserve
=
str_repeat
(
'x'
,
1024
*
256
);
register_shutdown_function
(
array
(
$this
,
'end'
),
0
,
false
);
register_shutdown_function
(
array
(
$this
,
'handleFatalError'
));
register_shutdown_function
(
array
(
$this
,
'handleFatalError'
));
}
}
}
}
...
@@ -172,6 +171,7 @@ class Application extends Module
...
@@ -172,6 +171,7 @@ class Application extends Module
$this
->
beforeRun
();
$this
->
beforeRun
();
$response
=
$this
->
getResponse
();
$response
=
$this
->
getResponse
();
$response
->
begin
();
$response
->
begin
();
register_shutdown_function
(
array
(
$this
,
'end'
),
0
,
false
);
$status
=
$this
->
processRequest
();
$status
=
$this
->
processRequest
();
$response
->
end
();
$response
->
end
();
$this
->
afterRun
();
$this
->
afterRun
();
...
...
framework/yii/base/HttpException.php
View file @
9806563f
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
yii\base
;
namespace
yii\base
;
use
yii\web\Response
;
/**
/**
* HttpException represents an exception caused by an improper request of the end-user.
* HttpException represents an exception caused by an improper request of the end-user.
...
@@ -43,8 +44,8 @@ class HttpException extends UserException
...
@@ -43,8 +44,8 @@ class HttpException extends UserException
*/
*/
public
function
getName
()
public
function
getName
()
{
{
if
(
isset
(
\yii\web\Response
::
$statusText
s
[
$this
->
statusCode
]))
{
if
(
isset
(
Response
::
$httpStatuse
s
[
$this
->
statusCode
]))
{
return
\yii\web\Response
::
$statusText
s
[
$this
->
statusCode
];
return
Response
::
$httpStatuse
s
[
$this
->
statusCode
];
}
else
{
}
else
{
return
'Error'
;
return
'Error'
;
}
}
...
...
framework/yii/base/Response.php
View file @
9806563f
...
@@ -13,23 +13,29 @@ namespace yii\base;
...
@@ -13,23 +13,29 @@ namespace yii\base;
*/
*/
class
Response
extends
Component
class
Response
extends
Component
{
{
/**
* @event Event an event raised when the application begins to generate the response.
*/
const
EVENT_BEGIN_RESPONSE
=
'beginResponse'
;
const
EVENT_BEGIN_RESPONSE
=
'beginResponse'
;
/**
* @event Event an event raised when the generation of the response finishes.
*/
const
EVENT_END_RESPONSE
=
'endResponse'
;
const
EVENT_END_RESPONSE
=
'endResponse'
;
/**
/**
* Starts output buffering
* Starts output buffering
*/
*/
public
function
begin
Output
()
public
function
begin
Buffer
()
{
{
ob_start
();
ob_start
();
ob_implicit_flush
(
false
);
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
* @return string output buffer contents
*/
*/
public
function
end
Output
()
public
function
end
Buffer
()
{
{
return
ob_get_clean
();
return
ob_get_clean
();
}
}
...
@@ -38,16 +44,16 @@ class Response extends Component
...
@@ -38,16 +44,16 @@ class Response extends Component
* Returns contents of the output buffer
* Returns contents of the output buffer
* @return string output buffer contents
* @return string output buffer contents
*/
*/
public
function
get
Output
()
public
function
get
Buffer
()
{
{
return
ob_get_contents
();
return
ob_get_contents
();
}
}
/**
/**
* Discards the output buffer
* 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
)
{
if
(
$all
)
{
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
...
@@ -60,11 +66,25 @@ class Response extends Component
...
@@ -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
()
public
function
begin
()
{
{
$this
->
trigger
(
self
::
EVENT_BEGIN_RESPONSE
);
$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
()
public
function
end
()
{
{
$this
->
trigger
(
self
::
EVENT_END_RESPONSE
);
$this
->
trigger
(
self
::
EVENT_END_RESPONSE
);
...
...
framework/yii/web/Response.php
View file @
9806563f
...
@@ -46,11 +46,10 @@ class Response extends \yii\base\Response
...
@@ -46,11 +46,10 @@ class Response extends \yii\base\Response
* @var string the version of the HTTP protocol to use
* @var string the version of the HTTP protocol to use
*/
*/
public
$version
=
'1.0'
;
public
$version
=
'1.0'
;
/**
/**
* @var array list of HTTP status codes and the corresponding texts
* @var array list of HTTP status codes and the corresponding texts
*/
*/
public
static
$
statusText
s
=
array
(
public
static
$
httpStatuse
s
=
array
(
100
=>
'Continue'
,
100
=>
'Continue'
,
101
=>
'Switching Protocols'
,
101
=>
'Switching Protocols'
,
102
=>
'Processing'
,
102
=>
'Processing'
,
...
@@ -135,12 +134,12 @@ class Response extends \yii\base\Response
...
@@ -135,12 +134,12 @@ class Response extends \yii\base\Response
public
function
begin
()
public
function
begin
()
{
{
parent
::
begin
();
parent
::
begin
();
$this
->
begin
Output
();
$this
->
begin
Buffer
();
}
}
public
function
end
()
public
function
end
()
{
{
$this
->
content
.=
$this
->
end
Output
();
$this
->
content
.=
$this
->
end
Buffer
();
$this
->
send
();
$this
->
send
();
parent
::
end
();
parent
::
end
();
}
}
...
@@ -157,7 +156,7 @@ class Response extends \yii\base\Response
...
@@ -157,7 +156,7 @@ class Response extends \yii\base\Response
throw
new
InvalidParamException
(
"The HTTP status code is invalid:
$value
"
);
throw
new
InvalidParamException
(
"The HTTP status code is invalid:
$value
"
);
}
}
if
(
$text
===
null
)
{
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
{
}
else
{
$this
->
statusText
=
$text
;
$this
->
statusText
=
$text
;
}
}
...
@@ -178,15 +177,17 @@ class Response extends \yii\base\Response
...
@@ -178,15 +177,17 @@ class Response extends \yii\base\Response
public
function
renderJson
(
$data
)
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
->
content
=
Json
::
encode
(
$data
);
$this
->
send
();
}
}
public
function
renderJsonp
(
$data
,
$callbackName
)
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
);
$data
=
Json
::
encode
(
$data
);
$this
->
content
=
"
$callbackName
(
$data
);"
;
$this
->
content
=
"
$callbackName
(
$data
);"
;
$this
->
send
();
}
}
/**
/**
...
@@ -197,6 +198,17 @@ class Response extends \yii\base\Response
...
@@ -197,6 +198,17 @@ class Response extends \yii\base\Response
{
{
$this
->
sendHeaders
();
$this
->
sendHeaders
();
$this
->
sendContent
();
$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
()
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