Skip to content

Commit 0947c59

Browse files
committed
anonymous namespaced components
1 parent 2343476 commit 0947c59

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

php-templates/blade-components.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ protected function findFiles($path, $extension, $keyCallback = null)
4747
->files()
4848
->name("*." . $extension)
4949
->in($path);
50+
$components = [];
51+
$pathRealPath = realpath($path);
5052

5153
foreach ($files as $file) {
5254
$realPath = $file->getRealPath();
5355

5456
$key = \Illuminate\Support\Str::of($realPath)
55-
->replace(realpath($path), '')
57+
->replace($pathRealPath, '')
5658
->ltrim('/\\')
5759
->replace('.' . $extension, '')
5860
->replace(['/', '\\'], '.');
@@ -99,16 +101,28 @@ protected function getAliases()
99101
return $components;
100102
}
101103

102-
protected function getExtensions()
103-
{
104-
// \Illuminate\Support\Facades\Blade::getExtensions(),
105-
return [];
106-
}
107-
108104
protected function getAnonymousNamespaced()
109105
{
110-
// \Illuminate\Support\Facades\Blade::getAnonymousComponentNamespaces();
111-
return [];
106+
$components = [];
107+
108+
foreach (\Illuminate\Support\Facades\Blade::getAnonymousComponentNamespaces() as $key => $dir) {
109+
$path = collect([$dir, resource_path('views/' . $dir)])->first(fn($p) => is_dir($p));
110+
111+
if (!$path) {
112+
continue;
113+
}
114+
115+
array_push(
116+
$components,
117+
...$this->findFiles(
118+
$path,
119+
'blade.php',
120+
fn($k) => $k->kebab()->prepend($key . "::"),
121+
)
122+
);
123+
}
124+
125+
return $components;
112126
}
113127

114128
protected function getAnonymous()

src/templates/blade-components.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ $components = new class {
4747
->files()
4848
->name("*." . $extension)
4949
->in($path);
50+
$components = [];
51+
$pathRealPath = realpath($path);
5052
5153
foreach ($files as $file) {
5254
$realPath = $file->getRealPath();
5355
5456
$key = \\Illuminate\\Support\\Str::of($realPath)
55-
->replace(realpath($path), '')
57+
->replace($pathRealPath, '')
5658
->ltrim('/\\\\')
5759
->replace('.' . $extension, '')
5860
->replace(['/', '\\\\'], '.');
@@ -99,16 +101,28 @@ $components = new class {
99101
return $components;
100102
}
101103
102-
protected function getExtensions()
103-
{
104-
// \\Illuminate\\Support\\Facades\\Blade::getExtensions(),
105-
return [];
106-
}
107-
108104
protected function getAnonymousNamespaced()
109105
{
110-
// \\Illuminate\\Support\\Facades\\Blade::getAnonymousComponentNamespaces();
111-
return [];
106+
$components = [];
107+
108+
foreach (\\Illuminate\\Support\\Facades\\Blade::getAnonymousComponentNamespaces() as $key => $dir) {
109+
$path = collect([$dir, resource_path('views/' . $dir)])->first(fn($p) => is_dir($p));
110+
111+
if (!$path) {
112+
continue;
113+
}
114+
115+
array_push(
116+
$components,
117+
...$this->findFiles(
118+
$path,
119+
'blade.php',
120+
fn($k) => $k->kebab()->prepend($key . "::"),
121+
)
122+
);
123+
}
124+
125+
return $components;
112126
}
113127
114128
protected function getAnonymous()

0 commit comments

Comments
 (0)