File io/data/config/AbstractConfigData.class.php
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88:
<?php
/**
* This is a default and minimal implementation of the ConfigData interface.
* @package IO
* @subpackage Data\config
* @copyright © 2005-2019 PHPBoost
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
* @author Benoit SAUTEL <ben.popeye@phpboost.com>
* @version PHPBoost 5.2 - last update: 2014 12 22
* @since PHPBoost 3.0 - 2009 09 16
*/
abstract class AbstractConfigData implements ConfigData
{
private $properties_map = array();
/**
* Constructs a AbstractConfigData object
*/
public function __construct()
{
}
/**
* This method is not used in the configuration context.
* {@inheritdoc}
*/
public final function synchronize()
{
}
/**
* Redefine this method if you want to avoid getting errors while asking values.
* {@inheritdoc}
*/
public function set_default_values()
{
$default_values = $this->get_default_values();
foreach ($default_values as $property => $value)
{
$this->set_property($property, $value);
}
}
/**
* {@inheritdoc}
*/
public function get_property($name)
{
if (array_key_exists($name, $this->properties_map))
{
return $this->properties_map[$name];
}
else
{
return $this->get_default_value($name);
}
}
private function get_default_value($property)
{
$default_values = $this->get_default_values();
if (array_key_exists($property, $default_values))
{
return $default_values[$property];
}
else
{
throw new PropertyNotFoundException($property);
}
}
/**
* {@inheritdoc}
*/
public function set_property($name, $value)
{
$this->properties_map[$name] = $value;
}
/**
* Returns a map associating to each property name the corresponding default value
* @return string[mixed]
*/
abstract protected function get_default_values();
}
?>