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

@ -369,6 +369,14 @@ class ViewTest extends TestCase
html, html,
['name' => 'Victoria', 'occupation' => 'Astronaut'], ['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