Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/ResourceObserver.php
Show All 9 Lines | class ResourceObserver | ||||
* Handle the resource "creating" event. | * Handle the resource "creating" event. | ||||
* | * | ||||
* @param \App\Resource $resource The resource | * @param \App\Resource $resource The resource | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function creating(Resource $resource): void | public function creating(Resource $resource): void | ||||
{ | { | ||||
if (empty($resource->email)) { | |||||
if (!isset($resource->domain)) { | |||||
throw new \Exception("Missing 'domain' property for a new resource"); | |||||
} | |||||
$domainName = \strtolower($resource->domain); | |||||
$resource->email = "resource-{$resource->id}@{$domainName}"; | |||||
} else { | |||||
$resource->email = \strtolower($resource->email); | |||||
} | |||||
$resource->status |= Resource::STATUS_NEW | Resource::STATUS_ACTIVE; | $resource->status |= Resource::STATUS_NEW | Resource::STATUS_ACTIVE; | ||||
} | } | ||||
/** | /** | ||||
* Handle the resource "created" event. | * Handle the resource "created" event. | ||||
* | * | ||||
* @param \App\Resource $resource The resource | * @param \App\Resource $resource The resource | ||||
* | * | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |