From ac607948c14dbc23d8c3ea7df0aec719a38a680d Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 31 Mar 2025 20:26:53 +0300 Subject: [PATCH] Replaced deprecated `dragon-code/simple-dto` with `spatie/laravel-data` --- composer.json | 2 +- src/Console/Command.php | 8 +-- src/Data/Casts/BoolCast.php | 18 ++++++ src/Data/Casts/OperationNameCast.php | 28 ++++++++++ src/Data/Casts/PathCast.php | 29 ++++++++++ src/Data/OptionsData.php | 44 +++++++++++++++ src/Helpers/ConfigHelper.php | 4 +- src/Processors/Processor.php | 2 +- src/Services/MigratorService.php | 4 +- src/Values/OptionsData.php | 82 ---------------------------- tests/TestCase.php | 6 +- 11 files changed, 134 insertions(+), 93 deletions(-) create mode 100644 src/Data/Casts/BoolCast.php create mode 100644 src/Data/Casts/OperationNameCast.php create mode 100644 src/Data/Casts/PathCast.php create mode 100644 src/Data/OptionsData.php delete mode 100644 src/Values/OptionsData.php diff --git a/composer.json b/composer.json index 346cacc1..47d743c6 100644 --- a/composer.json +++ b/composer.json @@ -40,13 +40,13 @@ "require": { "php": "^8.2", "composer-runtime-api": "^2.2", - "dragon-code/simple-dto": "^2.5.1", "dragon-code/support": "^6.6", "illuminate/console": "^10.0 || ^11.0 || ^12.0", "illuminate/container": "^10.0 || ^11.0 || ^12.0", "illuminate/database": "^10.0 || ^11.0 || ^12.0", "illuminate/support": "^10.0 || ^11.0 || ^12.0", "laravel/prompts": ">=0.1", + "spatie/laravel-data": "^4.14", "symfony/console": "^6.0 || ^7.0" }, "require-dev": { diff --git a/src/Console/Command.php b/src/Console/Command.php index 436f150e..e1e9e2b6 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -7,8 +7,8 @@ use DragonCode\LaravelDeployOperations\Concerns\ConfirmableTrait; use DragonCode\LaravelDeployOperations\Concerns\HasIsolatable; use DragonCode\LaravelDeployOperations\Concerns\HasOptionable; +use DragonCode\LaravelDeployOperations\Data\OptionsData; use DragonCode\LaravelDeployOperations\Processors\Processor; -use DragonCode\LaravelDeployOperations\Values\OptionsData; use Illuminate\Console\Command as BaseCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -56,14 +56,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int protected function resolveProcessor(): Processor { return app($this->processor, [ - 'options' => $this->getOptionsDto(), + 'options' => $this->getOptionsData(), 'input' => $this->input, 'output' => $this->output, ]); } - protected function getOptionsDto(): OptionsData + protected function getOptionsData(): OptionsData { - return OptionsData::fromArray(array_merge($this->options(), $this->arguments()))->resolvePath(); + return OptionsData::from(array_merge($this->options(), $this->arguments())); } } diff --git a/src/Data/Casts/BoolCast.php b/src/Data/Casts/BoolCast.php new file mode 100644 index 00000000..3363f39d --- /dev/null +++ b/src/Data/Casts/BoolCast.php @@ -0,0 +1,18 @@ +replace('\\', '/') + ->replace('.php', '') + ->explode('/') + ->map(fn (string $path) => Str::snake($path)) + ->implode(DIRECTORY_SEPARATOR) + ->toString(); + } +} diff --git a/src/Data/Casts/PathCast.php b/src/Data/Casts/PathCast.php new file mode 100644 index 00000000..2b242c12 --- /dev/null +++ b/src/Data/Casts/PathCast.php @@ -0,0 +1,29 @@ +config()->basePath(); + } + + return $this->config()->basePath($value); + } + + protected function config(): ConfigHelper + { + return app(ConfigHelper::class); + } +} diff --git a/src/Data/OptionsData.php b/src/Data/OptionsData.php new file mode 100644 index 00000000..ee304b7c --- /dev/null +++ b/src/Data/OptionsData.php @@ -0,0 +1,44 @@ +toArray(); } - public function path(?string $path = null): string + public function basePath(string $path = ''): string { - return rtrim($this->directory(), '\\/') . DIRECTORY_SEPARATOR . ltrim((string) $path, '\\/'); + return rtrim($this->directory(), '\\/') . DIRECTORY_SEPARATOR . ltrim($path, '\\/'); } public function gitPath(): string diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 8e727407..92681bb9 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -6,6 +6,7 @@ use Closure; use DragonCode\LaravelDeployOperations\Concerns\HasArtisan; +use DragonCode\LaravelDeployOperations\Data\OptionsData; use DragonCode\LaravelDeployOperations\Enums\MethodEnum; use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper; use DragonCode\LaravelDeployOperations\Helpers\GitHelper; @@ -13,7 +14,6 @@ use DragonCode\LaravelDeployOperations\Notifications\Notification; use DragonCode\LaravelDeployOperations\Repositories\OperationsRepository; use DragonCode\LaravelDeployOperations\Services\MigratorService; -use DragonCode\LaravelDeployOperations\Values\OptionsData; use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Facades\Helpers\Str; use DragonCode\Support\Filesystem\File; diff --git a/src/Services/MigratorService.php b/src/Services/MigratorService.php index 6917baf7..b570eea8 100644 --- a/src/Services/MigratorService.php +++ b/src/Services/MigratorService.php @@ -4,12 +4,12 @@ namespace DragonCode\LaravelDeployOperations\Services; +use DragonCode\LaravelDeployOperations\Data\OptionsData; use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper; use DragonCode\LaravelDeployOperations\Jobs\OperationJob; use DragonCode\LaravelDeployOperations\Notifications\Notification; use DragonCode\LaravelDeployOperations\Operation; use DragonCode\LaravelDeployOperations\Repositories\OperationsRepository; -use DragonCode\LaravelDeployOperations\Values\OptionsData; use DragonCode\Support\Exceptions\FileNotFoundException; use DragonCode\Support\Facades\Helpers\Str; use DragonCode\Support\Filesystem\File; @@ -168,7 +168,7 @@ protected function resolveOperation(string $path): Operation protected function resolveOperationName(string $path): string { return Str::of(realpath($path)) - ->after(realpath($this->config->path()) . DIRECTORY_SEPARATOR) + ->after(realpath($this->config->basePath()) . DIRECTORY_SEPARATOR) ->replace(['\\', '/'], '/') ->before('.php') ->toString(); diff --git a/src/Values/OptionsData.php b/src/Values/OptionsData.php deleted file mode 100644 index 5b9bdb2c..00000000 --- a/src/Values/OptionsData.php +++ /dev/null @@ -1,82 +0,0 @@ -path = $this->realpath - ? $this->path ?? $this->config()->path() - : $this->config()->path($this->path); - - return $this; - } - - protected function castName(?string $value): ?string - { - if (empty($value)) { - return null; - } - - return Str::of($value) - ->replace('\\', '/') - ->replace('.php', '') - ->explode('/') - ->map(fn (string $path) => Str::snake($path)) - ->implode(DIRECTORY_SEPARATOR) - ->toString(); - } - - protected function castBefore(mixed $value): bool - { - return Boolean::parse($value); - } - - protected function castForce(mixed $value): bool - { - return Boolean::parse($value); - } - - protected function castRealpath(mixed $value): bool - { - return Boolean::parse($value); - } - - protected function castStep(int|string|null $value): ?int - { - return is_numeric($value) ? (int) $value : null; - } - - protected function config(): ConfigHelper - { - return app(ConfigHelper::class); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index c45537c7..021f504c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,6 +11,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Orchestra\Testbench\TestCase as BaseTestCase; +use Spatie\LaravelData\LaravelDataServiceProvider; use Tests\Concerns\AssertDatabase; use Tests\Concerns\Database; use Tests\Concerns\Files; @@ -32,7 +33,10 @@ protected function setUp(): void protected function getPackageProviders($app): array { - return [ServiceProvider::class]; + return [ + ServiceProvider::class, + LaravelDataServiceProvider::class, + ]; } protected function getEnvironmentSetUp($app): void