Skip to content

Replaced deprecated dragon-code/simple-dto with spatie/laravel-data #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}
18 changes: 18 additions & 0 deletions src/Data/Casts/BoolCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Casts;

use DragonCode\Support\Facades\Helpers\Boolean;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

class BoolCast implements Cast
{
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): bool
{
return Boolean::parse($value);
}
}
28 changes: 28 additions & 0 deletions src/Data/Casts/OperationNameCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Casts;

use DragonCode\Support\Facades\Helpers\Str;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

class OperationNameCast implements Cast
{
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): ?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();
}
}
29 changes: 29 additions & 0 deletions src/Data/Casts/PathCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Casts;

use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

use function app;

class PathCast implements Cast
{
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
{
if ($properties['realpath'] ?? false) {
return $value ?: $this->config()->basePath();
}

return $this->config()->basePath($value);
}

protected function config(): ConfigHelper
{
return app(ConfigHelper::class);
}
}
44 changes: 44 additions & 0 deletions src/Data/OptionsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data;

use DragonCode\LaravelDeployOperations\Data\Casts\BoolCast;
use DragonCode\LaravelDeployOperations\Data\Casts\OperationNameCast;
use DragonCode\LaravelDeployOperations\Data\Casts\PathCast;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

class OptionsData extends Data
{
#[WithCast(BoolCast::class)]
public bool $before = false;

public ?string $connection = null;

#[WithCast(BoolCast::class)]
public bool $force = false;

#[WithCast(OperationNameCast::class)]
public ?string $name = null;

#[WithCast(PathCast::class)]
public ?string $path = null;

#[WithCast(BoolCast::class)]
public bool $realpath = false;

public ?int $step = null;

public bool $mute = false;

public bool $sync = false;

public static function prepareForPipeline(array $properties): array
{
$properties['path'] ??= '';

return $properties;
}
}
4 changes: 2 additions & 2 deletions src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function exclude(): array
->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
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

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;
use DragonCode\LaravelDeployOperations\Helpers\SorterHelper;
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Services/MigratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
82 changes: 0 additions & 82 deletions src/Values/OptionsData.php

This file was deleted.

6 changes: 5 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down