*/ abstract class AbstractRegistry extends ConfigurableService { /** * * @author Lionel Lecaque, lionel@taotesting.com * @return AbstractRegistry */ public static function getRegistry() { return ServiceManager::getServiceManager()->get(get_called_class()); } /** * Specify in which extensions the config will be stored * * @author Lionel Lecaque, lionel@taotesting.com * @return common_ext_Extension */ abstract protected function getExtension(); /** * * config file in which the data will be stored * * @author Lionel Lecaque, lionel@taotesting.com * @return string */ abstract protected function getConfigId(); /** * * Get the config of dedicated extensions * * @author Lionel Lecaque, lionel@taotesting.com */ protected function getConfig() { return $this->getExtension()->getConfig($this->getConfigId()); } /** * * @author Lionel Lecaque, lionel@taotesting.com * @param array $map */ protected function setConfig($map) { $this->getExtension()->setConfig($this->getConfigId(), $map); } /** * * Remove a element from the array * * @author Lionel Lecaque, lionel@taotesting.com * @param string $id */ public function remove($id) { $map = $this->getMap(); if (isset($map[$id])) { unset($map[$id]); $this->setConfig($map); } } /** * Get the complete array * * @author Lionel Lecaque, lionel@taotesting.com * @return array */ public function getMap() { $map = $this->getConfig(); return is_array($map) ? $map : []; } /** * Add a value to the config with given id * * @author Lionel Lecaque, lionel@taotesting.com * @param string $id * @param string $value */ public function set($id, $value) { $map = $this->getMap(); $map[$id] = $value; $this->setConfig($map); } /** * Check if the config element exist * * @author Lionel Lecaque, lionel@taotesting.com * @param unknown $id */ public function isRegistered($id) { return array_key_exists($id, $this->getMap()); } /** * * Retrieve the given element from the array in config * * @author Lionel Lecaque, lionel@taotesting.com * @param string $id * @return string */ public function get($id) { $map = $this->getMap(); return isset($map[$id]) ? $map[$id] : ''; } }