catchAdmin/extend/catcher/base/CatchValidate.php

47 lines
872 B
PHP
Raw Normal View History

2019-12-06 09:17:40 +08:00
<?php
namespace catcher\base;
2019-12-07 17:31:38 +08:00
use catcher\validates\Sometimes;
2019-12-06 09:17:40 +08:00
use think\Validate;
2019-12-12 09:14:08 +08:00
abstract class CatchValidate extends Validate
2019-12-06 09:17:40 +08:00
{
public function __construct()
{
parent::__construct();
$this->register();
$this->rule = $this->getRules();
}
abstract protected function getRules(): array ;
2019-12-07 17:31:38 +08:00
/**
*
* @time 2019年12月07日
* @return void
*/
private function register(): void
2019-12-06 09:17:40 +08:00
{
if (!empty($this->newValidates())) {
foreach ($this->newValidates() as $validate) {
$this->extend($validate->type(), [$validate, 'verify'], $validate->message());
}
}
}
2019-12-07 17:31:38 +08:00
/**
*
* @time 2019年12月07日
* @return array
*/
private function newValidates(): array
2019-12-06 09:17:40 +08:00
{
return [
2019-12-07 17:31:38 +08:00
new Sometimes(),
2019-12-06 09:17:40 +08:00
];
}
}