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
Hide 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(
|--------------------------------------------------------------------------
*/
'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
)
{
$paths
=
array
(
SYS_CONFIG_PATH
,
CONFIG_PATH
);
...
...
@@ -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
()
{
return
new
Cookie
(
$_COOKIE
);
...
...
@@ -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
)
{
return
new
HTML
(
$container
->
resolve
(
'laravel.url'
),
$container
->
resolve
(
'laravel.config'
)
->
get
(
'application.encoding'
));
...
...
@@ -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
)
{
require_once
SYS_PATH
.
'view'
.
EXT
;
...
...
@@ -171,25 +197,6 @@ return array(
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/database/connector/factory.php
View file @
6281c8c3
...
...
@@ -8,7 +8,7 @@ class Factory {
* @param array $config
* @return Connector
*/
public
static
function
make
(
$config
)
public
function
make
(
$config
)
{
if
(
isset
(
$config
[
'connector'
]))
return
new
Callback
;
...
...
laravel/database/manager.php
View file @
6281c8c3
...
...
@@ -9,34 +9,45 @@ class Manager {
*/
public
$connections
=
array
();
/**
* The connector factory instance.
*
* @var Connector\Factory
*/
protected
$factory
;
/**
* The database connection configurations.
*
* @var array
*/
pr
ivate
$config
;
pr
otected
$config
;
/**
* The default database connection name.
*
* @var string
*/
pr
ivate
$default
;
pr
otected
$default
;
/**
* Create a new database manager instance.
*
* @param string $default
* @param Connector\Factory $factory
* @param array $config
* @param string $default
* @return void
*/
public
function
__construct
(
$config
,
$default
)
public
function
__construct
(
Connector\Factory
$factory
,
$config
,
$default
)
{
$this
->
config
=
$config
;
$this
->
factory
=
$factory
;
$this
->
default
=
$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.
*
...
...
@@ -54,7 +65,7 @@ class Manager {
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
);
}
...
...
@@ -67,8 +78,8 @@ class Manager {
*
* This method primarily serves as a short-cut to the $connection->table() method.
*
* @param string $table
* @param string $connection
* @param string
$table
* @param string
$connection
* @return Database\Query
*/
public
function
table
(
$table
,
$connection
=
null
)
...
...
laravel/request.php
View file @
6281c8c3
...
...
@@ -30,6 +30,16 @@ class Request {
*/
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.
*
...
...
@@ -59,6 +69,8 @@ class Request {
*/
public
function
uri
()
{
if
(
!
is_null
(
$this
->
uri
))
return
$this
->
uri
;
if
(
isset
(
$this
->
server
[
'PATH_INFO'
]))
{
$uri
=
$this
->
server
[
'PATH_INFO'
];
...
...
@@ -79,7 +91,19 @@ class Request {
$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 {
{
foreach
(
explode
(
', '
,
$keys
)
as
$key
)
{
if
(
!
is_null
(
$formats
=
$this
->
provides
(
$callback
)))
$key
.=
'(\.('
.
implode
(
'|'
,
$formats
)
.
'))?'
;
if
(
preg_match
(
'#^'
.
$this
->
translate_wildcards
(
$key
)
.
'$#'
,
$destination
))
{
return
$this
->
request
->
route
=
new
Route
(
$keys
,
$callback
,
$this
->
parameters
(
$destination
,
$key
),
$this
->
controller_path
);
...
...
@@ -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.
*
...
...
laravel/security/authenticator.php
View file @
6281c8c3
<?php
namespace
Laravel\Security
;
use
Laravel\IoC
;
use
Laravel\Config
;
use
Laravel\Session\Driver
;
class
Authenticator
{
...
...
@@ -53,15 +52,13 @@ class Authenticator {
}
/**
* Create a new Auth class instance.
*
* If no session driver or hasher is provided, the default implementations will be used.
* Get an authenticator instance from the IoC container.
*
* @return Auth
* @return Auth
enticator
*/
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
;
use
Laravel\
Config
;
use
Laravel\
IoC
;
class
Crypter
{
...
...
@@ -33,7 +33,7 @@ class Crypter {
* @param string $key
* @return void
*/
public
function
__construct
(
$cipher
=
MCRYPT_RIJNDAEL_256
,
$mode
=
'cbc'
,
$key
=
null
)
public
function
__construct
(
$cipher
,
$mode
,
$key
)
{
$this
->
cipher
=
$cipher
;
$this
->
mode
=
$mode
;
...
...
@@ -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.
*
...
...
laravel/validation/validator.php
View file @
6281c8c3
<?php
namespace
Laravel\Validation
;
use
Laravel\IoC
;
use
Laravel\Str
;
use
Laravel\Lang
;
use
Laravel\Database\Manager
as
DB
;
class
Validator
{
...
...
@@ -64,21 +65,12 @@ class Validator {
/**
* Create a new validator instance.
*
* @param array $attributes
* @param array $rules
* @param array $messages
* @param Lang $lang
* @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
->
attributes
=
$attributes
;
$this
->
messages
=
$messages
;
$this
->
rules
=
$rules
;
$this
->
lang
=
$lang
;
}
/**
...
...
@@ -91,7 +83,27 @@ class Validator {
*/
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 {
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 {
{
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
;
}
...
...
@@ -450,15 +462,15 @@ class Validator {
}
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
// the default error message for the appropriate type.
if
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
$this
->
has_rule
(
$attribute
,
$this
->
numeric_rules
))
{
return
(
array_key_exists
(
$attribute
,
$_FILES
))
?
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.kilobytes'
)
->
get
(
$this
->
language
)
.
'.'
:
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.characters'
)
->
get
(
$this
->
language
)
.
'.'
;
?
rtrim
(
$message
,
'.'
)
.
' '
.
$this
->
lang
->
line
(
'validation.kilobytes'
)
->
get
(
$this
->
language
)
.
'.'
:
rtrim
(
$message
,
'.'
)
.
' '
.
$this
->
lang
->
line
(
'validation.characters'
)
->
get
(
$this
->
language
)
.
'.'
;
}
return
$message
;
...
...
@@ -476,7 +488,7 @@ class Validator {
*/
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
);
...
...
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