Source of file ContainsRule.php
Size: 1,309 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Validator/Rule/ContainsRule.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Validator\Rule; /** * Check for contains * * @package Bluz\Validator\Rule */ class ContainsRule extends AbstractRule { /** * @var string needle for search inside input data (haystack) */ protected $containsValue; /** * Setup validation rule * * @param mixed $containsValue */ public function __construct($containsValue) { $this->containsValue = $containsValue; } /** * Check input data * * @param string|array $input * * @return bool */ public function validate($input): bool { // for array if (is_array($input)) { return in_array($this->containsValue, $input, false); } // for string if (is_string($input)) { return false !== mb_stripos($input, $this->containsValue, 0, mb_detect_encoding($input)); } // can't compare return false; } /** * Get error template * * @return string */ public function getDescription() : string { return __('must contain the value "%s"', $this->containsValue); } } |