appwrite/src/Appwrite/Task/Validator/Cron.php

68 lines
1.1 KiB
PHP
Raw Normal View History

2019-05-09 06:54:39 +00:00
<?php
namespace Appwrite\Task\Validator;
2019-05-09 06:54:39 +00:00
use Cron\CronExpression;
use Utopia\Validator;
class Cron extends Validator
{
/**
* Get Description.
2019-05-09 06:54:39 +00:00
*
* Returns validator description.
2019-05-09 06:54:39 +00:00
*
* @return string
*/
public function getDescription(): string
2019-05-09 06:54:39 +00:00
{
return 'String must be a valid cron expression';
}
/**
* Is valid.
2019-05-09 06:54:39 +00:00
*
* Returns true if valid or false if not.
*
* @param mixed $value
*
2019-05-09 06:54:39 +00:00
* @return bool
*/
public function isValid($value): bool
2019-05-09 06:54:39 +00:00
{
2020-10-27 19:44:15 +00:00
if (empty($value)) {
2020-05-12 20:18:34 +00:00
return true;
}
if (!CronExpression::isValidExpression($value)) {
2019-05-09 06:54:39 +00:00
return false;
}
return true;
}
/**
* 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;
}
}