2019-05-09 18:54:39 +12:00
|
|
|
<?php
|
|
|
|
|
2020-03-25 06:56:32 +13:00
|
|
|
namespace Appwrite\Database\Validator;
|
2019-05-09 18:54:39 +12:00
|
|
|
|
|
|
|
use Utopia\Validator;
|
|
|
|
|
|
|
|
class Key extends Validator
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $message = 'Parameter must contain only letters with no spaces or special chars and be shorter than 32 chars';
|
|
|
|
|
|
|
|
/**
|
2019-09-07 05:04:26 +12:00
|
|
|
* Get Description.
|
2019-05-09 18:54:39 +12:00
|
|
|
*
|
|
|
|
* Returns validator description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDescription()
|
|
|
|
{
|
|
|
|
return $this->message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-07 05:04:26 +12:00
|
|
|
* Is valid.
|
2019-05-09 18:54:39 +12:00
|
|
|
*
|
|
|
|
* Returns true if valid or false if not.
|
|
|
|
*
|
|
|
|
* @param $value
|
2019-09-07 05:04:26 +12:00
|
|
|
*
|
2019-05-09 18:54:39 +12:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isValid($value)
|
|
|
|
{
|
2020-06-25 09:02:27 +12:00
|
|
|
if (!\is_string($value)) {
|
2020-06-11 09:42:16 +12:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-20 23:05:43 +12:00
|
|
|
if (\preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
|
2019-05-09 18:54:39 +12:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-20 23:05:43 +12:00
|
|
|
if (\mb_strlen($value) > 32) {
|
2019-05-09 18:54:39 +12:00
|
|
|
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;
|
|
|
|
}
|
2019-09-07 05:04:26 +12:00
|
|
|
}
|