Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
Show All 38 Lines | class Domain extends Model | ||||
public const STATUS_DELETED = 1 << 3; | public const STATUS_DELETED = 1 << 3; | ||||
// ownership of the domain has been confirmed | // ownership of the domain has been confirmed | ||||
public const STATUS_CONFIRMED = 1 << 4; | public const STATUS_CONFIRMED = 1 << 4; | ||||
// domain has been verified that it exists in DNS | // domain has been verified that it exists in DNS | ||||
public const STATUS_VERIFIED = 1 << 5; | public const STATUS_VERIFIED = 1 << 5; | ||||
// domain has been created in LDAP | // domain has been created in LDAP | ||||
public const STATUS_LDAP_READY = 1 << 6; | public const STATUS_LDAP_READY = 1 << 6; | ||||
/** @var int The allowed states for this object used in StatusPropertyTrait */ | |||||
private int $allowed_states = self::STATUS_NEW | | |||||
self::STATUS_ACTIVE | | |||||
self::STATUS_SUSPENDED | | |||||
self::STATUS_DELETED | | |||||
self::STATUS_CONFIRMED | | |||||
self::STATUS_VERIFIED | | |||||
self::STATUS_LDAP_READY; | |||||
// open for public registration | // open for public registration | ||||
public const TYPE_PUBLIC = 1 << 0; | public const TYPE_PUBLIC = 1 << 0; | ||||
// zone hosted with us | // zone hosted with us | ||||
public const TYPE_HOSTED = 1 << 1; | public const TYPE_HOSTED = 1 << 1; | ||||
// zone registered externally | // zone registered externally | ||||
public const TYPE_EXTERNAL = 1 << 2; | public const TYPE_EXTERNAL = 1 << 2; | ||||
public const HASH_CODE = 1; | public const HASH_CODE = 1; | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | class Domain extends Model | ||||
/** | /** | ||||
* Domain status mutator | * Domain status mutator | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
public function setStatusAttribute($status) | public function setStatusAttribute($status) | ||||
{ | { | ||||
$new_status = 0; | // Detect invalid flags | ||||
if ($status & ~$this->allowed_states) { | |||||
$allowed_values = [ | |||||
self::STATUS_NEW, | |||||
self::STATUS_ACTIVE, | |||||
self::STATUS_SUSPENDED, | |||||
self::STATUS_DELETED, | |||||
self::STATUS_CONFIRMED, | |||||
self::STATUS_VERIFIED, | |||||
self::STATUS_LDAP_READY, | |||||
]; | |||||
foreach ($allowed_values as $value) { | |||||
if ($status & $value) { | |||||
$new_status |= $value; | |||||
$status ^= $value; | |||||
} | |||||
} | |||||
if ($status > 0) { | |||||
throw new \Exception("Invalid domain status: {$status}"); | throw new \Exception("Invalid domain status: {$status}"); | ||||
} | } | ||||
$new_status = $status; | |||||
if ($this->isPublic()) { | if ($this->isPublic()) { | ||||
$this->attributes['status'] = $new_status; | $this->attributes['status'] = $new_status; | ||||
return; | return; | ||||
} | } | ||||
if ($new_status & self::STATUS_CONFIRMED) { | if ($new_status & self::STATUS_CONFIRMED) { | ||||
// if we have confirmed ownership of or management access to the domain, then we have | // if we have confirmed ownership of or management access to the domain, then we have | ||||
// also confirmed the domain exists in DNS. | // also confirmed the domain exists in DNS. | ||||
▲ Show 20 Lines • Show All 227 Lines • Show Last 20 Lines |