68 lines
1.4 KiB
PHP
68 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace core\config;
|
|
|
|
/**
|
|
* Special configuration children, used especialy for the whole configuration
|
|
*/
|
|
class GlobalConfiguration
|
|
{
|
|
/**
|
|
* Equivalent to get method of \core\config\Configuration, but load the whole configuration
|
|
*
|
|
* @param \string $keys,... Ordered tuple of keys
|
|
*
|
|
* @return \core\config\Configuration | \string
|
|
*/
|
|
public static function read(...$keys) : \core\config\Configuration | \string
|
|
{
|
|
$part = self::load();
|
|
|
|
foreach ($keys as $key)
|
|
{
|
|
if (\key_exists($key, $part))
|
|
{
|
|
\throw new \core\config\ConfigException(
|
|
\core\substitute(_('the key {key} does not exist in this part of the configuration'), array('key' => $key))
|
|
);
|
|
}
|
|
$part = $part[$key];
|
|
}
|
|
if (\is_array($part))
|
|
{
|
|
return new \core\config\Configuration($part);
|
|
}
|
|
if (\is_string($part))
|
|
{
|
|
return $part
|
|
}
|
|
\throw new \core\config\ConfigException(
|
|
\core\substitute(_('the type {type} should not be in a configuration'), array('type' => \gettype($part)))
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get a subpart of this configuration or a value in this configuration
|
|
*
|
|
* @param \string $keys,... Ordered tuple of key, which give the address of the wanted part
|
|
*
|
|
* @return \bool
|
|
*/
|
|
public function exist(keys: \string ...$keys) : \bool
|
|
{
|
|
$part = self::load();
|
|
|
|
foreach ($keys as $key)
|
|
{
|
|
if (\key_exists($key, $part))
|
|
{
|
|
return False;
|
|
}
|
|
$part = $part[$key];
|
|
}
|
|
|
|
return True;
|
|
}
|
|
}
|
|
|
|
?>
|