$params]; } elseif (is_array($params)) { // Convert not associative array to allowed list if (! Arr::isAssoc($params)) { $params = ['allowed' => $params]; } elseif (array_key_exists(0, $params) && sizeof($params) > 1) { $this->setAllowed(array_shift($params)); } } return $params; } /** * Set allowed values list * @param array|Closure $allowed * @return bool */ protected function setAllowed($allowed) { if (empty($allowed)) { return false; } $this->allowed = $allowed; return true; } /** * Set strict value comparing mode * @param bool $strict * @return bool */ protected function setStrict($strict = true) { $this->strict = ! empty($strict); return true; } /** * Set strict value comparing mode * @param bool $strict * @return static */ public function strict($strict = true) { $this->setStrict($strict); return $this; } public function check(&$value) { $allowed = $this->fromClosure($this->allowed); if (! is_array($allowed)) { return false; } if (is_array($value)) { return false; } if (! $this->isNot()) { return in_array($value, $allowed, $this->strict); } else { return ! in_array($value, $allowed, $this->strict); } } }