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
adb58347
Commit
adb58347
authored
Jun 22, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Config::has and default value for Config::get.
parent
fcdcc656
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
12 deletions
+29
-12
config.php
system/config.php
+29
-12
No files found.
system/config.php
View file @
adb58347
...
@@ -9,35 +9,57 @@ class Config {
...
@@ -9,35 +9,57 @@ class Config {
*/
*/
private
static
$items
=
array
();
private
static
$items
=
array
();
/**
* Determine if a configuration item exists.
*
* @param string $key
* @return bool
*/
public
static
function
has
(
$key
)
{
return
!
is_null
(
static
::
get
(
$key
));
}
/**
/**
* Get a configuration item.
* Get a configuration item.
*
*
* @param string $key
* @param string $key
* @param string $default
* @return mixed
* @return mixed
*/
*/
public
static
function
get
(
$key
)
public
static
function
get
(
$key
,
$default
=
null
)
{
{
// -----------------------------------------------------
// -----------------------------------------------------
// If a dot is not present, we will just return the
// If a dot is not present, we will just return the
// entire configuration array.
// entire configuration array.
//
// If the configuration file does not exist, the default
// value will be returned.
// -----------------------------------------------------
// -----------------------------------------------------
if
(
strpos
(
$key
,
'.'
)
===
false
)
if
(
strpos
(
$key
,
'.'
)
===
false
)
{
{
static
::
load
(
$key
);
static
::
load
(
$key
);
return
static
::
$items
[
$key
]
;
return
(
array_key_exists
(
$key
,
static
::
$items
))
?
static
::
$items
[
$key
]
:
$default
;
}
}
list
(
$file
,
$key
)
=
static
::
parse
(
$key
);
list
(
$file
,
$key
)
=
static
::
parse
(
$key
);
static
::
load
(
$file
);
static
::
load
(
$file
);
if
(
array_key_exists
(
$key
,
static
::
$items
[
$file
]))
// -----------------------------------------------------
// If the file doesn't exist, return the default.
// -----------------------------------------------------
if
(
!
array_key_exists
(
$file
,
static
::
$items
))
{
{
return
static
::
$items
[
$file
][
$key
]
;
return
$default
;
}
}
throw
new
\Exception
(
"Configuration item [
$key
] is not defined."
);
// -----------------------------------------------------
// Return the configuration item. If the item doesn't
// exist, the default value will be returned.
// -----------------------------------------------------
return
(
array_key_exists
(
$key
,
static
::
$items
[
$file
]))
?
static
::
$items
[
$file
][
$key
]
:
$default
;
}
}
/**
/**
...
@@ -91,18 +113,13 @@ class Config {
...
@@ -91,18 +113,13 @@ class Config {
public
static
function
load
(
$file
)
public
static
function
load
(
$file
)
{
{
// -----------------------------------------------------
// -----------------------------------------------------
//
If we have already loaded the file, bail ou
t.
//
Bail out if already loaded or doesn't exis
t.
// -----------------------------------------------------
// -----------------------------------------------------
if
(
array_key_exists
(
$file
,
static
::
$items
))
if
(
array_key_exists
(
$file
,
static
::
$items
)
or
!
file_exists
(
$path
=
APP_PATH
.
'config/'
.
$file
.
EXT
)
)
{
{
return
;
return
;
}
}
if
(
!
file_exists
(
$path
=
APP_PATH
.
'config/'
.
$file
.
EXT
))
{
throw
new
\Exception
(
"Configuration file [
$file
] does not exist."
);
}
// -----------------------------------------------------
// -----------------------------------------------------
// Load the configuration array into the array of items.
// Load the configuration array into the array of items.
// The items array is keyed by filename.
// The items array is keyed by filename.
...
...
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