mirror of
https://github.com/Respect/Validation.git
synced 2024-05-17 21:56:40 +02:00
272f18dcf5
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
46 lines
975 B
PHP
46 lines
975 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;
|
|
use function in_array;
|
|
|
|
/**
|
|
* Abstract class for searches into arrays.
|
|
*
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
abstract class AbstractSearcher extends AbstractRule
|
|
{
|
|
use CanValidateUndefined;
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function validate($input): bool
|
|
{
|
|
$dataSource = $this->getDataSource();
|
|
if ($this->isUndefined($input) && empty($dataSource)) {
|
|
return true;
|
|
}
|
|
|
|
return in_array($input, $dataSource, true);
|
|
}
|
|
|
|
/**
|
|
* @return mixed[]
|
|
*/
|
|
abstract protected function getDataSource(): array;
|
|
}
|