constInterpreter = $constInterpreter; } /** * Convert dom node tree to array * * @param \DOMDocument $source * @return array */ public function convert($source) { $output = []; /** @var \DOMNodeList $cookies */ $cookies = $source->getElementsByTagName('cookie'); /** @var \DOMNode $cookie */ foreach ($cookies as $cookie) { $cookieConfig = []; foreach ($cookie->attributes as $attribute) { $cookieConfig[$attribute->nodeName] = $attribute->nodeValue; } /** @var \DOMNode $childNode */ foreach ($cookie->childNodes as $childNode) { if ($childNode->nodeType == XML_ELEMENT_NODE || ($childNode->nodeType == XML_CDATA_SECTION_NODE || $childNode->nodeType == XML_TEXT_NODE && trim( $childNode->nodeValue ) != '') ) { if ($childNode->attributes->getNamedItem('type') && 'const' === $childNode->attributes->getNamedItem('type')->nodeValue ) { $value = $this->constInterpreter->evaluate(['value' => $childNode->nodeValue]); } else { $value = $childNode->nodeValue; } $cookieConfig[$childNode->nodeName] = $value; } } $output[$cookie->attributes->getNamedItem('name')->nodeValue] = $cookieConfig; } $output = array_map(static function ($cookie) { $cookie['type'] = $cookie['type'] ?? Type::TYPE_FIRST; $cookie['category_key'] = $cookie['category']; unset($cookie['category']); return $cookie; }, $output); return ['cookies' => $output]; } }