本文整理汇总了PHP中Extension::defined方法的典型用法代码示例。如果您正苦于以下问题:PHP Extension::defined方法的具体用法?PHP Extension::defined怎么用?PHP Extension::defined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Extension
的用法示例。
在下文中一共展示了Extension::defined方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refreshCache
/**
* Re-reads config and refreshes cache.
*
* @return Yaml
* @throws Exception\LoaderException
*/
protected function refreshCache()
{
$ext = new Extension();
$ext->load();
try {
$yaml = Yaml::load(self::YAML_FILE);
} catch (\Exception $e) {
throw new Exception\LoaderException(sprintf('Could not load config. %s', $e->getMessage()));
}
$refSet = new \ReflectionMethod($yaml, 'set');
$refSet->setAccessible(true);
$before = clone $yaml;
foreach ($ext as $key => $obj) {
if (property_exists($obj, 'default') && (!$yaml->defined($key) || $yaml($key) === null)) {
//Set defaults only in the case it is provided in the Extension.
//Set defaults only if they are not overriden in config and not null.
$refSet->invoke($yaml, $key, $obj->default);
}
//Checks if at least one from all parents is not required.
$token = $key;
while (strpos($token, '.')) {
$token = preg_replace('/\\.[^\\.]+$/', '', $token);
//Parent bag is not required
if (!$ext->defined($token)) {
//And it is not defined in config
if (!$before->defined($token)) {
continue 2;
} else {
//check presence of nodes if it is defined in config
break;
}
}
}
if (!$yaml->defined($key)) {
//If, after all, value has not been defined in the Extension, it is considered as user error.
throw new Exception\LoaderException(sprintf('Parameter "%s" must be defined in the config', $key));
}
}
unset($before);
//serialize yaml
file_put_contents(self::YAML_CACHE_FILE, serialize($yaml));
@chmod(self::YAML_CACHE_FILE, 0666);
return $yaml;
}