Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
45 deletions
+75
-45
laravel/config/container.php
+14
-0
laravel/download.php
+42
-0
laravel/response.php
+19
-45
No files found.
laravel/config/container.php
View file @
15cde607
...
...
@@ -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
)
{
return
new
File
(
$container
->
resolve
(
'laravel.config'
)
->
get
(
'mimes'
));
...
...
@@ -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
)
{
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
...
...
@@ -10,22 +10,14 @@ class Response_Factory {
private
$view
;
/**
* The file manager instance.
*
* @var File
*/
private
$file
;
/**
* Create a new response factory instance.
*
* @param File $file
* @return void
*/
public
function
__construct
(
View_Factory
$view
,
File
$file
)
public
function
__construct
(
View_Factory
$view
)
{
$this
->
view
=
$view
;
$this
->
file
=
$file
;
}
/**
...
...
@@ -41,36 +33,15 @@ class Response_Factory {
}
/**
* Create a new download response instance.
*
* <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>
* Create a new response instance containing a view.
*
* @param string $
path
* @param
string $name
* @param string $
view
* @param
array $data
* @return Response
*/
public
function
download
(
$path
,
$name
=
null
)
public
function
view
(
$view
,
$data
=
array
()
)
{
if
(
is_null
(
$name
))
$name
=
basename
(
$path
);
$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
;
return
new
Response
(
$this
->
view
->
make
(
$view
,
$data
));
}
/**
...
...
@@ -80,11 +51,6 @@ class Response_Factory {
*
* 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 array $data
* @return void
...
...
@@ -233,11 +199,6 @@ class 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 $value
* @return Response
...
...
@@ -248,4 +209,16 @@ class Response {
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