1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00
appwrite/src/Appwrite/Network/Validator/CNAME.php
Eldad A. Fux 042660b15c
Feat psalm analysis (#699)
* Added static code analysis
* Updated code to solve psalm issue
2020-10-27 02:08:29 +02:00

58 lines
1 KiB
PHP

<?php
namespace Appwrite\Network\Validator;
use Utopia\Validator;
class CNAME extends Validator
{
/**
* @var string
*/
protected $target;
/**
* @param string $target
*/
public function __construct($target)
{
$this->target = $target;
}
/**
* @return string
*/
public function getDescription()
{
return 'Invalid CNAME record';
}
/**
* Check if CNAME record target value matches selected target
*
* @param mixed $domain
*
* @return bool
*/
public function isValid($domain)
{
if(!is_string($domain)) {
return false;
}
try {
$records = \dns_get_record($domain, DNS_CNAME);
} catch (\Throwable $th) {
return false;
}
foreach ($records as $record) {
if (isset($record['target']) && $record['target'] === $this->target) {
return true;
}
}
return false;
}
}