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
82045e20
Commit
82045e20
authored
Aug 25, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring for dependency injection.
parent
6a8aafc2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
119 additions
and
63 deletions
+119
-63
dependencies.php
laravel/config/dependencies.php
+14
-3
container.php
laravel/container.php
+16
-0
form.php
laravel/form.php
+10
-8
html.php
laravel/html.php
+11
-5
inflector.php
laravel/inflector.php
+16
-0
laravel.php
laravel/laravel.php
+15
-11
redirect.php
laravel/redirect.php
+5
-3
renderable.php
laravel/renderable.php
+0
-12
response.php
laravel/response.php
+11
-0
url.php
laravel/url.php
+21
-21
No files found.
laravel/config/dependencies.php
View file @
82045e20
...
...
@@ -2,6 +2,17 @@
return
array
(
/*
|--------------------------------------------------------------------------
| Laravel URL Writer
|--------------------------------------------------------------------------
*/
'laravel.url'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
()
{
return
new
URL
;
}),
/*
|--------------------------------------------------------------------------
| Laravel File Cache Driver
...
...
@@ -19,7 +30,7 @@ return array(
|--------------------------------------------------------------------------
*/
'laravel.cache.file_engine'
=>
array
(
'resolver'
=>
function
(
$container
)
'laravel.cache.file_engine'
=>
array
(
'resolver'
=>
function
()
{
return
new
Cache\File_Engine
;
}),
...
...
@@ -41,7 +52,7 @@ return array(
|--------------------------------------------------------------------------
*/
'laravel.cache.apc_engine'
=>
array
(
'resolver'
=>
function
(
$container
)
'laravel.cache.apc_engine'
=>
array
(
'resolver'
=>
function
()
{
return
new
Cache\APC_Engine
;
}),
...
...
@@ -63,7 +74,7 @@ return array(
|--------------------------------------------------------------------------
*/
'laravel.memcache'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
'laravel.memcache'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
()
{
if
(
!
class_exists
(
'Memcache'
))
{
...
...
laravel/container.php
View file @
82045e20
...
...
@@ -41,6 +41,14 @@ class Container {
/**
* Register a dependency as a singleton.
*
* Singletons will only be instantiated the first time they are resolved. On subsequent
* requests for the object, the original instance will be returned.
*
* <code>
* // Register a dependency as a singleton
* $container->singleton('user', function() { return new User; })
* </code>
*
* @param string $name
* @param Closure $resolver
* @return void
...
...
@@ -53,6 +61,14 @@ class Container {
/**
* Register an instance as a singleton.
*
* This method allows you to register an already existing object instance with the
* container as a singleton instance.
*
* <code>
* // Register an object instance as a singleton in the container
* $container->instance('user', new User);
* </code>
*
* @param string $name
* @param mixed $instance
* @return void
...
...
laravel/form.php
View file @
82045e20
...
...
@@ -30,10 +30,10 @@ class Form {
* containing the request method. PUT and DELETE are not supported by HTML forms, so the
* hidden field will allow us to "spoof" PUT and DELETE requests.
*
* @param string $action
* @param string $method
* @param array $attributes
* @param bool $https
* @param string
$action
* @param string
$method
* @param array
$attributes
* @param bool
$https
* @return string
*/
public
static
function
open
(
$action
=
null
,
$method
=
'POST'
,
$attributes
=
array
(),
$https
=
false
)
...
...
@@ -69,13 +69,15 @@ class Form {
*
* If no action is specified, the current request URI will be used.
*
* @param string $action
* @param bool $https
* @param string
$action
* @param bool
$https
* @return string
*/
private
static
function
action
(
$action
,
$https
)
{
return
HTML
::
entities
(
URL
::
to
(((
is_null
(
$action
))
?
Request
::
uri
()
:
$action
),
$https
));
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
);
return
HTML
::
entities
(
$url
->
to
(((
is_null
(
$action
))
?
IoC
::
resolve
(
'laravel.request'
)
->
uri
()
:
$action
),
$https
));
}
/**
...
...
@@ -447,7 +449,7 @@ class Form {
*/
public
static
function
image
(
$url
,
$name
=
null
,
$attributes
=
array
())
{
$attributes
[
'src'
]
=
URL
::
to_asset
(
$url
);
$attributes
[
'src'
]
=
IoC
::
container
()
->
resolve
(
'laravel.url'
)
->
to_asset
(
$url
);
return
static
::
input
(
'image'
,
$name
,
null
,
$attributes
);
}
...
...
laravel/html.php
View file @
82045e20
...
...
@@ -24,7 +24,9 @@ class HTML {
*/
public
static
function
script
(
$url
,
$attributes
=
array
())
{
return
'<script type="text/javascript" src="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'></script>'
.
PHP_EOL
;
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
);
return
'<script type="text/javascript" src="'
.
static
::
entities
(
$url
->
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'></script>'
.
PHP_EOL
;
}
/**
...
...
@@ -40,7 +42,9 @@ class HTML {
$attributes
=
array_merge
(
$attributes
,
array
(
'rel'
=>
'stylesheet'
,
'type'
=>
'text/css'
));
return
'<link href="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
.
PHP_EOL
;
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
);
return
'<link href="'
.
static
::
entities
(
$url
->
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
.
PHP_EOL
;
}
/**
...
...
@@ -67,7 +71,9 @@ class HTML {
*/
public
static
function
link
(
$url
,
$title
,
$attributes
=
array
(),
$https
=
false
,
$asset
=
false
)
{
return
'<a href="'
.
static
::
entities
(
URL
::
to
(
$url
,
$https
,
$asset
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
.
static
::
entities
(
$title
)
.
'</a>'
;
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
);
return
'<a href="'
.
static
::
entities
(
$url
->
to
(
$url
,
$https
,
$asset
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
.
static
::
entities
(
$title
)
.
'</a>'
;
}
/**
...
...
@@ -130,7 +136,7 @@ class HTML {
*/
public
static
function
link_to_route
(
$name
,
$title
,
$parameters
=
array
(),
$attributes
=
array
(),
$https
=
false
)
{
return
static
::
link
(
URL
::
to_route
(
$name
,
$parameters
,
$https
),
$title
,
$attributes
);
return
static
::
link
(
IoC
::
resolve
(
'laravel.url'
)
->
to_route
(
$name
,
$parameters
,
$https
),
$title
,
$attributes
);
}
/**
...
...
@@ -189,7 +195,7 @@ class HTML {
{
$attributes
[
'alt'
]
=
static
::
entities
(
$alt
);
return
'<img src="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
;
return
'<img src="'
.
static
::
entities
(
IoC
::
resolve
(
'laravel.url'
)
->
to_asset
(
$url
))
.
'"'
.
static
::
attributes
(
$attributes
)
.
'>'
;
}
/**
...
...
laravel/inflector.php
View file @
82045e20
...
...
@@ -136,6 +136,14 @@ class Inflector {
/**
* Convert a word to its plural form.
*
* <code>
* // Returns "friends"
* Inflector::plural('friend');
*
* // Returns "children"
* Inflector::plural('child');
* </code>
*
* @param string $value
* @return string
*/
...
...
@@ -147,6 +155,14 @@ class Inflector {
/**
* Convert a word to its singular form.
*
* <code>
* // Returns "friend"
* Inflector::singular('friends');
*
* // Returns "child"
* Inflector::singular('children');
* </code>
*
* @param string $value
* @return string
*/
...
...
laravel/laravel.php
View file @
82045e20
...
...
@@ -45,11 +45,6 @@ Loader::bootstrap(Config::get('aliases'), array(APP_PATH.'libraries/', APP_PATH.
spl_autoload_register
(
array
(
'Laravel\\Loader'
,
'load'
));
// --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
IoC
::
bootstrap
(
Config
::
get
(
'dependencies'
));
// --------------------------------------------------------------
// Set the error reporting and display levels.
// --------------------------------------------------------------
...
...
@@ -98,21 +93,25 @@ register_shutdown_function(function() use ($error_dependencies)
// --------------------------------------------------------------
date_default_timezone_set
(
Config
::
get
(
'application.timezone'
));
// --------------------------------------------------------------
// Load the session.
// --------------------------------------------------------------
if
(
Config
::
get
(
'session.driver'
)
!=
''
)
Session
::
driver
()
->
start
(
Cookie
::
get
(
'laravel_session'
));
// --------------------------------------------------------------
// Load all of the core routing and response classes.
// --------------------------------------------------------------
require
SYS_PATH
.
'renderable'
.
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
;
// --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
IoC
::
bootstrap
(
Config
::
get
(
'dependencies'
));
// --------------------------------------------------------------
// Load the session.
// --------------------------------------------------------------
if
(
Config
::
get
(
'session.driver'
)
!=
''
)
Session
::
driver
()
->
start
(
Cookie
::
get
(
'laravel_session'
));
// --------------------------------------------------------------
// Load the packages that are in the auto-loaded packages array.
// --------------------------------------------------------------
...
...
@@ -133,6 +132,11 @@ $request = new Request($_SERVER);
// --------------------------------------------------------------
$request
->
input
=
new
Input
(
$request
,
$_GET
,
$_POST
,
$_COOKIE
,
$_FILES
);
// --------------------------------------------------------------
// Register the request as a singleton in the IoC container.
// --------------------------------------------------------------
IoC
::
container
()
->
instance
(
'laravel.request'
,
$request
);
// --------------------------------------------------------------
// Register the filters for the default module.
// --------------------------------------------------------------
...
...
laravel/redirect.php
View file @
82045e20
...
...
@@ -24,7 +24,7 @@ class Redirect extends Response {
*/
public
static
function
to
(
$url
,
$status
=
302
,
$method
=
'location'
,
$https
=
false
)
{
$url
=
URL
::
to
(
$url
,
$https
);
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
)
->
to
(
$url
,
$https
);
if
(
$method
==
'location'
)
{
...
...
@@ -93,14 +93,16 @@ class Redirect extends Response {
{
$parameters
=
(
isset
(
$parameters
[
0
]))
?
$parameters
[
0
]
:
array
();
$url
=
IoC
::
container
()
->
resolve
(
'laravel.url'
);
if
(
strpos
(
$method
,
'to_secure_'
)
===
0
)
{
return
static
::
to
(
URL
::
to_route
(
substr
(
$method
,
10
),
$parameters
,
true
));
return
static
::
to
(
$url
->
to_route
(
substr
(
$method
,
10
),
$parameters
,
true
));
}
if
(
strpos
(
$method
,
'to_'
)
===
0
)
{
return
static
::
to
(
URL
::
to_route
(
substr
(
$method
,
3
),
$parameters
));
return
static
::
to
(
$url
->
to_route
(
substr
(
$method
,
3
),
$parameters
));
}
throw
new
\Exception
(
"Method [
$method
] is not defined on the Redirect class."
);
...
...
laravel/renderable.php
deleted
100644 → 0
View file @
6a8aafc2
<?php
namespace
Laravel
;
interface
Renderable
{
/**
* Get the evaluated string contents of the object.
*
* @return string
*/
public
function
render
();
}
\ No newline at end of file
laravel/response.php
View file @
82045e20
<?php
namespace
Laravel
;
interface
Renderable
{
/**
* Get the evaluated string contents of the object.
*
* @return string
*/
public
function
render
();
}
class
Response
implements
Renderable
{
/**
...
...
laravel/url.php
View file @
82045e20
...
...
@@ -11,7 +11,7 @@ class URL {
* @param bool $https
* @return string
*/
public
static
function
to
(
$url
=
''
,
$https
=
false
)
public
function
to
(
$url
=
''
,
$https
=
false
)
{
if
(
filter_var
(
$url
,
FILTER_VALIDATE_URL
)
!==
false
)
return
$url
;
...
...
@@ -31,9 +31,9 @@ class URL {
* @param string $url
* @return string
*/
public
static
function
to_secure
(
$url
=
''
)
public
function
to_secure
(
$url
=
''
)
{
return
static
::
to
(
$url
,
true
);
return
$this
->
to
(
$url
,
true
);
}
/**
...
...
@@ -44,9 +44,9 @@ class URL {
* @param string $url
* @return string
*/
public
static
function
to_asset
(
$url
)
public
function
to_asset
(
$url
)
{
return
str_replace
(
'index.php/'
,
''
,
static
::
to
(
$url
,
Request
::
active
(
)
->
is_secure
()));
return
str_replace
(
'index.php/'
,
''
,
$this
->
to
(
$url
,
IoC
::
resolve
(
'laravel.request'
)
->
is_secure
()));
}
/**
...
...
@@ -57,10 +57,10 @@ class URL {
*
* <code>
* // Generate a URL for the "profile" named route
* $url =
URL::
to_route('profile');
* $url =
$url->
to_route('profile');
*
* // Generate a URL for the "profile" named route with parameters.
* $url =
URL::
to_route('profile', array('fred'));
* $url =
$url->
to_route('profile', array('fred'));
* </code>
*
* @param string $name
...
...
@@ -68,7 +68,7 @@ class URL {
* @param bool $https
* @return string
*/
public
static
function
to_route
(
$name
,
$parameters
=
array
(),
$https
=
false
)
public
function
to_route
(
$name
,
$parameters
=
array
(),
$https
=
false
)
{
if
(
!
is_null
(
$route
=
Routing\Finder
::
find
(
$name
,
Routing\Loader
::
all
())))
{
...
...
@@ -83,7 +83,7 @@ class URL {
$uri
=
str_replace
(
array
(
'/(:any?)'
,
'/(:num?)'
),
''
,
$uri
);
return
static
::
to
(
$uri
,
$https
);
return
$this
->
to
(
$uri
,
$https
);
}
throw
new
\Exception
(
"Error generating named route for route [
$name
]. Route is not defined."
);
...
...
@@ -94,16 +94,16 @@ class URL {
*
* <code>
* // Generate a HTTPS URL for the "profile" named route
* $url =
URL::
to_secure_route('profile');
* $url =
$url->
to_secure_route('profile');
* </code>
*
* @param string $name
* @param array $parameters
* @return string
*/
public
static
function
to_secure_route
(
$name
,
$parameters
=
array
())
public
function
to_secure_route
(
$name
,
$parameters
=
array
())
{
return
static
::
to_route
(
$name
,
$parameters
,
true
);
return
$this
->
to_route
(
$name
,
$parameters
,
true
);
}
/**
...
...
@@ -111,17 +111,17 @@ class URL {
*
* <code>
* // Returns "my-first-post"
* $slug =
URL::
slug('My First Post!!');
* $slug =
$url->
slug('My First Post!!');
*
* // Returns "my_first_post"
* $slug =
URL::
slug('My First Post!!', '_');
* $slug =
$url->
slug('My First Post!!', '_');
* </code>
*
* @param string $title
* @param string $separator
* @return string
*/
public
static
function
slug
(
$title
,
$separator
=
'-'
)
public
function
slug
(
$title
,
$separator
=
'-'
)
{
$title
=
Str
::
ascii
(
$title
);
...
...
@@ -139,27 +139,27 @@ class URL {
*
* <code>
* // Generate a URL for the "profile" named route
* $url =
URL::
to_profile();
* $url =
$url->
to_profile();
*
* // Generate a URL for the "profile" named route using HTTPS
* $url =
URL::
to_secure_profile();
* $url =
$url->
to_secure_profile();
*
* // Generate a URL for the "profile" named route with parameters.
* $url =
URL::
to_profile(array('fred'));
* $url =
$url->
to_profile(array('fred'));
* </code>
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
$parameters
=
(
isset
(
$parameters
[
0
]))
?
$parameters
[
0
]
:
array
();
if
(
strpos
(
$method
,
'to_secure_'
)
===
0
)
{
return
static
::
to_route
(
substr
(
$method
,
10
),
$parameters
,
true
);
return
$this
->
to_route
(
substr
(
$method
,
10
),
$parameters
,
true
);
}
if
(
strpos
(
$method
,
'to_'
)
===
0
)
{
return
static
::
to_route
(
substr
(
$method
,
3
),
$parameters
);
return
$this
->
to_route
(
substr
(
$method
,
3
),
$parameters
);
}
throw
new
\Exception
(
"Method [
$method
] is not defined on the URL class."
);
...
...
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