Skip to content

Commit b578629

Browse files
committed
fix: allow autoload to build namespaces
1 parent 002bb53 commit b578629

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Sprout/App.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ public function autoloadCommands(string $path): void
8888
foreach ($commandFiles as $file) {
8989
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
9090
$className = pathinfo($file, PATHINFO_FILENAME);
91-
$fullClassName = "App\\Commands\\$className";
91+
$relativePath = str_replace([getcwd(), '/'], ['', '\\'], $path);
92+
$relativePath = implode('\\', array_map(
93+
'ucfirst',
94+
explode('\\', trim($relativePath, '\\')))
95+
);
96+
97+
$fullClassName = trim("$relativePath\\$className", '\\');
9298

9399
if (class_exists($fullClassName)) {
94100
$this->register(new $fullClassName());

0 commit comments

Comments
 (0)