'Select a valid tenant.', ]); } return new self( mode: self::MODE_SINGLE_TENANT, tenantId: $tenantId, ); } /** * @param array $data */ public static function fromArray(array $data): self { $mode = trim((string) ($data['mode'] ?? '')); if ($mode === '' || $mode === self::MODE_ALL_TENANTS) { return self::allTenants(); } if ($mode !== self::MODE_SINGLE_TENANT) { throw ValidationException::withMessages([ 'scope.mode' => 'Select a valid scope mode.', ]); } $tenantId = $data['tenant_id'] ?? null; if (! is_numeric($tenantId)) { throw ValidationException::withMessages([ 'scope.tenant_id' => 'Select a tenant.', ]); } return self::singleTenant((int) $tenantId); } public function isAllTenants(): bool { return $this->mode === self::MODE_ALL_TENANTS; } public function isSingleTenant(): bool { return $this->mode === self::MODE_SINGLE_TENANT; } }