-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from vinkla/config
Add new config method with dot notation.
- Loading branch information
Showing
13 changed files
with
115 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
<?php | ||
|
||
return [ | ||
'app' => require get_template_directory().'/config/app.php', | ||
'dashboard' => require get_template_directory().'/config/dashboard.php', | ||
'editor' => require get_template_directory().'/config/editor.php', | ||
'footer' => require get_template_directory().'/config/footer.php', | ||
'login' => require get_template_directory().'/config/login.php', | ||
'menus' => require get_template_directory().'/config/menus.php', | ||
'theme' => require get_template_directory().'/config/theme.php', | ||
'plugins' => require get_template_directory().'/config/plugins.php', | ||
'widgets' => require get_template_directory().'/config/widgets.php', | ||
]; | ||
if (!function_exists('config')) { | ||
|
||
/** | ||
* Get the specified configuration value. | ||
* | ||
* @param array|string $key | ||
* @param mixed $default | ||
* | ||
* @return mixed | ||
*/ | ||
function config($key = null, $default = null) | ||
{ | ||
$config = [ | ||
'app' => require get_template_directory().'/config/app.php', | ||
'dashboard' => require get_template_directory().'/config/dashboard.php', | ||
'editor' => require get_template_directory().'/config/editor.php', | ||
'footer' => require get_template_directory().'/config/footer.php', | ||
'login' => require get_template_directory().'/config/login.php', | ||
'menus' => require get_template_directory().'/config/menus.php', | ||
'theme' => require get_template_directory().'/config/theme.php', | ||
'plugins' => require get_template_directory().'/config/plugins.php', | ||
'widgets' => require get_template_directory().'/config/widgets.php', | ||
]; | ||
|
||
if (is_null($key)) { | ||
return $config; | ||
} | ||
|
||
if (isset($config[$key])) { | ||
return $config[$key]; | ||
} | ||
|
||
foreach (explode('.', $key) as $segment) { | ||
if (!is_array($config) || !array_key_exists($segment, $config)) { | ||
return $default; | ||
} | ||
|
||
$config = $config[$segment]; | ||
} | ||
|
||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* Format bytes to kilobytes, megabytes, gigabytes. | ||
* | ||
* @param int $bytes | ||
* @param int $precision | ||
* @return string | ||
*/ | ||
function format_bytes($bytes, $precision = 2) | ||
{ | ||
$units = ['B', 'KB', 'MB', 'GB', 'TB']; | ||
if (!function_exists('dd')) { | ||
|
||
$bytes = max($bytes, 0); | ||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); | ||
$pow = min($pow, count($units) - 1); | ||
/** | ||
* Dump the passed variables and end the script. | ||
* | ||
* @param mixed | ||
*/ | ||
function dd() | ||
{ | ||
array_map(function ($x) { var_dump($x); }, func_get_args()); | ||
die; | ||
} | ||
} | ||
|
||
if (!function_exists('format_bytes')) { | ||
|
||
/** | ||
* Format bytes to kilobytes, megabytes, gigabytes. | ||
* | ||
* @param int $bytes | ||
* @param int $precision | ||
* @return string | ||
*/ | ||
function format_bytes($bytes, $precision = 2) | ||
{ | ||
$units = ['B', 'KB', 'MB', 'GB', 'TB']; | ||
|
||
$bytes = max($bytes, 0); | ||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); | ||
$pow = min($pow, count($units) - 1); | ||
|
||
$bytes /= pow(1024, $pow); | ||
$bytes /= pow(1024, $pow); | ||
|
||
return sprintf('%s %s', round($bytes, $precision), $units[$pow]); | ||
return sprintf('%s %s', round($bytes, $precision), $units[$pow]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters