Add BootstrapTenantController and requests for tenant domain normalization; implement API route and tests

This commit is contained in:
2026-06-23 09:49:54 -03:00
parent 6d83d3dd7d
commit 3c6469617b
10 changed files with 399 additions and 34 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Domains\Tenant\Requests;
use App\Domains\Tenant\Support\TenantDomainNormalizer;
use Closure;
use Illuminate\Foundation\Http\FormRequest;
class BootstrapTenantRequest extends FormRequest
{
protected bool $hasInvalidDomain = false;
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$rawDomain = $this->route('dominio');
$normalizedDomain = TenantDomainNormalizer::normalize($rawDomain);
$this->hasInvalidDomain = TenantDomainNormalizer::hasValue($rawDomain)
&& $normalizedDomain === null;
$this->merge([
'dominio' => $normalizedDomain,
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'dominio' => [
'bail',
function (string $attribute, mixed $value, Closure $fail): void {
if ($this->hasInvalidDomain) {
$fail("The {$attribute} field must contain a valid domain or URL.");
}
},
'required',
'string',
'max:255',
],
];
}
}