mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Because traits are behaviors that are added to a class, it makes sense to name them with the behavior that they add the classes that use them. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
44 lines
950 B
PHP
44 lines
950 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use Respect\Validation\Helpers\CanValidateUndefined;
|
|
|
|
/**
|
|
* Abstract class for searches into arrays.
|
|
*
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
abstract class AbstractSearcher extends AbstractRule
|
|
{
|
|
use CanValidateUndefined;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
abstract protected function getDataSource(): array;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function validate($input): bool
|
|
{
|
|
$dataSource = $this->getDataSource();
|
|
if ($this->isUndefined($input) && empty($dataSource)) {
|
|
return true;
|
|
}
|
|
|
|
return in_array($input, $dataSource, true);
|
|
}
|
|
}
|