Skip to content

Commit

Permalink
Merge pull request #90 from mehrancodes/format-db-name
Browse files Browse the repository at this point in the history
Format FORGE_DB_NAME internally
  • Loading branch information
mehrancodes committed Mar 18, 2024
2 parents a277776 + ae136d9 commit 46993f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Actions/FormattedBranchName.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FormattedBranchName

protected const SLUGIFY_DICTIONARY = ['+' => '-', '_' => '-', '@' => '-'];

public function handle(string $branch, ?string $pattern): string
public function handle(string $branch, ?string $pattern = null): string
{
if (isset($pattern)) {
preg_match($pattern, $branch, $matches);
Expand Down
11 changes: 8 additions & 3 deletions app/Services/Forge/ForgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Actions\FormattedBranchName;
use App\Actions\GenerateDomainName;
use App\Actions\GenerateStandardizedBranchName;
use Illuminate\Support\Str;
use Laravel\Forge\Forge;
use Laravel\Forge\Resources\Server;
use Laravel\Forge\Resources\Site;
Expand Down Expand Up @@ -89,9 +90,13 @@ public function getSiteIsolationUsername(): string

public function getFormattedDatabaseName(): string
{
return $this->setting->dbName ?? GenerateStandardizedBranchName::run(
$this->getFormattedBranchName()
);
if ($this->setting->dbName) {
$dbName = FormattedBranchName::run($this->setting->dbName);
} else {
$dbName = $this->getFormattedBranchName();
}

return Str::replace('-', '_', $dbName);
}

public function siteNginxTemplate(): string
Expand Down
11 changes: 2 additions & 9 deletions app/Services/Forge/ForgeSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class ForgeSetting
'site_isolation_required' => ['boolean'],
'job_scheduler_required' => ['boolean'],
'db_creation_required' => ['boolean'],
'db_name' => ['nullable', 'string', 'regex:/^[a-zA-Z0-9_]+$/'],
'db_name' => ['nullable', 'string'],
'auto_source_required' => ['boolean'],
'ssl_required' => ['boolean'],
'wait_on_ssl' => ['boolean'],
Expand All @@ -230,14 +230,7 @@ public function __construct()

private function init(array $configurations): void
{
$validator = Validator::make(
$configurations,
$this->validationRules,
[
'db_name.regex' => 'The :attribute must only contain letters, numbers, and underscores.'
],
['db_name' => 'FORGE_DB_NAME']
);
$validator = Validator::make($configurations, $this->validationRules);

throw_if($validator->fails(), ValidationException::class, $validator->errors()->all());

Expand Down

0 comments on commit 46993f1

Please sign in to comment.