public function parse($content, __Configuration &$configuration) { $return = true; $lines = preg_split('/\\r?\\n/', $content); $n = 0; $lastline = ''; $current_section =& $configuration; foreach ($lines as $line) { $n++; if (preg_match('/^\\s*' . $this->_comment_symbol . '(.*?)\\s*$/', $line, $match)) { // a comment $current_section->createComment($match[1]); } elseif (trim($line) == '') { // a blank line $current_section->createBlank(); } elseif (preg_match('/^\\s*([a-zA-Z0-9_\\-\\.\\s:]*)\\s*=\\s*(.*)\\s*$/', $line, $match)) { // a directive $values = $this->_quoteAndCommaParser($match[2]); if (count($values)) { foreach ($values as $value) { if ($value[0] == 'normal') { $current_section->createProperty(trim($match[1]), $value[1]); } if ($value[0] == 'comment') { $current_section->createComment(substr($value[1], 1)); } } } } elseif (preg_match('/^\\s*\\[\\s*(.*)\\s*\\]\\s*$/', $line, $match)) { // a section $current_section =& $configuration->createSection($match[1]); } elseif (trim($line) == '') { $current_section =& $obj->container->createBlank(); } else { throw new __ConfigurationException("Syntax error in '{$line}' at line {$n}."); } } return $return; }
public function load($filename, __Configuration &$configuration) { //Set the name for current __Configuration as the name of configuration file: $configuration->setName(strtoupper(basename($filename))); if (!file_exists($filename)) { throw new __ConfigurationException('Configuration file not found: "' . $filename . '"'); } $current_section =& $configuration; $configuration_array = parse_ini_file($filename, true); if ($configuration_array === false) { throw new __ConfigurationException('Unknow configuration file format for : "' . $filename . '"'); } foreach ($configuration_array as $key => $value) { if (is_array($value)) { $current_section =& $configuration->createSection($key); foreach ($value as $property => $content) { $current_section->createProperty($property, $content); } } else { $current_section->createProperty($key, $value); } } }