query('//@*'); /** @var DOMElement $node */ foreach ($attributeNodes as $node) { if (isset($packedAssets[$node->value])) { $node->value = $packedAssets[$node->value]->getReplacedBy(); } } $fileHrefNodes = $xpath->query("//*[local-name()='fileHref']"); /** @var DOMElement $fileHrefNodes */ foreach ($fileHrefNodes as $node) { if (isset($packedAssets[$node->nodeValue])) { $node->nodeValue = $packedAssets[$node->nodeValue]->getReplacedBy(); } } $this->replaceEncodedNodes($xpath, $packedAssets); return $packedAssets; } /** * Replace assets in html encoded properties (such as content of text reader interaction) * @param $xpath * @param array $packedAssets */ private function replaceEncodedNodes(DOMXPath $xpath, array $packedAssets): void { $replacementList = array_filter($packedAssets, function ($asset) { return $asset instanceof PackedAsset; }); /** @var PackedAsset $asset */ foreach ($replacementList as $key => $asset) { $replacementList[$key] = $asset->getReplacedBy(); } $attributeNodes = $xpath->query(self::HTML_CONTENT_NODES_QUERY) ?: []; foreach ($attributeNodes as $node) { if ($node->nodeValue) { $node->nodeValue = strtr(htmlentities($node->nodeValue, ENT_XML1), $replacementList); } } } }