2015-04-24 19:55:00 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-04-24 19:55:00 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-03 12:18:30 +02:00
|
|
|
use Respect\Validation\Helpers\CanValidateUndefined;
|
2019-02-17 19:41:55 +01:00
|
|
|
use function in_array;
|
2018-01-18 20:28:51 +01:00
|
|
|
|
2018-01-18 20:27:32 +01:00
|
|
|
/**
|
|
|
|
* Abstract class for searches into arrays.
|
|
|
|
*
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
2015-04-24 19:55:00 +02:00
|
|
|
abstract class AbstractSearcher extends AbstractRule
|
|
|
|
{
|
2018-09-03 12:18:30 +02:00
|
|
|
use CanValidateUndefined;
|
2018-01-18 20:28:51 +01:00
|
|
|
|
2018-01-18 20:27:32 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-18 20:27:32 +01:00
|
|
|
*/
|
|
|
|
public function validate($input): bool
|
2015-04-24 19:55:00 +02:00
|
|
|
{
|
2018-01-18 20:27:32 +01:00
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
if ($this->isUndefined($input) && empty($dataSource)) {
|
|
|
|
return true;
|
2015-04-24 19:55:00 +02:00
|
|
|
}
|
|
|
|
|
2018-01-18 20:27:32 +01:00
|
|
|
return in_array($input, $dataSource, true);
|
2015-04-24 19:55:00 +02:00
|
|
|
}
|
2019-05-11 19:59:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed[]
|
|
|
|
*/
|
|
|
|
abstract protected function getDataSource(): array;
|
2015-04-24 19:55:00 +02:00
|
|
|
}
|