public static function fromFile($Parent, $File, $Name = 'Configuration')
{
$LoadedFromCache = false;
$UseCache = false;
if ($Parent && $Parent->caching()) {
$FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $File);
if (Gdn::cache()->type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::cache()->activeEnabled()) {
$UseCache = true;
$CachedConfigData = Gdn::cache()->get($FileKey, array(Gdn_Cache::FEATURE_NOPREFIX => true));
$LoadedFromCache = $CachedConfigData !== Gdn_Cache::CACHEOP_FAILURE;
}
}
// Define the variable properly.
${$Name} = null;
// If we're not loading config from cache, directly include the conf file
if ($LoadedFromCache) {
${$Name} = $CachedConfigData;
}
if ((is_null(${$Name}) || !is_array(${$Name})) && file_exists($File)) {
$LoadedFromCache = false;
// Include the file.
require $File;
}
// Make sure the config variable is here and is an array.
if (!is_array(${$Name})) {
${$Name} = array();
}
// We're caching, using the cache, and this data was not loaded from cache.
// Write it there now.
if ($Parent && $Parent->caching() && $UseCache && !$LoadedFromCache) {
Gdn::cache()->store($FileKey, ${$Name}, array(Gdn_Cache::FEATURE_NOPREFIX => true, Gdn_Cache::FEATURE_EXPIRY => 3600));
}
return new Gdn_ConfigurationSource($Parent, 'file', $File, $Name, ${$Name});
}