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
15cde607
Commit
15cde607
authored
Aug 29, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring redirect and response classes.
parent
f79dd1ba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
45 deletions
+73
-45
container.php
laravel/config/container.php
+14
-0
download.php
laravel/download.php
+41
-0
response.php
laravel/response.php
+18
-45
No files found.
laravel/config/container.php
View file @
15cde607
...
@@ -16,6 +16,12 @@ return array(
...
@@ -16,6 +16,12 @@ return array(
}),
}),
'laravel.download'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
return
new
Download
(
$container
->
resolve
(
'laravel.file'
));
}),
'laravel.file'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
'laravel.file'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
{
return
new
File
(
$container
->
resolve
(
'laravel.config'
)
->
get
(
'mimes'
));
return
new
File
(
$container
->
resolve
(
'laravel.config'
)
->
get
(
'mimes'
));
...
@@ -57,6 +63,14 @@ return array(
...
@@ -57,6 +63,14 @@ return array(
}),
}),
'laravel.response'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
require_once
SYS_PATH
.
'response'
.
EXT
;
return
new
Response_Factory
(
$container
->
resolve
(
'laravel.view'
));
}),
'laravel.router'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
'laravel.router'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
{
return
new
Routing\Router
(
$container
->
resolve
(
'laravel.request'
),
require
APP_PATH
.
'routes'
.
EXT
,
CONTROLLER_PATH
);
return
new
Routing\Router
(
$container
->
resolve
(
'laravel.request'
),
require
APP_PATH
.
'routes'
.
EXT
,
CONTROLLER_PATH
);
...
...
laravel/download.php
0 → 100644
View file @
15cde607
<?php
namespace
Laravel
;
class
Download
extends
Response
{
/**
* Create a new download generator instance.
*
* @param File $file
* @return void
*/
public
function
__construct
(
File
$file
)
{
$this
->
file
=
$file
;
}
/**
* Create a new download response instance.
*
* @param string $path
* @param string $name
* @return Response
*/
public
function
of
(
$path
,
$name
=
null
)
{
if
(
is_null
(
$name
))
$name
=
basename
(
$path
);
$response
=
parent
::
__construct
(
$this
->
file
->
get
(
$path
));
$response
->
header
(
'Content-Description'
,
'File Transfer'
);
$response
->
header
(
'Content-Type'
,
$this
->
file
->
mime
(
$this
->
file
->
extension
(
$path
)));
$response
->
header
(
'Content-Disposition'
,
'attachment; filename="'
.
$name
.
'"'
);
$response
->
header
(
'Content-Transfer-Encoding'
,
'binary'
);
$response
->
header
(
'Expires'
,
0
);
$response
->
header
(
'Cache-Control'
,
'must-revalidate, post-check=0, pre-check=0'
);
$response
->
header
(
'Pragma'
,
'public'
);
$response
->
header
(
'Content-Length'
,
$this
->
file
->
size
(
$path
));
return
$response
;
}
}
\ No newline at end of file
laravel/response.php
View file @
15cde607
...
@@ -9,23 +9,15 @@ class Response_Factory {
...
@@ -9,23 +9,15 @@ class Response_Factory {
*/
*/
private
$view
;
private
$view
;
/**
* The file manager instance.
*
* @var File
*/
private
$file
;
/**
/**
* Create a new response factory instance.
* Create a new response factory instance.
*
*
* @param File $file
* @param File $file
* @return void
* @return void
*/
*/
public
function
__construct
(
View_Factory
$view
,
File
$file
)
public
function
__construct
(
View_Factory
$view
)
{
{
$this
->
view
=
$view
;
$this
->
view
=
$view
;
$this
->
file
=
$file
;
}
}
/**
/**
...
@@ -41,36 +33,15 @@ class Response_Factory {
...
@@ -41,36 +33,15 @@ class Response_Factory {
}
}
/**
/**
* Create a new download response instance.
* Create a new response instance containing a view.
*
* <code>
* // Return a download response for a given file
* return new Download('path/to/image.jpg');
*
* // Return a download response for a given file and assign a name
* return new Download('path/to/image.jpg', 'you.jpg');
* </code>
*
*
* @param string $
path
* @param string $
view
* @param
string $name
* @param
array $data
* @return Response
* @return Response
*/
*/
public
function
download
(
$path
,
$name
=
null
)
public
function
view
(
$view
,
$data
=
array
()
)
{
{
if
(
is_null
(
$name
))
$name
=
basename
(
$path
);
return
new
Response
(
$this
->
view
->
make
(
$view
,
$data
));
$response
=
new
Response
(
$this
->
file
->
get
(
$path
));
$response
->
header
(
'Content-Description'
,
'File Transfer'
);
$response
->
header
(
'Content-Type'
,
$this
->
file
->
mime
(
$this
->
file
->
extension
(
$path
)));
$response
->
header
(
'Content-Disposition'
,
'attachment; filename="'
.
$name
.
'"'
);
$response
->
header
(
'Content-Transfer-Encoding'
,
'binary'
);
$response
->
header
(
'Expires'
,
0
);
$response
->
header
(
'Cache-Control'
,
'must-revalidate, post-check=0, pre-check=0'
);
$response
->
header
(
'Pragma'
,
'public'
);
$response
->
header
(
'Content-Length'
,
$this
->
file
->
size
(
$path
));
return
$response
;
}
}
/**
/**
...
@@ -80,11 +51,6 @@ class Response_Factory {
...
@@ -80,11 +51,6 @@ class Response_Factory {
*
*
* Note: The specified error code should correspond to a view in your views/error directory.
* Note: The specified error code should correspond to a view in your views/error directory.
*
*
* <code>
* // Return a 404 error response
* return new Error('404');
* </code>
*
* @param int $code
* @param int $code
* @param array $data
* @param array $data
* @return void
* @return void
...
@@ -233,11 +199,6 @@ class Response {
...
@@ -233,11 +199,6 @@ class Response {
/**
/**
* Add a header to the response.
* Add a header to the response.
*
*
* <code>
* // Add a "location" header to a response
* $response->header('Location', 'http://google.com');
* </code>
*
* @param string $name
* @param string $name
* @param string $value
* @param string $value
* @return Response
* @return Response
...
@@ -248,4 +209,16 @@ class Response {
...
@@ -248,4 +209,16 @@ class Response {
return
$this
;
return
$this
;
}
}
/**
* Set the response status code.
*
* @param int $status
* @return Response
*/
public
function
status
(
$status
)
{
$this
->
status
=
$status
;
return
$this
;
}
}
}
\ No newline at end of file
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