Remove Global has/get

This commit is contained in:
MaZderMind 2015-03-31 17:16:40 +02:00
parent c01f7979db
commit 3de36d7a63
3 changed files with 4 additions and 42 deletions

View file

@ -21,44 +21,6 @@ function forceslash($url)
return $url;
}
function has($keychain)
{
return _has($GLOBALS['CONFIG'], $keychain);
}
function _has($array, $keychain)
{
if(!is_array($keychain))
$keychain = explode('.', $keychain);
$key = $keychain[0];
if(!isset($array[$key]))
return false;
if(count($keychain) == 1)
return true;
return _has($array[$key], array_slice($keychain, 1));
}
function get($keychain, $default = null)
{
return _get($GLOBALS['CONFIG'], $keychain, $default);
}
function _get($array, $keychain, $default)
{
if(!is_array($keychain))
$keychain = explode('.', $keychain);
$key = $keychain[0];
if(!isset($array[$key]))
return $default;
if(count($keychain) == 1)
return $array[$key];
return _get($array[$key], array_slice($keychain, 1), $default);
}
function startswith($needle, $haystack)
{
return substr($haystack, 0, strlen($needle)) == $needle;

View file

@ -11,7 +11,7 @@ class Schedule extends ModelBase
}
public function getScale() {
return floatval(get('SCHEDULE.SCALE', 7));
return floatval($this->get('SCHEDULE.SCALE', 7));
}
private function fetchSchedule()
@ -205,12 +205,12 @@ class Schedule extends ModelBase
private function isCacheEnabled()
{
return has('SCHEDULE.CACHE') && function_exists('apc_fetch') && function_exists('apc_store');
return $this->has('SCHEDULE.CACHE') && function_exists('apc_fetch') && function_exists('apc_store');
}
private function getCacheDuration()
{
return get('SCHEDULE.CACHE', 60*10 /* 10 minutes */);
return $this->get('SCHEDULE.CACHE', 60*10 /* 10 minutes */);
}
private $localCache = null;

View file

@ -5,4 +5,4 @@ if(!$schedule->isEnabled())
throw new NotFoundException('Schedule is disabled');
header('Content-Type: application/json');
echo json_encode(program());
echo json_encode($schedule->getSchedule());