Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\Api\Validator\Rule;
|
||||
|
||||
use Rakit\Validation\MissingRequiredParameterException;
|
||||
use Rakit\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Regel prüft ob ein valides Zeitformat vorliegt.
|
||||
*/
|
||||
class TimeRule extends Rule
|
||||
{
|
||||
/** @var string $message */
|
||||
protected $message = "The attribute ':attribute' is not valid time format. Format ':format' is required.";
|
||||
|
||||
/** @var array $fillable_params */
|
||||
protected $fillable_params = ['format'];
|
||||
|
||||
/** @var array $params */
|
||||
protected $params = [
|
||||
'format' => 'H:i:s',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws MissingRequiredParameterException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check($value)
|
||||
{
|
||||
$this->requireParameters($this->fillable_params);
|
||||
|
||||
$format = $this->parameter('format');
|
||||
|
||||
return date_create_from_format('Y-m-d ' . $format, '2019-01-01 ' . $value) !== false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user