Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
Show First 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | public function verify(): bool | ||||
} | } | ||||
$records = \dns_get_record($this->namespace, DNS_ANY); | $records = \dns_get_record($this->namespace, DNS_ANY); | ||||
if ($records === false) { | if ($records === false) { | ||||
throw new \Exception("Failed to get DNS record for {$this->namespace}"); | throw new \Exception("Failed to get DNS record for {$this->namespace}"); | ||||
} | } | ||||
// It may happen that result contains other domains depending on the host | // It may happen that result contains other domains depending on the host DNS setup | ||||
// DNS setup | // that's why in_array() and not just !empty() | ||||
$hosts = array_map( | if (in_array($this->namespace, array_column($records, 'host'))) { | ||||
function ($record) { | |||||
return $record['host']; | |||||
}, | |||||
$records | |||||
); | |||||
if (in_array($this->namespace, $hosts)) { | |||||
$this->status |= Domain::STATUS_VERIFIED; | $this->status |= Domain::STATUS_VERIFIED; | ||||
$this->save(); | $this->save(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Returns the wallet by which the domain is controlled | * Returns the wallet by which the domain is controlled | ||||
* | * | ||||
* @return \App\Wallet A wallet object | * @return \App\Wallet A wallet object | ||||
*/ | */ | ||||
public function wallet(): Wallet | public function wallet(): ?Wallet | ||||
{ | { | ||||
return $this->entitlement()->first()->wallet; | // Note: Not all domains have a entitlement/wallet | ||||
$entitlement = $this->entitlement()->first(); | |||||
return $entitlement ? $entitlement->wallet : null; | |||||
} | } | ||||
} | } |