diff --git a/flight/template/View.php b/flight/template/View.php index a7212db..d47eeff 100644 --- a/flight/template/View.php +++ b/flight/template/View.php @@ -158,7 +158,7 @@ class View } preg_match( - '/[a-z-]+)\s*(?[a-z]+="[a-z-A-Z]+")*\s*\/>/', + '/[a-z-]+)\s*(?([a-z]+="[a-zA-Z]+"\s*)*)?\s*\/>/', $view, $matches, ); @@ -168,15 +168,25 @@ class View $component = $matches['component']; $props = $matches['props'] ?? ''; - preg_match( - '/^(?[a-z]+)="(?[a-zA-Z]+)"$/', + preg_match_all( + '/(?[a-z]+)="(?[a-zA-Z]+)"/', $props, $matches, ); - $props = $matches - ? [$matches['name'] => $matches['value']] - : []; + $matches = array_filter($matches); + + if ($matches) { + $props = []; + + foreach (array_keys($matches[0]) as $index) { + $name = $matches['name'][$index]; + $value = $matches['value'][$index]; + $props[$name] = $value; + } + } else { + $props = []; + } $component = $this->fetch("components/$component", $props); $view = str_replace($tag, $component, $view); diff --git a/tests/ViewTest.php b/tests/ViewTest.php index bb5c47e..178c22c 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -345,7 +345,17 @@ class ViewTest extends TestCase html, ['name' => 'Victoria'], ], - + [ + 'page-with-component-with-two-props', + <<<'html' + + +

Hello, Astronaut Victoria

+ + + html, + ['name' => 'Victoria', 'occupation' => 'Astronaut'], + ], ]; } diff --git a/tests/views/components/greeting-with-two-props.php b/tests/views/components/greeting-with-two-props.php new file mode 100644 index 0000000..24045d6 --- /dev/null +++ b/tests/views/components/greeting-with-two-props.php @@ -0,0 +1 @@ +

Hello,

\ No newline at end of file diff --git a/tests/views/pages/page-with-component-with-two-props.php b/tests/views/pages/page-with-component-with-two-props.php new file mode 100644 index 0000000..6cb9045 --- /dev/null +++ b/tests/views/pages/page-with-component-with-two-props.php @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file