2020-07-08 10:11:02 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Appwrite\Network\Validator;
|
|
|
|
|
|
|
|
use Utopia\Validator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Domain
|
|
|
|
*
|
|
|
|
* Validate that an variable is a valid domain address
|
|
|
|
*
|
|
|
|
* @package Utopia\Validator
|
|
|
|
*/
|
|
|
|
class Domain extends Validator
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get Description
|
|
|
|
*
|
|
|
|
* Returns validator description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-12-14 04:42:40 +13:00
|
|
|
public function getDescription(): string
|
2020-07-08 10:11:02 +12:00
|
|
|
{
|
|
|
|
return 'Value must be a valid domain';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is valid
|
|
|
|
*
|
|
|
|
* Validation will pass when $value is valid domain.
|
|
|
|
*
|
|
|
|
* Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123.
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-12-14 04:42:40 +13:00
|
|
|
public function isValid($value): bool
|
2020-07-08 10:11:02 +12:00
|
|
|
{
|
2020-10-28 08:44:15 +13:00
|
|
|
if (empty($value)) {
|
2020-07-08 10:11:02 +12:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-28 08:44:15 +13:00
|
|
|
if (!is_string($value)) {
|
2020-07-08 10:11:02 +12:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\filter_var($value, FILTER_VALIDATE_DOMAIN) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-13 20:46:30 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-07-08 10:11:02 +12:00
|
|
|
}
|