You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhpCliProgram/src/CliProgram/Validation/Validators/AbstractDateTimeValidator.php

38 lines
920 B
PHP

<?php
namespace jrosset\CliProgram\Validation\Validators;
use DateTimeInterface;
/**
* An argument/option value validator expecting a date and/or time
*
* @template-implements BasedValidator<RegexValidator>
*/
abstract class AbstractDateTimeValidator extends BasedValidator {
/**
* Create a validator
*/
public function __construct () {
parent::__construct(new RegexValidator($this->getPattern()));
}
/**
* @inheritDoc
*/
public function validate (mixed $value): bool {
$this->getInternalValidator()->setPattern($this->getPattern());
return parent::validate($value);
}
/**
* The date and/or time regex pattern
*
* @return string The date and/or time regex pattern
*/
protected abstract function getPattern (): string;
/**
* @inheritDoc
*/
public abstract function getValue (): DateTimeInterface;
}