![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/laminas/laminas-config/src/Writer/ |
<?php namespace Laminas\Config\Writer; use Laminas\Config\Exception; use XMLWriter; use function is_array; use function is_numeric; use function str_repeat; class Xml extends AbstractWriter { /** * processConfig(): defined by AbstractWriter. * * @param array $config * @return string */ public function processConfig(array $config) { $writer = new XMLWriter(); $writer->openMemory(); $writer->setIndent(true); $writer->setIndentString(str_repeat(' ', 4)); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement('laminas-config'); foreach ($config as $sectionName => $data) { if (! is_array($data)) { $writer->writeElement($sectionName, (string) $data); } else { $this->addBranch($sectionName, $data, $writer); } } $writer->endElement(); $writer->endDocument(); return $writer->outputMemory(); } /** * Add a branch to an XML object recursively. * * @param string $branchName * @param array $config * @return void * @throws Exception\RuntimeException */ protected function addBranch($branchName, array $config, XMLWriter $writer) { $branchType = null; foreach ($config as $key => $value) { if ($branchType === null) { if (is_numeric($key)) { $branchType = 'numeric'; } else { $writer->startElement($branchName); $branchType = 'string'; } } elseif ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) { throw new Exception\RuntimeException('Mixing of string and numeric keys is not allowed'); } if ($branchType === 'numeric') { if (is_array($value)) { $this->addBranch($branchName, $value, $writer); } else { $writer->writeElement($branchName, (string) $value); } } else { if (is_array($value)) { $this->addBranch($key, $value, $writer); } else { $writer->writeElement($key, (string) $value); } } } if ($branchType === 'string') { $writer->endElement(); } } }