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
66af3542
Commit
66af3542
authored
Aug 30, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored the lang class for dependency injection.
parent
f113b5c8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
23 deletions
+46
-23
container.php
laravel/config/container.php
+6
-0
lang.php
laravel/lang.php
+40
-23
No files found.
laravel/config/container.php
View file @
66af3542
...
...
@@ -51,6 +51,12 @@ return array(
}),
'laravel.lang'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
(
$container
)
{
return
new
Lang
(
$container
->
resolve
(
'laravel.config'
)
->
get
(
'application.language'
),
array
(
SYS_LANG_PATH
,
LANG_PATH
));
}),
'laravel.package'
=>
array
(
'singleton'
=>
true
,
'resolver'
=>
function
()
{
return
new
Package
;
...
...
laravel/lang.php
View file @
66af3542
...
...
@@ -9,45 +9,58 @@ class Lang {
*
* @var array
*/
p
ublic
static
$lines
=
array
();
p
rivate
static
$lines
=
array
();
/**
* The
key of the line that is being requested
.
* The
default language being used by the application
.
*
* @var string
*/
p
ublic
$key
;
p
rivate
$language
;
/**
* The language the line should be returned in.
* The paths containing the language files.
*
* @var array
*/
private
$paths
;
/**
* The key of the language line being retrieved.
*
* @var string
*/
p
ublic
$language
;
p
rivate
$key
;
/**
* The
place-holder replacements
.
* The
replacements that should be made on the language line
.
*
* @var array
*/
public
$replacements
=
array
();
private
$replacements
;
/**
* The language of the line being retrieved.
*
* @var string
*/
private
$line_language
;
/**
* Create a new Lang instance.
*
* @param string $
key
* @param array $
replacement
s
* @param string $
language
* @param array $
path
s
* @return void
*/
p
rivate
function
__construct
(
$key
,
$replacements
=
array
()
)
p
ublic
function
__construct
(
$language
,
$paths
)
{
$this
->
key
=
$key
;
$this
->
replacements
=
$replacements
;
$this
->
language
=
Config
::
get
(
'application.language'
);
$this
->
paths
=
$paths
;
$this
->
language
=
$language
;
}
/**
*
Create a new Lang instanc
e.
*
Begin retrieving a new language lin
e.
*
* Language lines are retrieved using "dot" notation. So, asking for the "messages.required" langauge
* line would return the "required" line from the "messages" language file.
...
...
@@ -56,9 +69,13 @@ class Lang {
* @param array $replacements
* @return Lang
*/
public
static
function
line
(
$key
,
$replacements
=
array
())
public
function
line
(
$key
,
$replacements
=
array
())
{
return
new
static
(
$key
,
$replacements
);
$this
->
key
=
$key
;
$this
->
replacements
=
$replacements
;
$this
->
line_language
=
$this
->
language
;
return
$this
;
}
/**
...
...
@@ -78,7 +95,7 @@ class Lang {
return
(
$default
instanceof
\Closure
)
?
call_user_func
(
$default
)
:
$default
;
}
$line
=
Arr
::
get
(
static
::
$lines
[
$this
->
language
.
$file
],
$line
,
$default
);
$line
=
Arr
::
get
(
static
::
$lines
[
$this
->
l
ine_l
anguage
.
$file
],
$line
,
$default
);
foreach
(
$this
->
replacements
as
$key
=>
$value
)
{
...
...
@@ -118,13 +135,13 @@ class Lang {
*/
private
function
load
(
$file
)
{
if
(
isset
(
static
::
$lines
[
$this
->
language
.
$file
]))
return
;
if
(
isset
(
static
::
$lines
[
$this
->
l
ine_l
anguage
.
$file
]))
return
;
$language
=
array
();
foreach
(
array
(
SYS_LANG_PATH
,
LANG_PATH
)
as
$directory
)
foreach
(
$this
->
paths
as
$directory
)
{
if
(
file_exists
(
$path
=
$directory
.
$this
->
language
.
'/'
.
$file
.
EXT
))
if
(
file_exists
(
$path
=
$directory
.
$this
->
l
ine_l
anguage
.
'/'
.
$file
.
EXT
))
{
$language
=
array_merge
(
$language
,
require
$path
);
}
...
...
@@ -132,10 +149,10 @@ class Lang {
if
(
count
(
$language
)
>
0
)
{
static
::
$lines
[
$this
->
language
.
$file
]
=
$language
;
static
::
$lines
[
$this
->
l
ine_l
anguage
.
$file
]
=
$language
;
}
return
isset
(
static
::
$lines
[
$this
->
language
.
$file
]);
return
isset
(
static
::
$lines
[
$this
->
l
ine_l
anguage
.
$file
]);
}
/**
...
...
@@ -148,7 +165,7 @@ class Lang {
*/
public
function
in
(
$language
)
{
$this
->
l
anguage
=
$
language
;
$this
->
l
ine_language
=
$line_
language
;
return
$this
;
}
...
...
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