respect-validation/library/Rules/In.php
Henrique Moody da193b75e0 Use PSR-2 standard
Most changes was made by php-cs-fixer.
Also removes unused `RecursiveTreeIterator` class.
2015-01-08 00:44:12 -02:00

38 lines
943 B
PHP

<?php
namespace Respect\Validation\Rules;
class In extends AbstractRule
{
public $haystack;
public $compareIdentical;
public function __construct($haystack, $compareIdentical = false)
{
$this->haystack = $haystack;
$this->compareIdentical = $compareIdentical;
}
public function reportError($input, array $extraParams = array())
{
return parent::reportError($input, $extraParams);
}
public function validate($input)
{
if (is_array($this->haystack)) {
return in_array($input, $this->haystack, $this->compareIdentical);
}
if (!is_string($this->haystack)) {
return false;
}
$enc = mb_detect_encoding($input);
if ($this->compareIdentical) {
return mb_strpos($this->haystack, $input, 0, $enc) !== false;
}
return mb_stripos($this->haystack, $input, 0, $enc) !== false;
}
}