Skip to content

Commit ac60794

Browse files
Replaced deprecated dragon-code/simple-dto with spatie/laravel-data
1 parent 4d933c9 commit ac60794

File tree

11 files changed

+134
-93
lines changed

11 files changed

+134
-93
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
"require": {
4141
"php": "^8.2",
4242
"composer-runtime-api": "^2.2",
43-
"dragon-code/simple-dto": "^2.5.1",
4443
"dragon-code/support": "^6.6",
4544
"illuminate/console": "^10.0 || ^11.0 || ^12.0",
4645
"illuminate/container": "^10.0 || ^11.0 || ^12.0",
4746
"illuminate/database": "^10.0 || ^11.0 || ^12.0",
4847
"illuminate/support": "^10.0 || ^11.0 || ^12.0",
4948
"laravel/prompts": ">=0.1",
49+
"spatie/laravel-data": "^4.14",
5050
"symfony/console": "^6.0 || ^7.0"
5151
},
5252
"require-dev": {

src/Console/Command.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use DragonCode\LaravelDeployOperations\Concerns\ConfirmableTrait;
88
use DragonCode\LaravelDeployOperations\Concerns\HasIsolatable;
99
use DragonCode\LaravelDeployOperations\Concerns\HasOptionable;
10+
use DragonCode\LaravelDeployOperations\Data\OptionsData;
1011
use DragonCode\LaravelDeployOperations\Processors\Processor;
11-
use DragonCode\LaravelDeployOperations\Values\OptionsData;
1212
use Illuminate\Console\Command as BaseCommand;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Output\OutputInterface;
@@ -56,14 +56,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656
protected function resolveProcessor(): Processor
5757
{
5858
return app($this->processor, [
59-
'options' => $this->getOptionsDto(),
59+
'options' => $this->getOptionsData(),
6060
'input' => $this->input,
6161
'output' => $this->output,
6262
]);
6363
}
6464

65-
protected function getOptionsDto(): OptionsData
65+
protected function getOptionsData(): OptionsData
6666
{
67-
return OptionsData::fromArray(array_merge($this->options(), $this->arguments()))->resolvePath();
67+
return OptionsData::from(array_merge($this->options(), $this->arguments()));
6868
}
6969
}

src/Data/Casts/BoolCast.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Data\Casts;
6+
7+
use DragonCode\Support\Facades\Helpers\Boolean;
8+
use Spatie\LaravelData\Casts\Cast;
9+
use Spatie\LaravelData\Support\Creation\CreationContext;
10+
use Spatie\LaravelData\Support\DataProperty;
11+
12+
class BoolCast implements Cast
13+
{
14+
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): bool
15+
{
16+
return Boolean::parse($value);
17+
}
18+
}

src/Data/Casts/OperationNameCast.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Data\Casts;
6+
7+
use DragonCode\Support\Facades\Helpers\Str;
8+
use Spatie\LaravelData\Casts\Cast;
9+
use Spatie\LaravelData\Support\Creation\CreationContext;
10+
use Spatie\LaravelData\Support\DataProperty;
11+
12+
class OperationNameCast implements Cast
13+
{
14+
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): ?string
15+
{
16+
if (empty($value)) {
17+
return null;
18+
}
19+
20+
return Str::of($value)
21+
->replace('\\', '/')
22+
->replace('.php', '')
23+
->explode('/')
24+
->map(fn (string $path) => Str::snake($path))
25+
->implode(DIRECTORY_SEPARATOR)
26+
->toString();
27+
}
28+
}

src/Data/Casts/PathCast.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Data\Casts;
6+
7+
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
8+
use Spatie\LaravelData\Casts\Cast;
9+
use Spatie\LaravelData\Support\Creation\CreationContext;
10+
use Spatie\LaravelData\Support\DataProperty;
11+
12+
use function app;
13+
14+
class PathCast implements Cast
15+
{
16+
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
17+
{
18+
if ($properties['realpath'] ?? false) {
19+
return $value ?: $this->config()->basePath();
20+
}
21+
22+
return $this->config()->basePath($value);
23+
}
24+
25+
protected function config(): ConfigHelper
26+
{
27+
return app(ConfigHelper::class);
28+
}
29+
}

