* @link http://jensarps.de * @license http://www.opensource.org/licenses/lgpl-3.0.html LGPL * */ class YourProject_StaticData { /** * * @var array data the container for all collected data */ private $data = array(); static private $instance = null; static public function getInstance() { if (self::$instance === null) { self::$instance = new self; } return self::$instance; } private function __construct(){} private function __clone(){} /** * collectStaticData * collects static data. run this method during the bootstrapping process. * */ function collectStaticData() { $staticPath = PATH.'static/'; $entries = scandir($staticPath); foreach($entries as $item) if(is_file($staticPath.$item) and end(explode('.',$item)) === 'data') $this->data[basename($item,'.data')] = parse_ini_file($staticPath.$item,true); } /** * getSection * returns a section of data * * @param string $section the name of the section (i.e., the basename of the file) * @return array the section, if found, or an empty array if not */ function getSection($section) { return empty($this->data[$section]) ? array() : $this->data[$section]; } /** * getSubSection * return a specific key of a section * * @param string $section the name of the section * @param string $key * @return mixed the value, if thet given key is found in the given section, or null if not */ function getSubSection($section,$key) { $sectionData = $this->getSection($section); return empty($sectionData[$key]) ? null : $sectionData[$key]; } /** * getAll * returns all collected data * * @return array all collected data */ function getAll() { return $this->data; } /** * get * shorthand for "getSection" * * @see getSection */ function get($section) { return $this->getSection($section); // section shorthand } }