/** * Returns a formatted string for a __ConfigurationComponent instance * @param __ConfigurationComponent $configuration_component The __ConfigurationComponent instance to be output as string * @return string The formatted string */ public function toString(__ConfigurationComponent &$configuration_component) { static $childrenCount, $commaString; $return_value = ''; if ($configuration_component instanceof __ConfigurationBlank) { $return_value = "\n"; } else { if ($configuration_component instanceof __ConfigurationComment) { $return_value = $this->_comment_symbol . $configuration_component->getContent() . "\n"; } else { if ($configuration_component instanceof __ConfigurationProperty) { $count = $configuration_component->getParent()->countChildren('__ConfigurationProperty', $configuration_component->getName()); $content = $configuration_component->getContent(); if ($content === false) { $content = $this->_bool_false; } elseif ($content === true) { $content = $this->_bool_true; } elseif ($this->_use_quotes === true && (strlen(trim($content)) < strlen($content) || strpos($content, ',') !== false || strpos($content, ';') !== false || strpos($content, '=') !== false || strpos($content, '"') !== false || strpos($content, '%') !== false || strpos($content, '~') !== false)) { $content = '"' . addslashes($content) . '"'; } if ($count > 1) { // multiple values for a directive are separated by a comma if (isset($childrenCount[$configuration_component->getName()])) { $childrenCount[$configuration_component->getName()]++; } else { $childrenCount[$configuration_component->getName()] = 0; $commaString[$configuration_component->getName()] = $configuration_component->getName() . '='; } if ($childrenCount[$configuration_component->getName()] == $count - 1) { // Clean the static for future calls to toString $return_value .= $commaString[$configuration_component->getName()] . $content . "\n"; unset($childrenCount[$configuration_component->getName()]); unset($commaString[$configuration_component->getName()]); } else { $commaString[$configuration_component->getName()] .= $content . ', '; } } else { $return_value = $configuration_component->getName() . '=' . $content . "\n"; } } else { if ($configuration_component instanceof __ConfigurationSection || $configuration_component instanceof __Configuration) { if (!$configuration_component->isRoot()) { $return_value = '[' . $configuration_component->getName() . "]\n"; } $configuration_childrens = $configuration_component->getChildrens(); foreach ($configuration_childrens as $configuration_children) { $return_value .= $this->toString($configuration_children); } } else { $return_value = ''; } } } } return $return_value; }
public function toString(__ConfigurationComponent &$configuration_component) { $indent = ''; if (!$configuration_component->isRoot()) { // no indent for root $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } else { // Initialize string with xml declaration $string = ''; if ($this->options['addDecl']) { $string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']); $string .= $this->options['linebreak']; } if (!empty($this->options['name'])) { $string .= '<' . $this->options['name'] . '>' . $this->options['linebreak']; $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } } if (!isset($string)) { $string = ''; } if ($configuration_component instanceof __ConfigurationProperty) { $attributes = $this->options['useAttr'] ? $configuration_component->attributes : array(); $string .= $indent . XML_Util::createTag($configuration_component->name, $attributes, $configuration_component->content, null, $this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES); $string .= $this->options['linebreak']; } else { if ($configuration_component instanceof __ConfigurationComment) { $string .= $indent . '<!-- ' . $configuration_component->content . ' -->'; $string .= $this->options['linebreak']; } else { if ($configuration_component instanceof __ConfigurationSection) { if (!$configuration_component->isRoot()) { $string = $indent . '<' . $configuration_component->name; $string .= $this->options['useAttr'] ? XML_Util::attributesToString($configuration_component->attributes) : ''; } if ($children = count($configuration_component->children)) { if (!$configuration_component->isRoot()) { $string .= '>' . $this->options['linebreak']; } for ($i = 0; $i < $children; $i++) { $string .= $this->toString($configuration_component->getChild($i)); } } if (!$configuration_component->isRoot()) { if ($children) { $string .= $indent . '</' . $configuration_component->name . '>' . $this->options['linebreak']; } else { $string .= '/>' . $this->options['linebreak']; } } else { if (!empty($this->options['name'])) { $string .= '</' . $this->options['name'] . '>' . $this->options['linebreak']; } } } else { $string = ''; } } } if (!$configuration_component->isRoot()) { $this->_deep--; } return $string; }