Skip to content

Replace ConfigHelper with ConfigData #204

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
Apr 1, 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
7 changes: 4 additions & 3 deletions config/deploy-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
*/

'transactions' => [
// | Determines whether the use of database transactions is enabled.
// Determines whether the use of database transactions is enabled.

'enabled' => false,

// | The number of attempts to execute a request within a transaction before throwing an error.
// The number of attempts to execute a request within a transaction before throwing an error.

'attempts' => 1,
],

Expand Down Expand Up @@ -146,6 +147,6 @@
|
*/

'full_path' => env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
'full_path' => (bool) env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

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

protected function table(): string
{
return app(ConfigHelper::class)->table();
return app(ConfigData::class)->table;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

Expand Down Expand Up @@ -39,6 +39,6 @@ protected function doesntSame(string $first, string $second): bool

protected function table(): string
{
return app(ConfigHelper::class)->table();
return app(ConfigData::class)->table;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use DragonCode\LaravelDeployOperations\Helpers\ConfigHelper;
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

Expand Down Expand Up @@ -39,6 +39,6 @@ protected function doesntSame(string $first, string $second): bool

protected function table(): string
{
return app(ConfigHelper::class)->table();
return app(ConfigData::class)->table;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

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

protected function table(): string
{
return app(ConfigHelper::class)->table();
return app(ConfigData::class)->table;
}
};
22 changes: 22 additions & 0 deletions src/Data/Casts/Config/ExcludeCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Casts\Config;

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

class ExcludeCast implements Cast
{
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): array
{
return (new Collection($value))
->map(static fn (string $path) => Str::replace(['\\', '/'], DIRECTORY_SEPARATOR, $path))
->filter()
->all();
}
}
19 changes: 19 additions & 0 deletions src/Data/Casts/Config/PathCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Casts\Config;

use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

use function rtrim;

class PathCast implements Cast
{
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
{
return rtrim($value, '\\/') . DIRECTORY_SEPARATOR;
}
}
8 changes: 4 additions & 4 deletions src/Data/Casts/PathCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace DragonCode\LaravelDeployOperations\Data\Casts;

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

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

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

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Config;

use DragonCode\LaravelDeployOperations\Data\Casts\Config\ExcludeCast;
use DragonCode\LaravelDeployOperations\Data\Casts\Config\PathCast;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

class ConfigData extends Data
{
public ?string $connection;

public string $table;

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

#[WithCast(ExcludeCast::class)]
public ?array $exclude;

public bool $async;

public TransactionsData $transactions;

public QueueData $queue;

public ShowData $show;
}
14 changes: 14 additions & 0 deletions src/Data/Config/QueueData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Config;

use Spatie\LaravelData\Data;

class QueueData extends Data
{
public ?string $connection;

public ?string $name;
}
15 changes: 15 additions & 0 deletions src/Data/Config/ShowData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Config;

use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

#[MapInputName(SnakeCaseMapper::class)]
class ShowData extends Data
{
public bool $fullPath;
}
14 changes: 14 additions & 0 deletions src/Data/Config/TransactionsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations\Data\Config;

use Spatie\LaravelData\Data;

class TransactionsData extends Data
{
public bool $enabled;

public int $attempts;
}
68 changes: 0 additions & 68 deletions src/Helpers/ConfigHelper.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Helpers/GitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@

use DragonCode\Support\Facades\Filesystem\Directory;

use function base_path;
use function exec;
use function realpath;
use function rtrim;
use function sprintf;

class GitHelper
{
public function __construct(
protected ConfigHelper $config
) {}

public function currentBranch(?string $path = null): ?string
{
if ($this->hasGitDirectory($path)) {
Expand All @@ -42,6 +39,6 @@ protected function hasGitDirectory(?string $path = null): bool

protected function resolvePath(?string $path = null): string
{
return realpath($path ?: $this->config->gitPath());
return realpath($path ?: base_path());
}
}
18 changes: 7 additions & 11 deletions src/Jobs/OperationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DragonCode\LaravelDeployOperations\Constants\Names;
use DragonCode\LaravelDeployOperations\Constants\Options;
use DragonCode\LaravelDeployOperations\Data\Config\ConfigData;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -14,7 +15,7 @@
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;

use function config;
use function app;

class OperationJob implements ShouldBeUnique, ShouldQueue
{
Expand All @@ -24,10 +25,10 @@ class OperationJob implements ShouldBeUnique, ShouldQueue
use SerializesModels;

public function __construct(
public string $filename
public string $filename,
) {
$this->setQueueConnection();
$this->setQueueName();
$this->onConnection($this->config()->queue->connection);
$this->onQueue($this->config()->queue->name);
}

public function handle(): void
Expand All @@ -43,13 +44,8 @@ public function uniqueId(): string
return $this->filename;
}

protected function setQueueConnection(): void
protected function config(): ConfigData
{
$this->onConnection(config('deploy-operations.queue.connection'));
}

protected function setQueueName(): void
{
$this->onQueue(config('deploy-operations.queue.name'));
return app(ConfigData::class);
}
}
Loading