1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00
appwrite/src/Appwrite/Network/Validator/CNAME.php

82 lines
1.4 KiB
PHP
Raw Normal View History

2020-02-21 11:15:53 +13:00
<?php
2020-06-12 07:36:10 +12:00
namespace Appwrite\Network\Validator;
2020-02-21 11:15:53 +13:00
use Utopia\Validator;
class CNAME extends Validator
{
/**
* @var string
2020-02-21 11:15:53 +13:00
*/
protected $target;
/**
* @param string $target
*/
public function __construct($target)
{
$this->target = $target;
}
/**
* @return string
*/
2020-02-21 11:15:53 +13:00
public function getDescription()
{
return 'Invalid CNAME record';
2020-02-21 11:15:53 +13:00
}
/**
* Check if CNAME record target value matches selected target
2020-06-25 09:05:16 +12:00
*
* @param mixed $domain
2020-02-21 11:15:53 +13:00
*
* @return bool
*/
public function isValid($domain)
{
2020-10-28 08:44:15 +13:00
if (!is_string($domain)) {
2020-02-21 11:15:53 +13:00
return false;
}
try {
$records = \dns_get_record($domain, DNS_CNAME);
} catch (\Throwable $th) {
2020-02-21 11:15:53 +13:00
return false;
}
2020-06-25 09:02:27 +12:00
foreach ($records as $record) {
if (isset($record['target']) && $record['target'] === $this->target) {
2020-02-21 11:15:53 +13:00
return true;
}
}
return false;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
2020-02-21 11:15:53 +13:00
}