src/Data/OptionsData.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Data;
6+
7+
use DragonCode\LaravelDeployOperations\Data\Casts\BoolCast;
8+
use DragonCode\LaravelDeployOperations\Data\Casts\OperationNameCast;
9+
use DragonCode\LaravelDeployOperations\Data\Casts\PathCast;
10+
use Spatie\LaravelData\Attributes\WithCast;
11+
use Spatie\LaravelData\Data;
12+
13+
class OptionsData extends Data
14+
{
15+
#[WithCast(BoolCast::class)]
16+
public bool $before = false;
17+
18+
public ?string $connection = null;
19+
20+
#[WithCast(BoolCast::class)]
21+
public bool $force = false;
22+
23+
#[WithCast(OperationNameCast::class)]
24+
public ?string $name = null;
25+
26+
#[WithCast(PathCast::class)]
27+
public ?string $path = null;
28+
29+
#[WithCast(BoolCast::class)]
30+
public bool $realpath = false;
31+
32+
public ?int $step = null;
33+
34+
public bool $mute = false;
35+
36+
public bool $sync = false;
37+
38+
public static function prepareForPipeline(array $properties): array
39+
{
40+
$properties['path'] ??= '';
41+
42+
return $properties;
43+
}
44+
}

src/Helpers/ConfigHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function exclude(): array
4646
->toArray();
4747
}
4848

49-
public function path(?string $path = null): string
49+
public function basePath(string $path = ''): string
5050
{
51-
return rtrim($this->directory(), '\\/') . DIRECTORY_SEPARATOR . ltrim((string) $path, '\\/');
51+
return rtrim($this->directory(), '\\/') . DIRECTORY_SEPARATOR . ltrim($path, '\\/');
5252
}
5353

5454
public function gitPath(): string

src/Processors/Processor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Closure;
88
use DragonCode\LaravelDeployOperations\Concerns\HasArtisan;
9+
use DragonCode\LaravelDeployOperations\Data\OptionsData;
910
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
1011
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
1112
use DragonCode\LaravelDeployOperations\Helpers\GitHelper;
1213
use DragonCode\LaravelDeployOperations\Helpers\SorterHelper;
1314
use DragonCode\LaravelDeployOperations\Notifications\Notification;
1415
use DragonCode\LaravelDeployOperations\Repositories\OperationsRepository;
1516
use DragonCode\LaravelDeployOperations\Services\MigratorService;
16-
use DragonCode\LaravelDeployOperations\Values\OptionsData;
1717
use DragonCode\Support\Facades\Helpers\Arr;
1818
use DragonCode\Support\Facades\Helpers\Str;
1919
use DragonCode\Support\Filesystem\File;

src/Services/MigratorService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace DragonCode\LaravelDeployOperations\Services;
66

7+
use DragonCode\LaravelDeployOperations\Data\OptionsData;
78
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
89
use DragonCode\LaravelDeployOperations\Jobs\OperationJob;
910
use DragonCode\LaravelDeployOperations\Notifications\Notification;
1011
use DragonCode\LaravelDeployOperations\Operation;
1112
use DragonCode\LaravelDeployOperations\Repositories\OperationsRepository;
12-
use DragonCode\LaravelDeployOperations\Values\OptionsData;
1313
use DragonCode\Support\Exceptions\FileNotFoundException;
1414
use DragonCode\Support\Facades\Helpers\Str;
1515
use DragonCode\Support\Filesystem\File;
@@ -168,7 +168,7 @@ protected function resolveOperation(string $path): Operation
168168
protected function resolveOperationName(string $path): string
169169
{
170170
return Str::of(realpath($path))
171-
->after(realpath($this->config->path()) . DIRECTORY_SEPARATOR)
171+
->after(realpath($this->config->basePath()) . DIRECTORY_SEPARATOR)
172172
->replace(['\\', '/'], '/')
173173
->before('.php')
174174
->toString();

src/Values/OptionsData.php

-82
This file was deleted.

tests/TestCase.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Foundation\Testing\RefreshDatabase;
1212
use Illuminate\Support\Facades\DB;
1313
use Orchestra\Testbench\TestCase as BaseTestCase;
14+
use Spatie\LaravelData\LaravelDataServiceProvider;
1415
use Tests\Concerns\AssertDatabase;
1516
use Tests\Concerns\Database;
1617
use Tests\Concerns\Files;
@@ -32,7 +33,10 @@ protected function setUp(): void
3233

3334
protected function getPackageProviders($app): array
3435
{
35-
return [ServiceProvider::class];
36+
return [
37+
ServiceProvider::class,
38+
LaravelDataServiceProvider::class,
39+
];
3640
}
3741

3842
protected function getEnvironmentSetUp($app): void

0 commit comments

Comments
 (0)