commit 08-2025
This commit is contained in:
parent
9ae662f63e
commit
480fdc65ed
404 changed files with 65310 additions and 2600431 deletions
69
app/Domain/DomainContext.php
Normal file
69
app/Domain/DomainContext.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Domain;
|
||||
|
||||
use App\Models\UserShop;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* DomainContext ist ein unveränderliches Datenobjekt, das den Kontext
|
||||
* der aktuellen Domain für eine einzelne Anfrage enthält.
|
||||
*
|
||||
* Es wird vom DomainServiceProvider erstellt und im Service-Container
|
||||
* registriert, damit andere Teile der Anwendung darauf zugreifen können.
|
||||
*/
|
||||
final class DomainContext
|
||||
{
|
||||
/**
|
||||
* @param string $type Der Typ der Domain (z.B. 'main', 'crm', 'user-shop').
|
||||
* @param string $host Der vollständige Hostname (z.B. 'my.mivita.care').
|
||||
* @param string|null $subdomain Die extrahierte Subdomain (z.B. 'my').
|
||||
* @param UserShop|null $userShop Das zugehörige UserShop-Objekt, falls vorhanden.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $type,
|
||||
public readonly string $host,
|
||||
public readonly ?string $subdomain,
|
||||
public readonly ?UserShop $userShop
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine neue Instanz aus einem Array von Domain-Informationen.
|
||||
*/
|
||||
public static function fromArray(array $domainInfo, ?UserShop $userShop = null): self
|
||||
{
|
||||
return new self(
|
||||
Arr::get($domainInfo, 'type', 'unknown'),
|
||||
Arr::get($domainInfo, 'host', ''),
|
||||
Arr::get($domainInfo, 'subdomain'),
|
||||
$userShop
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob es sich um eine bekannte Domain handelt.
|
||||
*/
|
||||
public function isUnknown(): bool
|
||||
{
|
||||
return $this->type === 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob es sich um eine User-Shop-Domain handelt.
|
||||
*/
|
||||
public function isUserShop(): bool
|
||||
{
|
||||
return $this->type === 'user-shop';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Slug des User-Shops zurück.
|
||||
*/
|
||||
public function getUserShopSlug(): ?string
|
||||
{
|
||||
return $this->userShop?->slug;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue