Source of file ArrayRule.php
Size: 1,096 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Validator/Rule/ArrayRule.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Validator\Rule; use Bluz\Validator\Exception\ComponentException; /** * Check for array * * @package Bluz\Validator\Rule */ class ArrayRule extends AbstractRule { /** * @var string error template */ protected $description = 'must be an array'; /** * @var callable Callback for check input array */ protected $callback; /** * Setup validation rule * * @param callable $callback * * @throws ComponentException */ public function __construct(callable $callback) { $this->callback = $callback; } /** * Check input data * * @param string $input * * @return bool */ public function validate($input): bool { if (!is_array($input)) { return false; } $filtered = array_filter($input, $this->callback); return count($input) === count($filtered); } } |