Skip to content

Commit ae7beb6

Browse files
Replace ConfigHelper with ConfigData
1 parent 34978e3 commit ae7beb6

26 files changed

+193
-129
lines changed

config/deploy-operations.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
*/
4040

4141
'transactions' => [
42-
// | Determines whether the use of database transactions is enabled.
42+
// Determines whether the use of database transactions is enabled.
4343

4444
'enabled' => false,
4545

46-
// | The number of attempts to execute a request within a transaction before throwing an error.
46+
// The number of attempts to execute a request within a transaction before throwing an error.
47+
4748
'attempts' => 1,
4849
],
4950

@@ -146,6 +147,6 @@
146147
|
147148
*/
148149

149-
'full_path' => env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
150+
'full_path' => (bool) env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
150151
],
151152
];

database/migrations/2022_08_18_180137_change_migration_actions_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
5+
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
66
use Illuminate\Database\Migrations\Migration;
77
use Illuminate\Database\Schema\Blueprint;
88
use Illuminate\Support\Facades\Schema;
@@ -49,6 +49,6 @@ protected function doesntHaveColumn(string $column): bool
4949

5050
protected function table(): string
5151
{
52-
return app(ConfigHelper::class)->table();
52+
return app(ConfigData::class)->table;
5353
}
5454
};

database/migrations/2023_01_21_172923_rename_migrations_actions_table_to_actions.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
5+
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
66
use Illuminate\Database\Migrations\Migration;
77
use Illuminate\Support\Facades\Schema;
88

@@ -28,7 +28,13 @@ public function down(): void
2828
protected function validateTable(string $name): void
2929
{
3030
if (Schema::hasTable($name)) {
31-
throw new RuntimeException(sprintf('A table named [%s] already exists. Change the table name settings in the [%s] configuration file.', $name, 'config/actions.php'));
31+
throw new RuntimeException(
32+
sprintf(
33+
'A table named [%s] already exists. Change the table name settings in the [%s] configuration file.',
34+
$name,
35+
'config/actions.php'
36+
)
37+
);
3238
}
3339
}
3440

@@ -39,6 +45,6 @@ protected function doesntSame(string $first, string $second): bool
3945

4046
protected function table(): string
4147
{
42-
return app(ConfigHelper::class)->table();
48+
return app(ConfigData::class)->table;
4349
}
4450
};

database/migrations/2024_05_21_112438_rename_actions_table_to_operations.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
5+
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
66
use Illuminate\Database\Migrations\Migration;
77
use Illuminate\Support\Facades\Schema;
88

@@ -28,7 +28,13 @@ public function down(): void
2828
protected function validateTable(string $name): void
2929
{
3030
if (Schema::hasTable($name)) {
31-
throw new RuntimeException(sprintf('A table named [%s] already exists. Change the table name settings in the [%s] configuration file.', $name, 'config/deploy-operations.php'));
31+
throw new RuntimeException(
32+
sprintf(
33+
'A table named [%s] already exists. Change the table name settings in the [%s] configuration file.',
34+
$name,
35+
'config/deploy-operations.php'
36+
)
37+
);
3238
}
3339
}
3440

@@ -39,6 +45,6 @@ protected function doesntSame(string $first, string $second): bool
3945

4046
protected function table(): string
4147
{
42-
return app(ConfigHelper::class)->table();
48+
return app(ConfigData::class)->table;
4349
}
4450
};

database/migrations/2024_05_21_114318_rename_column_in_operations_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
5+
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
66
use Illuminate\Database\Migrations\Migration;
77
use Illuminate\Database\Schema\Blueprint;
88
use Illuminate\Support\Facades\Schema;
@@ -27,6 +27,6 @@ protected function rename(string $from, string $to): void
2727

2828
protected function table(): string
2929
{
30-
return app(ConfigHelper::class)->table();
30+
return app(ConfigData::class)->table;
3131
}
3232
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace DragonCode\LaravelDeployOperations\Data\Casts\Config;
4+
5+
use Illuminate\Support\Collection;
6+
use Illuminate\Support\Str;
7+
use Spatie\LaravelData\Casts\Cast;
8+
use Spatie\LaravelData\Support\Creation\CreationContext;
9+
use Spatie\LaravelData\Support\DataProperty;
10+
11+
class ExcludeCast implements Cast
12+
{
13+
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): array
14+
{
15+
return (new Collection($value))
16+
->map(static fn (string $path) => Str::replace(['\\', '/'], DIRECTORY_SEPARATOR, $path))
17+
->filter()
18+
->all();
19+
}
20+
}

src/Data/Casts/Config/PathCast.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace DragonCode\LaravelDeployOperations\Data\Casts\Config;
4+
5+
use Spatie\LaravelData\Casts\Cast;
6+
use Spatie\LaravelData\Support\Creation\CreationContext;
7+
use Spatie\LaravelData\Support\DataProperty;
8+
9+
use function rtrim;
10+
11+
class PathCast implements Cast
12+
{
13+
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
14+
{
15+
return rtrim($value, '\\/') . DIRECTORY_SEPARATOR;
16+
}
17+
}

src/Data/Casts/OperationNameCast.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public function cast(DataProperty $property, mixed $value, array $properties, Cr
1818
}
1919

2020
return Str::of($value)
21-
->replace('\\', '/')
21+
->replace('\\', DIRECTORY_SEPARATOR)
2222
->replace('.php', '')
23-
->explode('/')
23+
->explode(DIRECTORY_SEPARATOR)
2424
->map(fn (string $path) => Str::snake($path))
2525
->implode(DIRECTORY_SEPARATOR)
2626
->toString();

src/Data/Casts/PathCast.php

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

55
namespace DragonCode\LaravelDeployOperations\Data\Casts;
66

7-
use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
7+
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
88
use Illuminate\Support\Str;
99
use Spatie\LaravelData\Casts\Cast;
1010
use Spatie\LaravelData\Support\Creation\CreationContext;
@@ -17,7 +17,7 @@ class PathCast implements Cast
1717
{
1818
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
1919
{
20-
$path = $this->config()->basePath((string) $value);
20+
$path = $this->config()->path . $value;
2121

2222
if ($properties['realpath'] ?? false) {
2323
return $value ?: $path;
@@ -31,8 +31,8 @@ protected function filename(string $path): false|string
3131
return realpath(Str::finish($path, '.php'));
3232
}
3333

34-
protected function config(): ConfigHelper
34+
protected function config(): ConfigData
3535
{
36-
return app(ConfigHelper::class);
36+
return app(ConfigData::class);
3737
}
3838
}

src/Data/Config/ConfigData.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Data\Config;
6+
7+
use DragonCode\LaravelDeployOperations\Data\Casts\Config\ExcludeCast;
8+
use DragonCode\LaravelDeployOperations\Data\Casts\Config\PathCast;
9+
use Spatie\LaravelData\Attributes\WithCast;
10+
use Spatie\LaravelData\Data;
11+
12+
class ConfigData extends Data
13+
{
14+
public ?string $connection;
15+
16+
public string $table;
17+
18+
#[WithCast(PathCast::class)]
19+
public string $path;
20+
21+
#[WithCast(ExcludeCast::class)]
22+
public ?array $exclude;
23+
24+
public bool $async;
25+
26+
public TransactionsData $transactions;
27+
28+
public QueueData $queue;
29+
30+
public ShowData $show;
31+
}

0 commit comments

Comments
 (0)