Files

53 lines
871 B
PHP
Raw Permalink Normal View History

2022-01-09 14:01:11 +08:00
<?php
declare(strict_types=1);
namespace validator;
use Exception;
2023-10-24 17:22:29 +08:00
/**
* Class \validator\BaseValidator
*/
2022-01-09 14:01:11 +08:00
abstract class BaseValidator
{
2023-12-18 15:01:09 +08:00
public mixed $value;
2023-12-12 15:35:34 +08:00
2023-12-18 15:01:09 +08:00
protected string $message;
2023-12-12 15:35:34 +08:00
/**
2023-12-18 15:01:09 +08:00
* @param float $value
2023-12-12 15:35:34 +08:00
* @return bool
2023-12-18 15:01:09 +08:00
* @throws Exception
2023-12-12 15:35:34 +08:00
*/
2023-12-19 14:51:13 +08:00
public function trigger(mixed $value): bool
2023-12-12 15:35:34 +08:00
{
throw new Exception('Child Class must define method of trigger');
}
2022-01-09 14:01:11 +08:00
2023-05-06 17:20:51 +08:00
/**
2023-12-18 18:24:39 +08:00
* @param string $field
* @param string $message
2023-05-06 17:20:51 +08:00
* @return bool
*/
2023-12-18 18:24:39 +08:00
public function addError(string $field, string $message): bool
2023-12-12 15:35:34 +08:00
{
2023-12-18 18:24:39 +08:00
$this->message = str_replace(':attribute', $field, $message);
2023-12-18 15:01:09 +08:00
return false;
2023-12-12 15:35:34 +08:00
}
/**
* @return string
*/
public function getError(): string
{
return $this->message;
}
2022-01-09 14:01:11 +08:00
}