Skip to content

Commit b6892df

Browse files
committed
wip
1 parent d6a7d92 commit b6892df

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/view/src/ViewComponentDiscovery.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ public function discoverPath(DiscoveryLocation $location, string $path): void
4444
}
4545

4646
$fileName = str(pathinfo($path, PATHINFO_FILENAME))->before('.');
47+
4748
$contents = str(file_get_contents($path))->ltrim();
4849

49-
preg_match(
50-
pattern: '/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">(?<view>(.|\n)*?)<\/x-component>/',
51-
subject: $contents->toString(),
52-
matches: $matches,
53-
);
50+
preg_match('/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">/', $contents->toString(), $matches);
51+
52+
$view = $contents
53+
->replaceRegex('/^(.|\n)*<x-component.*>?/', '')
54+
->replaceRegex('/<\/x-component>$/', '')
55+
->toString();
5456

5557
if ($fileName->startsWith('x-') && ! isset($matches['name'])) {
5658
$this->discoveryItems->add($location, [
5759
$fileName->toString(),
5860
new AnonymousViewComponent(
59-
contents: $matches['view'] ?? $contents->toString(),
61+
contents: $view,
6062
file: $path,
6163
),
6264
]);
@@ -71,7 +73,7 @@ public function discoverPath(DiscoveryLocation $location, string $path): void
7173
$this->discoveryItems->add($location, [
7274
$matches['name'],
7375
new AnonymousViewComponent(
74-
contents: $matches['header'] . $matches['view'],
76+
contents: $matches['header'] . $view,
7577
file: $path,
7678
),
7779
]);

0 commit comments

Comments
 (0)