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
6281c8c3
Commit
6281c8c3
authored
Sep 03, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring for dependency injection.
parent
893bb838
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
122 additions
and
76 deletions
+122
-76
container.php
laravel/config/container.php
+26
-19
factory.php
laravel/database/connector/factory.php
+1
-1
manager.php
laravel/database/manager.php
+19
-8
request.php
laravel/request.php
+25
-1
router.php
laravel/routing/router.php
+13
-0
authenticator.php
laravel/security/authenticator.php
+3
-6
crypter.php
laravel/security/crypter.php
+2
-20
validator.php
laravel/validation/validator.php
+33
-21
No files found.
laravel/config/container.php
View file @
6281c8c3
...
@@ -8,6 +8,12 @@ return array(
...
@@ -8,6 +8,12 @@ return array(
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
*/
*/
'laravel.auth'
=>
array
(
'resolver'
=>
function
(
$container
)
{
return
new
Security\Authenticator
(
$container
->
resolve
(
'laravel.session'
),
$container
->
resolve
(
'laravel.hasher'
));
}),
'laravel.config'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
'laravel.config'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
{
$paths
=
array
(
SYS_CONFIG_PATH
,
CONFIG_PATH
);
$paths
=
array
(
SYS_CONFIG_PATH
,
CONFIG_PATH
);
...
@@ -21,6 +27,14 @@ return array(
...
@@ -21,6 +27,14 @@ return array(
}),
}),
'laravel.crypter'
=>
array
(
'resolver'
=>
function
(
$container
)
{
$key
=
$container
->
resolve
(
'laravel.config'
)
->
get
(
'application.key'
);
return
new
Security\Crypter
(
MCRYPT_RIJNDAEL_256
,
'cbc'
,
$key
);
}),
'laravel.cookie'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
()
'laravel.cookie'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
()
{
{
return
new
Cookie
(
$_COOKIE
);
return
new
Cookie
(
$_COOKIE
);
...
@@ -59,6 +73,12 @@ return array(
...
@@ -59,6 +73,12 @@ return array(
}),
}),
'laravel.hasher'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
return
new
Security\Hashing\BCrypt
(
10
,
false
);
}),
'laravel.html'
=>
array
(
'resolver'
=>
function
(
$container
)
'laravel.html'
=>
array
(
'resolver'
=>
function
(
$container
)
{
{
return
new
HTML
(
$container
->
resolve
(
'laravel.url'
),
$container
->
resolve
(
'laravel.config'
)
->
get
(
'application.encoding'
));
return
new
HTML
(
$container
->
resolve
(
'laravel.url'
),
$container
->
resolve
(
'laravel.config'
)
->
get
(
'application.encoding'
));
...
@@ -158,6 +178,12 @@ return array(
...
@@ -158,6 +178,12 @@ return array(
}),
}),
'laravel.validator'
=>
array
(
'resolver'
=>
function
(
$container
)
{
return
new
Validation\Validator
(
$container
->
resolve
(
'laravel.lang'
));
}),
'laravel.view'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
'laravel.view'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
{
require_once
SYS_PATH
.
'view'
.
EXT
;
require_once
SYS_PATH
.
'view'
.
EXT
;
...
@@ -171,25 +197,6 @@ return array(
...
@@ -171,25 +197,6 @@ return array(
return
new
View_Composer
(
$container
->
resolve
(
'laravel.application'
),
require
APP_PATH
.
'composers'
.
EXT
);
return
new
View_Composer
(
$container
->
resolve
(
'laravel.application'
),
require
APP_PATH
.
'composers'
.
EXT
);
}),
}),
/*
|--------------------------------------------------------------------------
| Laravel Security Components
|--------------------------------------------------------------------------
*/
'laravel.security.auth'
=>
array
(
'resolver'
=>
function
(
$container
)
{
$hasher
=
$container
->
resolve
(
'laravel.security.hashing.engine'
);
return
new
Security\Auth
(
Session\Manager
::
driver
(),
$hasher
);
}),
'laravel.security.hashing.engine'
=>
array
(
'resolver'
=>
function
()
{
return
new
Security\Hashing\BCrypt
(
10
,
false
);
}),
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
| Laravel Cookie Session Components
| Laravel Cookie Session Components
...
...
laravel/database/connector/factory.php
View file @
6281c8c3
...
@@ -8,7 +8,7 @@ class Factory {
...
@@ -8,7 +8,7 @@ class Factory {
* @param array $config
* @param array $config
* @return Connector
* @return Connector
*/
*/
public
static
function
make
(
$config
)
public
function
make
(
$config
)
{
{
if
(
isset
(
$config
[
'connector'
]))
return
new
Callback
;
if
(
isset
(
$config
[
'connector'
]))
return
new
Callback
;
...
...
laravel/database/manager.php
View file @
6281c8c3
...
@@ -9,34 +9,45 @@ class Manager {
...
@@ -9,34 +9,45 @@ class Manager {
*/
*/
public
$connections
=
array
();
public
$connections
=
array
();
/**
* The connector factory instance.
*
* @var Connector\Factory
*/
protected
$factory
;
/**
/**
* The database connection configurations.
* The database connection configurations.
*
*
* @var array
* @var array
*/
*/
pr
ivate
$config
;
pr
otected
$config
;
/**
/**
* The default database connection name.
* The default database connection name.
*
*
* @var string
* @var string
*/
*/
pr
ivate
$default
;
pr
otected
$default
;
/**
/**
* Create a new database manager instance.
* Create a new database manager instance.
*
*
* @param Connector\Factory $factory
* @param array $config
* @param string $default
* @param string $default
* @return void
*/
*/
public
function
__construct
(
$config
,
$default
)
public
function
__construct
(
Connector\Factory
$factory
,
$config
,
$default
)
{
{
$this
->
config
=
$config
;
$this
->
config
=
$config
;
$this
->
factory
=
$factory
;
$this
->
default
=
$default
;
$this
->
default
=
$default
;
}
}
/**
/**
* Get a database connection. If no database name is specified, the default
* Get a database connection. If no database name is specified, the default
* connection will be returned as defined in the d
b
configuration file.
* connection will be returned as defined in the d
atabase
configuration file.
*
*
* Note: Database connections are managed as singletons.
* Note: Database connections are managed as singletons.
*
*
...
@@ -54,7 +65,7 @@ class Manager {
...
@@ -54,7 +65,7 @@ class Manager {
throw
new
\Exception
(
"Database connection [
$connection
] is not defined."
);
throw
new
\Exception
(
"Database connection [
$connection
] is not defined."
);
}
}
$connector
=
Connector\Factory
::
make
(
$this
->
config
[
$connection
]);
$connector
=
$this
->
factory
->
make
(
$this
->
config
[
$connection
]);
static
::
$connections
[
$connection
]
=
new
Connection
(
$connection
,
$this
->
config
[
$connection
],
$connector
);
static
::
$connections
[
$connection
]
=
new
Connection
(
$connection
,
$this
->
config
[
$connection
],
$connector
);
}
}
...
...
laravel/request.php
View file @
6281c8c3
...
@@ -30,6 +30,16 @@ class Request {
...
@@ -30,6 +30,16 @@ class Request {
*/
*/
private
$url
;
private
$url
;
/**
* The request URI.
*
* After determining the URI once, this property will be set and returned
* on subsequent requests for the URI.
*
* @var string
*/
private
$uri
;
/**
/**
* Create a new request instance.
* Create a new request instance.
*
*
...
@@ -59,6 +69,8 @@ class Request {
...
@@ -59,6 +69,8 @@ class Request {
*/
*/
public
function
uri
()
public
function
uri
()
{
{
if
(
!
is_null
(
$this
->
uri
))
return
$this
->
uri
;
if
(
isset
(
$this
->
server
[
'PATH_INFO'
]))
if
(
isset
(
$this
->
server
[
'PATH_INFO'
]))
{
{
$uri
=
$this
->
server
[
'PATH_INFO'
];
$uri
=
$this
->
server
[
'PATH_INFO'
];
...
@@ -79,7 +91,19 @@ class Request {
...
@@ -79,7 +91,19 @@ class Request {
$uri
=
(
strpos
(
$uri
,
$value
)
===
0
)
?
substr
(
$uri
,
strlen
(
$value
))
:
$uri
;
$uri
=
(
strpos
(
$uri
,
$value
)
===
0
)
?
substr
(
$uri
,
strlen
(
$value
))
:
$uri
;
}
}
return
((
$uri
=
trim
(
$uri
,
'/'
))
==
''
)
?
'/'
:
$uri
;
return
$this
->
uri
=
((
$uri
=
trim
(
$uri
,
'/'
))
==
''
)
?
'/'
:
$uri
;
}
/**
* Get the request format.
*
* The format is determined by essentially taking the "extension" of the URI.
*
* @return string
*/
public
function
format
()
{
return
((
$extension
=
pathinfo
(
$this
->
uri
(),
PATHINFO_EXTENSION
))
!==
''
)
?
$extension
:
'html'
;
}
}
/**
/**
...
...
laravel/routing/router.php
View file @
6281c8c3
...
@@ -101,6 +101,8 @@ class Router {
...
@@ -101,6 +101,8 @@ class Router {
{
{
foreach
(
explode
(
', '
,
$keys
)
as
$key
)
foreach
(
explode
(
', '
,
$keys
)
as
$key
)
{
{
if
(
!
is_null
(
$formats
=
$this
->
provides
(
$callback
)))
$key
.=
'(\.('
.
implode
(
'|'
,
$formats
)
.
'))?'
;
if
(
preg_match
(
'#^'
.
$this
->
translate_wildcards
(
$key
)
.
'$#'
,
$destination
))
if
(
preg_match
(
'#^'
.
$this
->
translate_wildcards
(
$key
)
.
'$#'
,
$destination
))
{
{
return
$this
->
request
->
route
=
new
Route
(
$keys
,
$callback
,
$this
->
parameters
(
$destination
,
$key
),
$this
->
controller_path
);
return
$this
->
request
->
route
=
new
Route
(
$keys
,
$callback
,
$this
->
parameters
(
$destination
,
$key
),
$this
->
controller_path
);
...
@@ -172,6 +174,17 @@ class Router {
...
@@ -172,6 +174,17 @@ class Router {
}
}
}
}
/**
* Get the request formats for which the route provides responses.
*
* @param mixed $callback
* @return array
*/
protected
function
provides
(
$callback
)
{
return
(
is_array
(
$callback
)
and
isset
(
$callback
[
'provides'
]))
?
explode
(
', '
,
$callback
[
'provides'
])
:
null
;
}
/**
/**
* Translate route URI wildcards into actual regular expressions.
* Translate route URI wildcards into actual regular expressions.
*
*
...
...
laravel/security/authenticator.php
View file @
6281c8c3
<?php
namespace
Laravel\Security
;
<?php
namespace
Laravel\Security
;
use
Laravel\IoC
;
use
Laravel\IoC
;
use
Laravel\Config
;
use
Laravel\Session\Driver
;
use
Laravel\Session\Driver
;
class
Authenticator
{
class
Authenticator
{
...
@@ -53,15 +52,13 @@ class Authenticator {
...
@@ -53,15 +52,13 @@ class Authenticator {
}
}
/**
/**
* Create a new Auth class instance.
* Get an authenticator instance from the IoC container.
*
* If no session driver or hasher is provided, the default implementations will be used.
*
*
* @return Auth
* @return Auth
enticator
*/
*/
public
static
function
make
()
public
static
function
make
()
{
{
return
IoC
::
container
()
->
resolve
(
'laravel.
security.
auth'
);
return
IoC
::
container
()
->
resolve
(
'laravel.auth'
);
}
}
/**
/**
...
...
laravel/security/crypter.php
View file @
6281c8c3
<?php
namespace
Laravel\Security
;
<?php
namespace
Laravel\Security
;
use
Laravel\
Config
;
use
Laravel\
IoC
;
class
Crypter
{
class
Crypter
{
...
@@ -33,7 +33,7 @@ class Crypter {
...
@@ -33,7 +33,7 @@ class Crypter {
* @param string $key
* @param string $key
* @return void
* @return void
*/
*/
public
function
__construct
(
$cipher
=
MCRYPT_RIJNDAEL_256
,
$mode
=
'cbc'
,
$key
=
null
)
public
function
__construct
(
$cipher
,
$mode
,
$key
)
{
{
$this
->
cipher
=
$cipher
;
$this
->
cipher
=
$cipher
;
$this
->
mode
=
$mode
;
$this
->
mode
=
$mode
;
...
@@ -45,24 +45,6 @@ class Crypter {
...
@@ -45,24 +45,6 @@ class Crypter {
}
}
}
}
/**
* Create a new Crypter instance.
*
* Any cipher and mode supported by Mcrypt may be specified. For more information regarding
* the supported ciphers and modes, check out: http://php.net/manual/en/mcrypt.ciphers.php
*
* By default, the AES-256 cipher will be used in CBC mode.
*
* @param string $cipher
* @param string $mode
* @param string $key
* @return Crypt
*/
public
static
function
make
(
$cipher
=
MCRYPT_RIJNDAEL_256
,
$mode
=
'cbc'
,
$key
=
null
)
{
return
new
static
(
$cipher
,
$mode
,
(
is_null
(
$key
))
?
Config
::
get
(
'application.key'
)
:
$key
);
}
/**
/**
* Encrypt a string using Mcrypt.
* Encrypt a string using Mcrypt.
*
*
...
...
laravel/validation/validator.php
View file @
6281c8c3
<?php
namespace
Laravel\Validation
;
<?php
namespace
Laravel\Validation
;
use
Laravel\IoC
;
use
Laravel\Str
;
use
Laravel\Lang
;
use
Laravel\Lang
;
use
Laravel\Database\Manager
as
DB
;
class
Validator
{
class
Validator
{
...
@@ -64,21 +65,12 @@ class Validator {
...
@@ -64,21 +65,12 @@ class Validator {
/**
/**
* Create a new validator instance.
* Create a new validator instance.
*
*
* @param array $attributes
* @param Lang $lang
* @param array $rules
* @param array $messages
* @return void
* @return void
*/
*/
public
function
__construct
(
$attributes
,
$rules
,
$messages
=
array
())
public
function
__construct
(
Lang
$lang
)
{
foreach
(
$rules
as
$key
=>
&
$rule
)
{
{
$rule
=
(
is_string
(
$rule
))
?
explode
(
'|'
,
$rule
)
:
$rule
;
$this
->
lang
=
$lang
;
}
$this
->
attributes
=
$attributes
;
$this
->
messages
=
$messages
;
$this
->
rules
=
$rules
;
}
}
/**
/**
...
@@ -91,7 +83,27 @@ class Validator {
...
@@ -91,7 +83,27 @@ class Validator {
*/
*/
public
static
function
make
(
$attributes
,
$rules
,
$messages
=
array
())
public
static
function
make
(
$attributes
,
$rules
,
$messages
=
array
())
{
{
return
new
static
(
$attributes
,
$rules
,
$messages
);
return
IoC
::
resolve
(
'laravel.validator'
)
->
of
(
$attributes
,
$rules
,
$messages
);
}
/**
* Set the attributes, rules, and messages for the validator.
*
* @param array $attributes
* @param array $rules
* @param array $messages
* @return Validator
*/
public
function
of
(
$attributes
,
$rules
,
$messages
=
array
())
{
foreach
(
$rules
as
$key
=>
&
$rule
)
{
$rule
=
(
is_string
(
$rule
))
?
explode
(
'|'
,
$rule
)
:
$rule
;
}
$this
->
attributes
=
$attributes
;
$this
->
messages
=
$messages
;
$this
->
rules
=
$rules
;
}
}
/**
/**
...
@@ -146,9 +158,9 @@ class Validator {
...
@@ -146,9 +158,9 @@ class Validator {
if
(
!
$this
->
$validator
(
$attribute
,
$parameters
))
if
(
!
$this
->
$validator
(
$attribute
,
$parameters
))
{
{
$message
=
$this
->
format_message
(
$this
->
get_message
(
$attribute
,
$rule
);
$message
=
$this
->
format_message
(
$this
->
get_message
(
$attribute
,
$rule
)
)
;
$this
->
errors
->
add
(
$attribute
,
$message
,
$attribute
,
$rule
,
$parameters
)
)
;
$this
->
errors
->
add
(
$attribute
,
$message
,
$attribute
,
$rule
,
$parameters
);
}
}
}
}
...
@@ -322,7 +334,7 @@ class Validator {
...
@@ -322,7 +334,7 @@ class Validator {
{
{
if
(
!
isset
(
$parameters
[
1
]))
$parameters
[
1
]
=
$attribute
;
if
(
!
isset
(
$parameters
[
1
]))
$parameters
[
1
]
=
$attribute
;
if
(
is_null
(
$this
->
connection
))
$this
->
connection
=
DB
::
connection
();
if
(
is_null
(
$this
->
connection
))
$this
->
connection
=
IoC
::
resolve
(
'laravel.database'
)
->
connection
();
return
$this
->
connection
->
table
(
$parameters
[
0
])
->
where
(
$parameters
[
1
],
'='
,
$this
->
attributes
[
$attribute
])
->
count
()
==
0
;
return
$this
->
connection
->
table
(
$parameters
[
0
])
->
where
(
$parameters
[
1
],
'='
,
$this
->
attributes
[
$attribute
])
->
count
()
==
0
;
}
}
...
@@ -450,15 +462,15 @@ class Validator {
...
@@ -450,15 +462,15 @@ class Validator {
}
}
else
else
{
{
$message
=
Lang
::
line
(
'validation.'
.
$rule
)
->
get
(
$this
->
language
);
$message
=
$this
->
lang
->
line
(
'validation.'
.
$rule
)
->
get
(
$this
->
language
);
// For "size" rules that are validating strings or files, we need to adjust
// For "size" rules that are validating strings or files, we need to adjust
// the default error message for the appropriate type.
// the default error message for the appropriate type.
if
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
$this
->
has_rule
(
$attribute
,
$this
->
numeric_rules
))
if
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
$this
->
has_rule
(
$attribute
,
$this
->
numeric_rules
))
{
{
return
(
array_key_exists
(
$attribute
,
$_FILES
))
return
(
array_key_exists
(
$attribute
,
$_FILES
))
?
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.kilobytes'
)
->
get
(
$this
->
language
)
.
'.'
?
rtrim
(
$message
,
'.'
)
.
' '
.
$this
->
lang
->
line
(
'validation.kilobytes'
)
->
get
(
$this
->
language
)
.
'.'
:
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.characters'
)
->
get
(
$this
->
language
)
.
'.'
;
:
rtrim
(
$message
,
'.'
)
.
' '
.
$this
->
lang
->
line
(
'validation.characters'
)
->
get
(
$this
->
language
)
.
'.'
;
}
}
return
$message
;
return
$message
;
...
@@ -476,7 +488,7 @@ class Validator {
...
@@ -476,7 +488,7 @@ class Validator {
*/
*/
protected
function
format_message
(
$message
,
$attribute
,
$rule
,
$parameters
)
protected
function
format_message
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
{
$display
=
Lang
::
line
(
'attributes.'
.
$attribute
)
->
get
(
$this
->
language
,
str_replace
(
'_'
,
' '
,
$attribute
));
$display
=
$this
->
lang
->
line
(
'attributes.'
.
$attribute
)
->
get
(
$this
->
language
,
str_replace
(
'_'
,
' '
,
$attribute
));
$message
=
str_replace
(
':attribute'
,
$display
,
$message
);
$message
=
str_replace
(
':attribute'
,
$display
,
$message
);
...
...
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