Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
89766bef
Commit
89766bef
authored
Mar 28, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converting to httpfoundation response.
parent
573725ad
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
135 deletions
+53
-135
core.php
laravel/core.php
+1
-1
helpers.php
laravel/helpers.php
+11
-0
request.php
laravel/request.php
+6
-6
response.php
laravel/response.php
+35
-128
No files found.
laravel/core.php
View file @
89766bef
...
...
@@ -176,4 +176,4 @@ foreach ($bundles as $bundle => $config)
use
Symfony\Component\HttpFoundation\Request
as
FoundationRequest
;
Request
::
$request
=
FoundationRequest
::
createFromGlobals
();
\ No newline at end of file
Request
::
$foundation
=
FoundationRequest
::
createFromGlobals
();
\ No newline at end of file
laravel/helpers.php
View file @
89766bef
...
...
@@ -361,6 +361,17 @@ function str_finish($value, $cap)
return
rtrim
(
$value
,
$cap
)
.
$cap
;
}
/**
* Determine if the given object has a toString method.
*
* @param object $value
* @return bool
*/
function
str_object
(
$value
)
{
return
is_object
(
$value
)
and
method_exists
(
$value
,
'__toString'
);
}
/**
* Get the root namespace of a given class.
*
...
...
laravel/request.php
View file @
89766bef
...
...
@@ -7,7 +7,7 @@ class Request {
*
* @var HttpFoundation\Request
*/
public
static
$
request
;
public
static
$
foundation
;
/**
* All of the route instances handling the request.
...
...
@@ -78,7 +78,7 @@ class Request {
*/
public
static
function
ip
(
$default
=
'0.0.0.0'
)
{
return
value
(
static
::
$
request
->
getClientIp
(),
$default
);
return
value
(
static
::
$
foundation
->
getClientIp
(),
$default
);
}
/**
...
...
@@ -98,7 +98,7 @@ class Request {
*/
public
static
function
accept
()
{
return
static
::
$
request
->
getAcceptableContentTypes
();
return
static
::
$
foundation
->
getAcceptableContentTypes
();
}
/**
...
...
@@ -118,7 +118,7 @@ class Request {
*/
public
static
function
secure
()
{
return
static
::
$
request
->
isSecure
();
return
static
::
$
foundation
->
isSecure
();
}
/**
...
...
@@ -140,7 +140,7 @@ class Request {
*/
public
static
function
ajax
()
{
return
static
::
$
request
->
isXmlHttpRequest
();
return
static
::
$
foundation
->
isXmlHttpRequest
();
}
/**
...
...
@@ -203,7 +203,7 @@ class Request {
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
return
call_user_func_array
(
array
(
static
::
$
request
,
$method
),
$parameters
);
return
call_user_func_array
(
array
(
static
::
$
foundation
,
$method
),
$parameters
);
}
}
\ No newline at end of file
laravel/response.php
View file @
89766bef
<?php
namespace
Laravel
;
use
Symfony\Component\HttpFoundation\Response
as
FoundationResponse
;
class
Response
{
/**
...
...
@@ -10,72 +12,11 @@ class Response {
public
$content
;
/**
* The HTTP status code of the response.
*
* @var int
*/
public
$status
=
200
;
/**
* The response headers.
*
* @var array
*/
public
$headers
=
array
();
/**
* HTTP status codes.
* The Symfony HttpFoundation Response instance.
*
* @var
array
* @var
HttpFoundation\Response
*/
public
static
$statuses
=
array
(
100
=>
'Continue'
,
101
=>
'Switching Protocols'
,
200
=>
'OK'
,
201
=>
'Created'
,
202
=>
'Accepted'
,
203
=>
'Non-Authoritative Information'
,
204
=>
'No Content'
,
205
=>
'Reset Content'
,
206
=>
'Partial Content'
,
207
=>
'Multi-Status'
,
300
=>
'Multiple Choices'
,
301
=>
'Moved Permanently'
,
302
=>
'Found'
,
303
=>
'See Other'
,
304
=>
'Not Modified'
,
305
=>
'Use Proxy'
,
307
=>
'Temporary Redirect'
,
400
=>
'Bad Request'
,
401
=>
'Unauthorized'
,
402
=>
'Payment Required'
,
403
=>
'Forbidden'
,
404
=>
'Not Found'
,
405
=>
'Method Not Allowed'
,
406
=>
'Not Acceptable'
,
407
=>
'Proxy Authentication Required'
,
408
=>
'Request Timeout'
,
409
=>
'Conflict'
,
410
=>
'Gone'
,
411
=>
'Length Required'
,
412
=>
'Precondition Failed'
,
413
=>
'Request Entity Too Large'
,
414
=>
'Request-URI Too Long'
,
415
=>
'Unsupported Media Type'
,
416
=>
'Requested Range Not Satisfiable'
,
417
=>
'Expectation Failed'
,
422
=>
'Unprocessable Entity'
,
423
=>
'Locked'
,
424
=>
'Failed Dependency'
,
500
=>
'Internal Server Error'
,
501
=>
'Not Implemented'
,
502
=>
'Bad Gateway'
,
503
=>
'Service Unavailable'
,
504
=>
'Gateway Timeout'
,
505
=>
'HTTP Version Not Supported'
,
507
=>
'Insufficient Storage'
,
509
=>
'Bandwidth Limit Exceeded'
);
public
$foundation
;
/**
* Create a new response instance.
...
...
@@ -87,9 +28,9 @@ class Response {
*/
public
function
__construct
(
$content
,
$status
=
200
,
$headers
=
array
())
{
$this
->
status
=
$status
;
$this
->
content
=
$content
;
$this
->
headers
=
$headers
;
$this
->
foundation
=
new
FoundationResponse
(
''
,
$status
,
$headers
);
}
/**
...
...
@@ -181,14 +122,14 @@ class Response {
if
(
is_null
(
$name
))
$name
=
basename
(
$path
);
$headers
=
array_merge
(
array
(
'
content-d
escription'
=>
'File Transfer'
,
'
content-t
ype'
=>
File
::
mime
(
File
::
extension
(
$path
)),
'
content-d
isposition'
=>
'attachment; filename="'
.
$name
.
'"'
,
'
content-transfer-e
ncoding'
=>
'binary'
,
'
e
xpires'
=>
0
,
'
cache-c
ontrol'
=>
'must-revalidate, post-check=0, pre-check=0'
,
'
p
ragma'
=>
'public'
,
'
content-l
ength'
=>
File
::
size
(
$path
),
'
Content-D
escription'
=>
'File Transfer'
,
'
Content-T
ype'
=>
File
::
mime
(
File
::
extension
(
$path
)),
'
Content-D
isposition'
=>
'attachment; filename="'
.
$name
.
'"'
,
'
Content-Transfer-E
ncoding'
=>
'binary'
,
'
E
xpires'
=>
0
,
'
Cache-C
ontrol'
=>
'must-revalidate, post-check=0, pre-check=0'
,
'
P
ragma'
=>
'public'
,
'
Content-L
ength'
=>
File
::
size
(
$path
),
),
$headers
);
return
new
static
(
File
::
get
(
$path
),
200
,
$headers
);
...
...
@@ -205,18 +146,14 @@ class Response {
*/
public
static
function
prepare
(
$response
)
{
// We'll need to force the response to be a string before closing
// the session, since the developer may be utilizing the session
// within the view, and we can't age it until rendering.
if
(
!
$response
instanceof
Response
)
{
$response
=
new
static
(
$response
);
}
// We'll need to force the response to be a string before closing the session,
// since the developer may be using the session within a view, and we can't
// age the flash data until the view is rendered.
//
// Since this method is used by both the Route and Controller classes, it is
// a convenient spot to cast the application response to a string before it
// is returned to the main request handler.
$response
->
render
();
return
$response
;
...
...
@@ -229,7 +166,10 @@ class Response {
*/
public
function
render
()
{
if
(
is_object
(
$this
->
content
)
and
method_exists
(
$this
->
content
,
'__toString'
))
// If the content is a stringable object, we'll go ahead and call
// to toString method so that we can get the string content of
// the content object. Otherwise we'll just cast to string.
if
(
str_object
(
$this
->
content
))
{
$this
->
content
=
$this
->
content
->
__toString
();
}
...
...
@@ -238,6 +178,11 @@ class Response {
$this
->
content
=
(
string
)
$this
->
content
;
}
// Once we have the string content, we can set the content on
// the HttpFoundation Response instance in preparation for
// sending it back to client browser when all is done.
$this
->
foundation
->
setContent
(
$this
->
content
);
return
$this
->
content
;
}
...
...
@@ -248,9 +193,9 @@ class Response {
*/
public
function
send
()
{
if
(
!
headers_sent
())
$this
->
send_headers
(
);
$this
->
foundation
->
prepare
(
Request
::
$foundation
);
echo
(
string
)
$this
->
content
;
$this
->
foundation
->
send
()
;
}
/**
...
...
@@ -260,49 +205,9 @@ class Response {
*/
public
function
send_headers
()
{
// If the server is using FastCGI, we need to send a slightly different
// protocol and status header than we normally would. Otherwise it will
// not call any custom scripts setup to handle 404 responses.
//
// The status header will contain both the code and the status message,
// such as "OK" or "Not Found". For typical servers, the HTTP protocol
// will also be included with the status.
if
(
isset
(
$_SERVER
[
'FCGI_SERVER_VERSION'
]))
{
header
(
'Status: '
.
$this
->
status
.
' '
.
$this
->
message
());
}
else
{
header
(
Request
::
protocol
()
.
' '
.
$this
->
status
.
' '
.
$this
->
message
());
}
$this
->
foundation
->
prepare
(
Request
::
$foundation
);
// If the content type was not set by the developer, we will set the
// header to a default value that indicates to the browser that the
// response is HTML and that it uses the default encoding.
if
(
!
isset
(
$this
->
headers
[
'content-type'
]))
{
$encoding
=
Config
::
get
(
'application.encoding'
);
$this
->
header
(
'content-type'
,
'text/html; charset='
.
$encoding
);
}
// Once the framework controlled headers have been sentm, we can
// simply iterate over the developer's headers and send each one
// back to the browser for the response.
foreach
(
$this
->
headers
as
$name
=>
$value
)
{
header
(
"
{
$name
}
:
{
$value
}
"
,
true
);
}
}
/**
* Get the status code message for the response.
*
* @return string
*/
public
function
message
()
{
return
static
::
$statuses
[
$this
->
status
];
$this
->
foundation
->
sendHeaders
();
}
/**
...
...
@@ -314,7 +219,8 @@ class Response {
*/
public
function
header
(
$name
,
$value
)
{
$this
->
headers
[
strtolower
(
$name
)]
=
$value
;
$this
->
foundation
->
headers
->
set
(
$name
,
$value
);
return
$this
;
}
...
...
@@ -326,7 +232,8 @@ class Response {
*/
public
function
status
(
$status
)
{
$this
->
status
=
$status
;
$this
->
foundation
->
setStatusCode
(
$status
);
return
$this
;
}
...
...
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