This commit is contained in:
2022-01-09 14:01:11 +08:00
parent 2288ea4778
commit 9fa7d2828c
14 changed files with 1100 additions and 1100 deletions
+43 -43
View File
@@ -1,43 +1,43 @@
<?php
declare(strict_types=1);
namespace validator;
/**
* Class EnumValidator
* @package validator
*/
class EnumValidator extends BaseValidator
{
public array $value = [];
/**
* @return bool
*/
public function trigger(): bool
{
if (empty($this->params) || !isset($this->params[$this->field])) {
return $this->addError('The param :attribute is null');
}
if (is_null($this->params[$this->field])) {
return $this->addError('The param :attribute is null');
}
if (!in_array($this->params[$this->field], $this->value)) {
return $this->addError($this->i());
}
return true;
}
/**
* @return string
*/
private function i(): string
{
return 'The param :attribute value only in ' . implode(',', $this->value);
}
}
<?php
declare(strict_types=1);
namespace validator;
/**
* Class EnumValidator
* @package validator
*/
class EnumValidator extends BaseValidator
{
public array $value = [];
/**
* @return bool
*/
public function trigger(): bool
{
if (empty($this->params) || !isset($this->params[$this->field])) {
return $this->addError('The param :attribute is null');
}
if (is_null($this->params[$this->field])) {
return $this->addError('The param :attribute is null');
}
if (!in_array($this->params[$this->field], $this->value)) {
return $this->addError($this->i());
}
return true;
}
/**
* @return string
*/
private function i(): string
{
return 'The param :attribute value only in ' . implode(',', $this->value);
}
}