Skip to content

Commit 1dc8c07

Browse files
authored
fix for when integrations_path is outside app/ (#78)
* fix for when integrations_path is outside app/ * get path a better way
1 parent 2562dec commit 1dc8c07

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/Console/Commands/MakeCommand.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Saloon\Laravel\Console\Commands;
66

7+
use Illuminate\Support\Str;
78
use Illuminate\Support\Facades\File;
89
use function Laravel\Prompts\suggest;
910
use Illuminate\Console\GeneratorCommand;
@@ -148,4 +149,27 @@ protected function getNamespaceFromIntegrationsPath(): string
148149

149150
return $namespace[0];
150151
}
152+
153+
/**
154+
* Get the destination class path.
155+
*
156+
* When integrations_path is configured outside app/ (e.g. base_path('src/Domains/Integrations')),
157+
* build the path from that config so files are written to the correct location.
158+
*
159+
* @param string $name
160+
* @return string
161+
*/
162+
protected function getPath($name)
163+
{
164+
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
165+
$relativePath = str_replace('\\', '/', $name) . '.php';
166+
$integrationsPath = config('saloon.integrations_path');
167+
$pathPrefix = str_replace('\\', '/', mb_trim($this->getNamespaceFromIntegrationsPath(), '\\')) . '/';
168+
169+
if ($pathPrefix !== '/' && str_starts_with($relativePath, $pathPrefix)) {
170+
return mb_rtrim($integrationsPath, '/\\') . \DIRECTORY_SEPARATOR . Str::after($relativePath, $pathPrefix);
171+
}
172+
173+
return $this->laravel->basePath('app') . '/' . $relativePath;
174+
}
151175
}

0 commit comments

Comments
 (0)