Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Console/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Saloon\Laravel\Console\Commands;

use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use function Laravel\Prompts\suggest;
use Illuminate\Console\GeneratorCommand;
Expand Down Expand Up @@ -148,4 +149,27 @@ protected function getNamespaceFromIntegrationsPath(): string

return $namespace[0];
}

/**
* Get the destination class path.
*
* When integrations_path is configured outside app/ (e.g. base_path('src/Domains/Integrations')),
* build the path from that config so files are written to the correct location.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
$relativePath = str_replace('\\', '/', $name) . '.php';
$integrationsPath = config('saloon.integrations_path');
$pathPrefix = str_replace('\\', '/', mb_trim($this->getNamespaceFromIntegrationsPath(), '\\')) . '/';

if ($pathPrefix !== '/' && str_starts_with($relativePath, $pathPrefix)) {
return mb_rtrim($integrationsPath, '/\\') . \DIRECTORY_SEPARATOR . Str::after($relativePath, $pathPrefix);
}

return $this->laravel->basePath('app') . '/' . $relativePath;
}
}