Skip to content

Commit a9fadb7

Browse files
committed
Added support for component tags into a component's innerHTML.
1 parent d09b823 commit a9fadb7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/HTMLServerComponentsCompiler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public function process($content, $options = [])
125125
if ($componentElementsCount > 0) {
126126
for ($i = 0; $i < $componentElementsCount; $i++) {
127127
$componentElement = $componentElements->item(0);
128+
if ($componentElement === null) { // component in component innerHTML case
129+
break;
130+
}
128131
$component = $this->constructComponent($componentElement->getAttributes(), $componentElement->innerHTML);
129132
$componentResultHTML = $getComponentResultHTML($component);
130133

tests/Test.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ public function testProccessData()
123123
$this->assertTrue($result === $expectedResult);
124124
}
125125

126+
/**
127+
*
128+
*/
129+
public function testComponentInComponentInnerHTML()
130+
{
131+
132+
$_GET['ivo'] = 1;
133+
$fullFilename1 = $this->createFile('component1.php', '<html><body>text1</body></html>');
134+
$fullFilename2 = $this->createFile('component2.php', '<html><head><title>hi</title><body><?= $component->innerHTML;?></body>/head></html>');
135+
136+
$compiler = new \IvoPetkov\HTMLServerComponentsCompiler();
137+
$result = $compiler->process('<component src="file:' . $fullFilename2 . '"><component src="file:' . $fullFilename1 . '"/></component>');
138+
$expectedResult = '<!DOCTYPE html><html><head><title>hi</title></head><body>text1</body></html>';
139+
$this->assertTrue($result === $expectedResult);
140+
}
141+
126142
/**
127143
*
128144
*/

0 commit comments

Comments
 (0)