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
932a70b6
Commit
932a70b6
authored
Oct 30, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring for better dependency injection on a few classes.
parent
faaea17f
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
244 additions
and
101 deletions
+244
-101
application.php
application/config/application.php
+2
-2
core.php
laravel/bootstrap/core.php
+1
-0
container.php
laravel/config/container.php
+63
-0
facades.php
laravel/facades.php
+63
-0
form.php
laravel/form.php
+3
-1
input.php
laravel/input.php
+34
-14
laravel.php
laravel/laravel.php
+4
-44
paginator.php
laravel/paginator.php
+3
-3
request.php
laravel/request.php
+59
-30
response.php
laravel/response.php
+3
-1
router.php
laravel/routing/router.php
+4
-3
url.php
laravel/url.php
+1
-1
validator.php
laravel/validation/validator.php
+4
-2
No files found.
application/config/application.php
View file @
932a70b6
...
...
@@ -146,13 +146,13 @@ return array(
'Hasher'
=>
'Laravel\\Security\\Hasher'
,
'HTML'
=>
'Laravel\\HTML'
,
'Inflector'
=>
'Laravel\\Inflector'
,
'Input'
=>
'Laravel\\Input'
,
'Input'
=>
'Laravel\\
Facades\\
Input'
,
'IoC'
=>
'Laravel\\IoC'
,
'Lang'
=>
'Laravel\\Lang'
,
'URL'
=>
'Laravel\\URL'
,
'Redirect'
=>
'Laravel\\Redirect'
,
'Redis'
=>
'Laravel\\Redis'
,
'Request'
=>
'Laravel\\Request'
,
'Request'
=>
'Laravel\\
Facades\\
Request'
,
'Response'
=>
'Laravel\\Response'
,
'Session'
=>
'Laravel\\Session\\Manager'
,
'Str'
=>
'Laravel\\Str'
,
...
...
laravel/bootstrap/core.php
View file @
932a70b6
...
...
@@ -9,6 +9,7 @@ require 'constants.php';
*/
require
SYS_PATH
.
'arr'
.
EXT
;
require
SYS_PATH
.
'config'
.
EXT
;
require
SYS_PATH
.
'facades'
.
EXT
;
/**
* Load some core configuration files by default so we don't have to
...
...
laravel/config/container.php
View file @
932a70b6
...
...
@@ -2,6 +2,69 @@
return
array
(
/*
|--------------------------------------------------------------------------
| Various Laravel Components
|--------------------------------------------------------------------------
|
| Many of the Laravel classes are resolved through the inversion of control
| container to maintain a high level of testability and flexibility.
|
| Most of them are also accessible through a "Facade", which simulates the
| class being usable via static methods for convenience. Facades allow the
| framework to keep a convenient API, while still having a testable core.
|
*/
'laravel.input'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$c
)
{
require
SYS_PATH
.
'input'
.
EXT
;
$input
=
array
();
$request
=
$c
->
core
(
'request'
);
switch
(
$request
->
method
())
{
case
'GET'
:
$input
=
$_GET
;
break
;
case
'POST'
:
$input
=
$_POST
;
break
;
case
'PUT'
:
case
'DELETE'
:
if
(
$request
->
spoofed
())
{
$input
=
$_POST
;
}
else
{
parse_str
(
file_get_contents
(
'php://input'
),
$input
);
}
}
return
new
Input
(
$input
,
$_FILES
);
}),
'laravel.request'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$c
)
{
require_once
SYS_PATH
.
'request'
.
EXT
;
return
new
Request
(
$c
->
core
(
'uri'
),
$_POST
,
$_SERVER
);
}),
'laravel.uri'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$c
)
{
require_once
SYS_PATH
.
'uri'
.
EXT
;
return
new
URI
(
$_SERVER
);
}),
/*
|--------------------------------------------------------------------------
| Laravel Routing Components
...
...
laravel/facades.php
0 → 100644
View file @
932a70b6
<?php
namespace
Laravel\Facades
;
use
Laravel\IoC
;
/**
* The Laravel framework makes thorough use of dependency injection assisted by an application
* inversion of control container. This allows for great flexibility, easy testing, and better
* architecture. However, most PHP framework users may be used to accessing classes through
* a variety of static methods. Laravel provides "facades" to simulate this behavior while
* still using heavy dependency injection.
*
* Each class that is commonly used by the developer has a corresponding facade defined in
* this file. All of the various facades inherit from the abstract Facade class, which only
* has a single __callStatic magic method. The facade simply resolves the requested class
* out of the IoC container and calls the appropriate method.
*/
abstract
class
Facade
{
/**
* Magic Method for passing methods to a class registered in the IoC container.
* This provides a convenient method of accessing functions on classes that
* could not otherwise be accessed staticly.
*
* Facades allow Laravel to still have a high level of dependency injection
* and testability while still accomodating the common desire to conveniently
* use classes via static methods.
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
$class
=
IoC
::
container
()
->
resolve
(
static
::
$resolve
);
$count
=
count
(
$parameters
);
if
(
$count
>
5
)
{
return
call_user_func_array
(
array
(
$class
,
$method
),
$parameters
);
}
elseif
(
$count
==
1
)
{
return
$class
->
$method
(
$parameters
[
0
]);
}
elseif
(
$count
==
2
)
{
return
$class
->
$method
(
$parameters
[
0
],
$parameters
[
1
]);
}
elseif
(
$count
==
3
)
{
return
$class
->
$method
(
$parameters
[
0
],
$parameters
[
1
],
$parameters
[
2
]);
}
elseif
(
$count
==
4
)
{
return
$class
->
$method
(
$parameters
[
0
],
$parameters
[
1
],
$parameters
[
2
],
$parameters
[
3
]);
}
elseif
(
$count
==
5
)
{
return
$class
->
$method
(
$parameters
[
0
],
$parameters
[
1
],
$parameters
[
2
],
$parameters
[
3
],
$parameters
[
4
]);
}
}
}
class
Input
extends
Facade
{
public
static
$resolve
=
'laravel.input'
;
}
class
Request
extends
Facade
{
public
static
$resolve
=
'laravel.request'
;
}
\ No newline at end of file
laravel/form.php
View file @
932a70b6
...
...
@@ -82,7 +82,9 @@ class Form {
*/
protected
static
function
action
(
$action
,
$https
)
{
return
HTML
::
entities
(
URL
::
to
(((
is_null
(
$action
))
?
Request
::
uri
()
->
get
()
:
$action
),
$https
));
$request
=
IoC
::
container
()
->
core
(
'uri'
);
return
HTML
::
entities
(
URL
::
to
(((
is_null
(
$action
))
?
$uri
->
get
()
:
$action
),
$https
));
}
/**
...
...
laravel/input.php
View file @
932a70b6
...
...
@@ -7,7 +7,14 @@ class Input {
*
* @var array
*/
public
static
$input
;
protected
$input
;
/**
* The $_FILES array for the request.
*
* @var array
*/
protected
$files
;
/**
* The key used to store old input in the session.
...
...
@@ -16,6 +23,19 @@ class Input {
*/
const
old_input
=
'laravel_old_input'
;
/**
* Create a new instance of the Input manager.
*
* @param array $input
* @param array $files
* @return void
*/
public
function
__construct
(
$input
,
$files
)
{
$this
->
input
=
$input
;
$this
->
files
=
$files
;
}
/**
* Get all of the input data for the request.
*
...
...
@@ -23,9 +43,9 @@ class Input {
*
* @return array
*/
public
static
function
all
()
public
function
all
()
{
return
array_merge
(
static
::
get
(),
static
::
file
());
return
array_merge
(
$this
->
get
(),
$this
->
file
());
}
/**
...
...
@@ -36,9 +56,9 @@ class Input {
* @param string $key
* @return bool
*/
public
static
function
has
(
$key
)
public
function
has
(
$key
)
{
return
(
!
is_null
(
static
::
get
(
$key
))
and
trim
((
string
)
static
::
get
(
$key
))
!==
''
);
return
(
!
is_null
(
$this
->
get
(
$key
))
and
trim
((
string
)
$this
->
get
(
$key
))
!==
''
);
}
/**
...
...
@@ -58,9 +78,9 @@ class Input {
* @param mixed $default
* @return mixed
*/
public
static
function
get
(
$key
=
null
,
$default
=
null
)
public
function
get
(
$key
=
null
,
$default
=
null
)
{
return
Arr
::
get
(
static
::
$
input
,
$key
,
$default
);
return
Arr
::
get
(
$this
->
input
,
$key
,
$default
);
}
/**
...
...
@@ -69,9 +89,9 @@ class Input {
* @param string $key
* @return bool
*/
public
static
function
had
(
$key
)
public
function
had
(
$key
)
{
return
(
!
is_null
(
static
::
old
(
$key
))
and
trim
((
string
)
static
::
old
(
$key
))
!==
''
);
return
(
!
is_null
(
$this
->
old
(
$key
))
and
trim
((
string
)
$this
->
old
(
$key
))
!==
''
);
}
/**
...
...
@@ -89,7 +109,7 @@ class Input {
* @param mixed $default
* @return string
*/
public
static
function
old
(
$key
=
null
,
$default
=
null
)
public
function
old
(
$key
=
null
,
$default
=
null
)
{
if
(
Config
::
get
(
'session.driver'
)
==
''
)
{
...
...
@@ -114,9 +134,9 @@ class Input {
* @param mixed $default
* @return array
*/
public
static
function
file
(
$key
=
null
,
$default
=
null
)
public
function
file
(
$key
=
null
,
$default
=
null
)
{
return
Arr
::
get
(
$
_FILES
,
$key
,
$default
);
return
Arr
::
get
(
$
this
->
files
,
$key
,
$default
);
}
/**
...
...
@@ -133,9 +153,9 @@ class Input {
* @param string $path
* @return bool
*/
public
static
function
upload
(
$key
,
$path
)
public
function
upload
(
$key
,
$path
)
{
return
array_key_exists
(
$key
,
$
_FILES
)
?
File
::
upload
(
$key
,
$path
,
$_FILES
)
:
false
;
return
array_key_exists
(
$key
,
$
this
->
files
)
?
File
::
upload
(
$key
,
$path
,
$this
->
files
)
:
false
;
}
}
\ No newline at end of file
laravel/laravel.php
View file @
932a70b6
...
...
@@ -37,52 +37,12 @@ if (Config::$items['session']['driver'] !== '')
* Manually load some core classes that are used on every request
* This allows to avoid using the loader for these classes.
*/
require
SYS_PATH
.
'uri'
.
EXT
;
require
SYS_PATH
.
'input'
.
EXT
;
require
SYS_PATH
.
'request'
.
EXT
;
require
SYS_PATH
.
'response'
.
EXT
;
require
SYS_PATH
.
'routing/route'
.
EXT
;
require
SYS_PATH
.
'routing/router'
.
EXT
;
require
SYS_PATH
.
'routing/loader'
.
EXT
;
require
SYS_PATH
.
'routing/filter'
.
EXT
;
/**
* Gather the input to the application for the current request.
* The input will be gathered based on the current request method
* and will be set on the Input manager.
*/
$input
=
array
();
switch
(
Request
::
method
())
{
case
'GET'
:
$input
=
$_GET
;
break
;
case
'POST'
:
$input
=
$_POST
;
break
;
case
'PUT'
:
case
'DELETE'
:
if
(
Request
::
spoofed
())
{
$input
=
$_POST
;
}
else
{
parse_str
(
file_get_contents
(
'php://input'
),
$input
);
}
}
/**
* The spoofed request method is removed from the input so it is
* not unexpectedly included in Input::all() or Input::get().s
*/
unset
(
$input
[
Request
::
spoofer
]);
Input
::
$input
=
$input
;
/**
* Route the request to the proper route in the application. If a
* route is found, the route will be called with the current request
...
...
@@ -91,13 +51,13 @@ Input::$input = $input;
*/
Routing\Filter
::
register
(
require
APP_PATH
.
'filters'
.
EXT
);
list
(
$uri
,
$method
)
=
array
(
Request
::
uri
()
->
get
(),
Request
::
method
()
);
$request
=
IoC
::
container
()
->
core
(
'request'
);
Request
::
$route
=
IoC
::
container
()
->
core
(
'routing.router'
)
->
route
(
$method
,
$uri
);
$request
->
route
=
IoC
::
container
()
->
core
(
'routing.router'
)
->
route
(
$request
);
if
(
!
is_null
(
Request
::
$
route
))
if
(
!
is_null
(
$request
->
route
))
{
$response
=
Request
::
$
route
->
call
();
$response
=
$request
->
route
->
call
();
}
else
{
...
...
laravel/paginator.php
View file @
932a70b6
...
...
@@ -105,7 +105,7 @@ class Paginator {
*/
public
static
function
page
(
$total
,
$per_page
)
{
$page
=
I
nput
::
get
(
'page'
,
1
);
$page
=
I
oC
::
container
()
->
core
(
'input'
)
->
get
(
'page'
,
1
);
// The page will be validated and adjusted if it is less than one or greater
// than the last page. For example, if the current page is not an integer or
...
...
@@ -250,11 +250,11 @@ class Paginator {
// We will assume the page links should use HTTPS if the current request
// is also using HTTPS. Since pagination links automatically point to
// the current URI, this makes pretty good sense.
list
(
$uri
,
$secure
)
=
array
(
Request
::
uri
()
->
get
(),
Request
::
secure
()
);
$request
=
IoC
::
container
()
->
core
(
'request'
);
$appendage
=
$this
->
appendage
(
$element
,
$page
);
return
HTML
::
link
(
$
uri
.
$appendage
,
$text
,
array
(
'class'
=>
$class
),
$secure
);
return
HTML
::
link
(
$
request
->
uri
()
.
$appendage
,
$text
,
array
(
'class'
=>
$class
),
$requst
->
secure
()
);
}
}
...
...
laravel/request.php
View file @
932a70b6
...
...
@@ -2,19 +2,33 @@
class
Request
{
/**
* The route handling the current request.
*
* @var Routing\Route
*/
public
$route
;
/**
* The request URI for the current request.
*
* @var URI
*/
p
ublic
static
$uri
;
p
rotected
$uri
;
/**
* The
route handling the current
request.
* The
$_POST array for the
request.
*
* @var
Routing\Route
* @var
array
*/
public
static
$route
;
protected
$post
;
/**
* The $_SERVER array for the request.
*
* @var array
*/
protected
$server
;
/**
* The request data key that is used to indicate a spoofed request method.
...
...
@@ -24,13 +38,28 @@ class Request {
const
spoofer
=
'__spoofer'
;
/**
*
Get the URI instance for the current request
.
*
Create a new Request instance
.
*
* @return URI
* @param URI $uri
* @param array $post
* @param array $server
* @return void
*/
public
function
__construct
(
$uri
,
$post
,
$server
)
{
$this
->
uri
=
$uri
;
$this
->
post
=
$post
;
$this
->
server
=
$server
;
}
/**
* Get the current request's URI.
*
* @return string
*/
public
static
function
uri
()
public
function
uri
()
{
return
(
is_null
(
static
::
$uri
))
?
static
::
$uri
=
new
URI
(
$_SERVER
)
:
static
::
$uri
;
return
$this
->
uri
->
get
()
;
}
/**
...
...
@@ -42,9 +71,9 @@ class Request {
*
* @return string
*/
public
static
function
method
()
public
function
method
()
{
return
(
static
::
spoofed
())
?
$_POST
[
Request
::
spoofer
]
:
$_SERVER
[
'REQUEST_METHOD'
];
return
(
$this
->
spoofed
())
?
$this
->
post
[
Request
::
spoofer
]
:
$this
->
server
[
'REQUEST_METHOD'
];
}
/**
...
...
@@ -56,9 +85,9 @@ class Request {
* @param mixed $default
* @return string
*/
public
static
function
server
(
$key
=
null
,
$default
=
null
)
public
function
server
(
$key
=
null
,
$default
=
null
)
{
return
Arr
::
get
(
$
_SERVER
,
strtoupper
(
$key
),
$default
);
return
Arr
::
get
(
$
this
->
server
,
strtoupper
(
$key
),
$default
);
}
/**
...
...
@@ -66,9 +95,9 @@ class Request {
*
* @return bool
*/
public
static
function
spoofed
()
public
function
spoofed
()
{
return
is_array
(
$
_POST
)
and
array_key_exists
(
Request
::
spoofer
,
$_POST
);
return
is_array
(
$
this
->
post
)
and
array_key_exists
(
Request
::
spoofer
,
$this
->
post
);
}
/**
...
...
@@ -77,19 +106,19 @@ class Request {
* @param mixed $default
* @return string
*/
public
static
function
ip
(
$default
=
'0.0.0.0'
)
public
function
ip
(
$default
=
'0.0.0.0'
)
{
if
(
isset
(
$
_SERVER
[
'HTTP_X_FORWARDED_FOR'
]))
if
(
isset
(
$
this
->
server
[
'HTTP_X_FORWARDED_FOR'
]))
{
return
$
_SERVER
[
'HTTP_X_FORWARDED_FOR'
];
return
$
this
->
server
[
'HTTP_X_FORWARDED_FOR'
];
}
elseif
(
isset
(
$
_SERVER
[
'HTTP_CLIENT_IP'
]))
elseif
(
isset
(
$
this
->
server
[
'HTTP_CLIENT_IP'
]))
{
return
$
_SERVER
[
'HTTP_CLIENT_IP'
];
return
$
this
->
server
[
'HTTP_CLIENT_IP'
];
}
elseif
(
isset
(
$
_SERVER
[
'REMOTE_ADDR'
]))
elseif
(
isset
(
$
this
->
server
[
'REMOTE_ADDR'
]))
{
return
$
_SERVER
[
'REMOTE_ADDR'
];
return
$
this
->
server
[
'REMOTE_ADDR'
];
}
return
(
$default
instanceof
Closure
)
?
call_user_func
(
$default
)
:
$default
;
...
...
@@ -100,9 +129,9 @@ class Request {
*
* @return string
*/
public
static
function
protocol
()
public
function
protocol
()
{
return
Arr
::
get
(
$
_SERVER
,
'SERVER_PROTOCOL'
,
'HTTP/1.1'
);
return
Arr
::
get
(
$
this
->
server
,
'SERVER_PROTOCOL'
,
'HTTP/1.1'
);
}
/**
...
...
@@ -110,9 +139,9 @@ class Request {
*
* @return bool
*/
public
static
function
secure
()
public
function
secure
()
{
return
isset
(
$
_SERVER
[
'HTTPS'
])
and
strtolower
(
$_SERVER
[
'HTTPS'
])
!==
'off'
;
return
isset
(
$
this
->
server
[
'HTTPS'
])
and
strtolower
(
$this
->
server
[
'HTTPS'
])
!==
'off'
;
}
/**
...
...
@@ -120,11 +149,11 @@ class Request {
*
* @return bool
*/
public
static
function
ajax
()
public
function
ajax
()
{
if
(
!
isset
(
$
_SERVER
[
'HTTP_X_REQUESTED_WITH'
]))
return
false
;
if
(
!
isset
(
$
this
->
server
[
'HTTP_X_REQUESTED_WITH'
]))
return
false
;
return
strtolower
(
$
_SERVER
[
'HTTP_X_REQUESTED_WITH'
])
===
'xmlhttprequest'
;
return
strtolower
(
$
this
->
server
[
'HTTP_X_REQUESTED_WITH'
])
===
'xmlhttprequest'
;
}
/**
...
...
@@ -132,9 +161,9 @@ class Request {
*
* @return Route
*/
public
static
function
route
()
public
function
route
()
{
return
static
::
$
route
;
return
$this
->
route
;
}
}
\ No newline at end of file
laravel/response.php
View file @
932a70b6
...
...
@@ -261,7 +261,9 @@ class Response {
$this
->
header
(
'Content-Type'
,
'text/html; charset='
.
Config
::
$items
[
'application'
][
'encoding'
]);
}
header
(
Request
::
protocol
()
.
' '
.
$this
->
status
.
' '
.
$this
->
statuses
[
$this
->
status
]);
$request
=
IoC
::
container
()
->
core
(
'request'
);
header
(
$request
->
protocol
()
.
' '
.
$this
->
status
.
' '
.
$this
->
statuses
[
$this
->
status
]);
foreach
(
$this
->
headers
as
$name
=>
$value
)
{
...
...
laravel/routing/router.php
View file @
932a70b6
...
...
@@ -102,12 +102,13 @@ class Router {
/**
* Search the routes for the route matching a request method and URI.
*
* @param string $method
* @param string $uri
* @param Request $request
* @return Route
*/
public
function
route
(
$method
,
$uri
)
public
function
route
(
Request
$request
)
{
list
(
$method
,
$uri
)
=
array
(
$request
->
method
(),
$request
->
uri
());
$routes
=
$this
->
loader
->
load
(
$uri
);
// All route URIs begin with the request method and have a leading
...
...
laravel/url.php
View file @
932a70b6
...
...
@@ -53,7 +53,7 @@ class URL {
*/
public
static
function
to_asset
(
$url
,
$https
=
null
)
{
if
(
is_null
(
$https
))
$https
=
Request
::
secure
();
if
(
is_null
(
$https
))
$https
=
IoC
::
container
()
->
core
(
'request'
)
->
secure
();
$url
=
static
::
to
(
$url
,
$https
);
...
...
laravel/validation/validator.php
View file @
932a70b6
...
...
@@ -341,7 +341,7 @@ class Validator {
{
return
$this
->
attributes
[
$attribute
];
}
elseif
(
array_key_exists
(
$attribute
,
I
nput
::
file
()))
elseif
(
array_key_exists
(
$attribute
,
I
oC
::
container
()
->
core
(
'input'
)
->
file
()))
{
return
$value
[
'size'
]
/
1024
;
}
...
...
@@ -529,7 +529,9 @@ class Validator {
// type of attribute being validated, either a file or a string.
elseif
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
$this
->
has_rule
(
$attribute
,
$this
->
numeric_rules
))
{
$line
=
(
array_key_exists
(
$attribute
,
Input
::
file
()))
?
"file"
:
"string"
;
$files
=
IoC
::
container
()
->
core
(
'input'
)
->
file
();
$line
=
(
array_key_exists
(
$attribute
,
$files
))
?
"file"
:
"string"
;
return
Lang
::
line
(
"validation.
{
$rule
}
.
{
$line
}
"
)
->
get
(
$this
->
language
);
}
...
...
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