* @access protected */ protected $paths = array('','ear/cfg'); /** * @var String * @access protected */ protected $seperator = self::DEFAULT_SEPERATOR; /** * construct * @param propertyFilePath */ public function __construct($propertyFileName = NULL, $seperator = self::DEFAULT_SEPERATOR){ $this->seperator = $seperator ? $seperator : self::DEFAULT_SEPERATOR; if($propertyFileName) $this->openPropertyFile($propertyFileName); } /** * @param String FilePath * @access public */ public function openPropertyFile($propertyFileName){ try { //reset the parent $this->exchangeArray(array()); //get the file $propertyFilePath = $this->findFile($propertyFileName); //read the file $this->readPropertiesFromFile($propertyFilePath); } catch (Exception $e){ throw $e; } } /** * @param String file name of the property * @return String file path * @access protected */ protected function findFile($propertyFilePath){ if (!file_exists($propertyFilePath) or !is_file($propertyFilePath)) { /** search the file in all property file paths */ foreach ($this->paths as $path){ if (file_exists("{$path}/{$propertyFilePath}")) { $propertyFilePath = "{$path}/{$propertyFilePath}"; break; } } if (!file_exists($propertyFilePath) or !is_file($propertyFilePath)) throw new Exception("File '{$propertyFilePath}' not found"); } return $propertyFilePath; } /** * @param String file path * @return Arrayvalue> * @access protected */ protected function readPropertiesFromFile($propertyFilePath){ $lines = array_filter(file($propertyFilePath), array($this, 'lineFilter')); array_walk($lines, array($this, 'addPropertyFromLine')); } /** * Filter for the Lines * @param String line * @return boolean */ protected function lineFilter($line){ return (trim($line) && preg_match(self::REMARKS_PATTERN, $line)); } /** * addPropertyFromLine * @param String property line */ protected function addPropertyFromLine($line){ while(is_numeric($length=eregi('~([0-9]+)~', $line, $found))){ $line = str_replace($found[0], chr($found[1]), $line); } $property = array_map('trim', explode($this->seperator, $line)); $key = $property[0]; $value = $property[1]; if (preg_match(self::PATTERN_ARRAY, $value, $found)) { $value = new ArrayObject(explode(',', $found[1])) ; } $this->$key = $value; } /** * @param String * @return Variant * @access public */ public function __get($key){ return $this[$key]; } /** * @param String * @param Variant * @access public */ public function __set($key, $value){ $this[$key] = $value; } /** * getProperties * @return propertyarray */ public function toArray(){ return $this->getArrayCopy(); } } ?>