aliases[$alias] = $original;
}
/**
* Converts components code (if any) into HTML code
*
* @param string|\IvoPetkov\HTMLServerComponent $content The content to be processed
* @param array $options Compiler options
* @return string The result HTML code
*/
public function process(string $content, array $options = [])
{
if (is_string($content)) {
if (strpos($content, 'attributes['src'])) {
// todo check alias of alias
$srcAttributeValue = $component->attributes['src'];
if (isset($this->aliases[$srcAttributeValue])) {
$sourceParts = explode(':', $this->aliases[$srcAttributeValue], 2);
} else {
$sourceParts = explode(':', $srcAttributeValue, 2);
}
if (isset($sourceParts[0], $sourceParts[1])) {
$scheme = $sourceParts[0];
if ($scheme === 'data') {
if (substr($sourceParts[1], 0, 7) === 'base64,') {
return base64_decode(substr($sourceParts[1], 7)); //$this->process(, isset($componentOptions) ? $componentOptions : $options);
}
throw new \Exception('Components data URI scheme only supports base64 (data:base64,ABCD...)!');
} elseif ($scheme === 'file') {
return $getComponentFileContent(urldecode($sourceParts[1]), $component, isset($options['variables']) && is_array($options['variables']) ? $options['variables'] : []); //$this->process(isset($componentOptions) ? $componentOptions : $options);
}
throw new \Exception('Components URI scheme not valid! It must be \'file:\', \'data:\' or an alias.');
}
throw new \Exception('Components URI scheme or alias not found at ' . (string) $component . '!');
}
throw new \Exception('Component src attribute is missing at ' . (string) $component . '!');
};
$disableLevelProcessing = false;
$domDocument = new HTML5DOMDocument();
if ($content instanceof HTMLServerComponent) {
$domDocument->loadHTML($getComponentResultHTML($content));
if (isset($options['recursive']) && $options['recursive'] === false) {
$disableLevelProcessing = true;
}
} else {
$domDocument->loadHTML($content);
}
if (!$disableLevelProcessing) {
for ($level = 0; $level < 1000; $level++) {
$componentElements = $domDocument->getElementsByTagName('component');
if ($componentElements->length === 0) {
break;
}
$insertHTMLSources = [];
$list = []; // Save the elements into an array because removeChild() messes up the NodeList
foreach ($componentElements as $componentElement) {
$isInOtherComponentTag = false;
$parentNode = $componentElement->parentNode;
while ($parentNode !== null && isset($parentNode->tagName)) {
if ($parentNode->tagName === 'component') {
$isInOtherComponentTag = true;
break;
}
$parentNode = $parentNode->parentNode;
}
if (!$isInOtherComponentTag) {
$list[] = $componentElement;
}
}
foreach ($list as $i => $componentElement) {
$component = $this->constructComponent($componentElement->getAttributes(), $componentElement->innerHTML);
$componentResultHTML = $getComponentResultHTML($component);
$isInBodyTag = false;
$parentNode = $componentElement->parentNode;
while ($parentNode !== null && isset($parentNode->tagName)) {
if ($parentNode->tagName === 'body') {
$isInBodyTag = true;
break;
}
$parentNode = $parentNode->parentNode;
}
if ($isInBodyTag) {
$insertTargetName = 'html-server-components-compiler-insert-target-' . $i;
$componentElement->parentNode->insertBefore($domDocument->createInsertTarget($insertTargetName), $componentElement);
$componentElement->parentNode->removeChild($componentElement); // must be before insertHTML because a duplicate elements IDs can occur.
$insertHTMLSources[] = ['source' => $componentResultHTML, 'target' => $insertTargetName];
} else {
$componentElement->parentNode->removeChild($componentElement);
$insertHTMLSources[] = ['source' => $componentResultHTML];
}
}
$domDocument->insertHTMLMulti($insertHTMLSources);
if (isset($options['recursive']) && $options['recursive'] === false) {
break;
}
}
}
return $domDocument->saveHTML();
}
/**
* Constructs a component object
*
* @param array $attributes The attributes of the component object
* @param string $innerHTML The innerHTML of the component object
* @return \IvoPetkov\HTMLServerComponent A component object
*/
public function constructComponent(array $attributes = [], string $innerHTML = '')
{
if (self::$newComponentCache === null) {
self::$newComponentCache = new HTMLServerComponent();
}
$component = clone(self::$newComponentCache);
$component->attributes = $attributes;
$component->innerHTML = $innerHTML;
return $component;
}
}__halt_compiler();----SIGNATURE:----tLn3Kbb24vIFnD82r1IYcmA5y2tlGem8y7cKToRfCF9bi6o9/Mhza9kGLxM1yTNlEOY9awCLMdKD67F80fdYpEbpmTNYNkrgXLQStXDmzSLglAvx+s4rOSUAP8IKSDXh348y4tm/rSrhvxFKeKTgH72S14oX0bUpBTpxHRqC7kKs/QiFFkCl2Tv1hCm1tHaXkFA/WVBSlK9tZdIwT1nFTQoMvP7EndiEKz4I2af+7Gy1NpK5n/j71lPioELZUZbdEXnFGyDr+QNRbubwiQ/KoOx8liiSUa7NSGRY2yZEeBzUA4tFQy2/8poO8L0gj2MGnmc0/mHd542xXYD9/wCSHaZnI3zR10OBROc6JNYB0X09Z/t3dFis/VAaVgBxvsYvIQ9NTFjuVyrrqGJ+8xZV6Qw9AbA6TQfEtpqzg1IOl20l/hXKzTm1Fu/md2AAw0Snv6efkopL6HWWyhEmuiAuJSptcxkaAstdMtPmJYO4x9wFI7xjUdfXhrf1fOd8NOA6ZNpfbtjvMmv02mK9ssolHz6aM6uIDTuU0F8zC8rGKjCFIa+v51wEXaAEaThzYl+hoZBCgzWfnv0aRDSV3CsPVfen7EyVjNJA2TtYYrbqIU23j7MoLqksxWji43DgsORxoo7yT1Frf/Ae/1qqQcGHYQcpug1pTApHgiZg3Wfh9yw=----ATTACHMENT:----NjQ4OTc5NjgwNDA5ODY5MyA5OTUyODQwOTU3MjU0NzEzIDI5NzYwMzU5NjcxMDgwODI=