allow to render different components

580-view-class-steroids
fadrian06 2 weeks ago
parent 5076b266b3
commit 52ec6b8803

@ -172,31 +172,33 @@ class View
$view = ob_get_clean();
}
preg_match(
preg_match_all(
"/<$this->componentPrefix-(?<component>[a-z-]+)\s*(?<props>([a-z]+=\"[a-zA-Z]+\"\s*)*)?\s*\/>/",
$view,
$matches,
$tagsMatches,
);
if ($matches) {
$tag = $matches[0];
$component = $matches['component'];
$props = $matches['props'] ?? '';
$tagsMatches = array_filter($tagsMatches);
foreach ($tagsMatches[0] ?? [] as $tagIndex => $match) {
$tag = $match;
$component = $tagsMatches['component'][$tagIndex];
$props = $tagsMatches['props'][$tagIndex] ?? '';
preg_match_all(
'/(?<name>[a-z]+)="(?<value>[a-zA-Z]+)"/',
$props,
$matches,
$propsMatches,
);
$matches = array_filter($matches);
$propsMatches = array_filter($propsMatches);
if ($matches) {
if ($propsMatches) {
$props = [];
foreach (array_keys($matches[0]) as $index) {
$name = $matches['name'][$index];
$value = $matches['value'][$index];
foreach (array_keys($propsMatches[0]) as $propIndex) {
$name = $propsMatches['name'][$propIndex];
$value = $propsMatches['value'][$propIndex];
$props[$name] = $value;
}
} else {

@ -369,6 +369,14 @@ class ViewTest extends TestCase
html,
['name' => 'Victoria', 'occupation' => 'Astronaut'],
],
[
'page-with-three-different-components',
<<<'html'
my-component
my-functional-component
my-class-component
html,
],
];
}

@ -0,0 +1,3 @@
<f-my-component />
<f-my-functional-component />
<f-my-class-component />
Loading…
Cancel
Save