Validate if given value is boolean

@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules

@return null|string
@throws ValidatorConfigException
@example 'param' => 'bool' - passed value must be boolean
978851
protected function validateBool($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        if ($value === '') {
            return null;
        }

        if (!is_bool($value) && $value !== 'true' && $value !== 'false') {
            return Message::getMessage(Message::BOOL, [
                'param' => $parameter
            ]);
        }

        return null;
    }
597733
public function validate($attribute, $rules, $value)
    {
        if (is_int($value)) {
            $value = (string)$value;
        } elseif (is_bool($value)) {
            $value = $value ? '1' : '0';
        } elseif ($value === null) {
            $value = '';
        }

        foreach ($rules as $k => $v) {
            if (is_int($k)) {
                $value = $this->_validate($attribute, $v, [], $value);
            } else {
                $value = $this->_validate($attribute, $k, is_array($v) ? $v : explode('-', $v), $value);
            }
        }

        return $value;
    }
1133595
function is_valid_parameter($parameter, $value) {

        if(is_array($value)) {
            if(!iCalendar_parameter::multiple_values_allowed($parameter)) {
                return false;
            }
            foreach($value as $item) {
                if(!iCalendar_parameter::is_valid_value($this, $parameter, $item)) {
                    return false;
                }
            }
            return true;
        }

        return iCalendar_parameter::is_valid_value($this, $parameter, $value);
    }
942584
protected function validate_boolean($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field]) && $input[$field] !== 0) {
            return;
        }

        $booleans = array('1','true',true,1,'0','false',false,0,'yes','no','on','off');
        if (in_array($input[$field], $booleans, true )) {
            return;
        }

        return array(
            'field' => $field,
            'value' => $input[$field],
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
1086605
public static function is(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $is_a_func = sprintf('is_%s', $parameters[0]);
        if (!function_exists($is_a_func)) {
            return;
        }

        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            // As "is:<type>" is validating value type only ignore null
            if (null === $value) {
                continue;
            }
            if (call_user_func($is_a_func, $value)) {
                continue;
            }

            $validator->addError($attribute, $rule, [':type' => $parameters[0]]);
        }
    }
1160047
public function validate_verify($value, $input, $args)
    {

        $userModel = config('auth.model');

        $user = $userModel::find($this->session->get('loginUserId'));


        if($user) {

            if($this->hash->verify($value, $user->password)) {
                return true;
            }

            return false;
        }

        return false;
    }
193413
public function eachValidator(array $values, ...$args): bool
    {
        if (!$validator = \array_shift($args)) {
            throw new \InvalidArgumentException('must setting a validator for \'each\' validate.');
        }

        foreach ($values as $value) {
            $passed = false;

            if (\is_object($validator) && \method_exists($validator, '__invoke')) {
                $passed = $validator($value, ...$args);
            } elseif (\is_string($validator)) {
                // special for required
                if ('required' === $validator) {
                    $passed = !Validators::isEmpty($value);

                } elseif (isset($this->_validators[$validator])) {
                    $callback = $this->_validators[$validator];
                    $passed   = $callback($value, ...$args);

                } elseif (\method_exists($this, $method = $validator . 'Validator')) {
                    $passed = $this->$method($value, ...$args);

                } elseif (\method_exists(Validators::class, $validator)) {
                    $passed = Validators::$validator($value, ...$args);

                    // it is function name
                } elseif (\function_exists($validator)) {
                    $passed = $validator($value, ...$args);
                } else {
                    throw new \InvalidArgumentException("The validator [$validator] don't exists!");
                }
            }

            if (!$passed) {
                return false;
            }
        }

        return true;
    }
451515
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        if($context->message->guild === null) {
            return 'Invalid place (not a guild channel) for argument type.';
        }
        
        $prg = \preg_match('/(?:<@!?)?(\d{15,})>?/', $value, $matches);
        if($prg === 1) {
            return $context->message->guild->fetchMember($matches[1])->then(function () {
                return true;
            }, function () {
                return false;
            });
        }
        
        $search = \mb_strtolower($value);
        
        $inexactMembers = $context->message->guild->members->filter(function ($member) use ($search) {
            return (\mb_stripos($member->user->tag, $search) !== false || \mb_stripos($member->displayName, $search) !== false);
        });
        $inexactLength = $inexactMembers->count();
        
        if($inexactLength === 0) {
             return false;
        }
        if($inexactLength === 1) {
            return true;
        }
        
        $exactMembers = $context->message->guild->members->filter(function ($member) use ($search) {
            return (\mb_strtolower($member->user->tag) === $search || \mb_strtolower($member->displayName) === $search);
        });
        $exactLength = $exactMembers->count();
        
        if($exactLength === 1) {
            return true;
        }
        
        if($exactLength > 0) {
            $members = $exactMembers;
        } else {
            $members = $inexactMembers;
        }
        
        if($members->count() >= 15) {
            return 'Multiple members found. Please be more specific.';
        }
        
        return \CharlotteDunois\Livia\Utils\DataHelpers::disambiguation($members, 'members', null).\PHP_EOL;
    }
132956
public function validateValue( $value ) : bool
   {

      if ( false === $this->hasValidator() )
      {
         return true;
      }

      return (bool) ( $this->_validator )( $value );

   }
31693
public static function isBoolean($value, $message = null)
    {
        if (!is_bool($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected boolean, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
72965
protected function validateArray($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        $count = $args[0] ?? null;

        if ($count !== null) {
            if ($count == '' || !is_numeric($count)) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}");
            }

            $count = (int)$count;

            if ($count < 0) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}, argument can not be negative");
            }
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (is_string($value) && $value === '') {
            return null;
        }

        if (!is_array($value)) {
            return Message::getMessage(Message::IS_NOT_ARRAY, [
                'param' => $parameter
            ]);
        }

        if ($count !== null) {
            $currentCount = count($value);

            if ($currentCount != $count) {
                if (ctype_digit($parameter)) {
                    $parameter = "Element on position {$parameter}";
                }

                return Message::getMessage(Message::ARRAY_WRONG_COUNT, [
                    'param' => $parameter,
                    'requiredCount' => $count,
                    'currentCount' => $currentCount
                ]);
            }
        }

        return null;
    }
558351
public function validateNotNullOrEmpty($parameter, $value)
    {
        $this->validateNotNull($parameter, $value);

        $this->validateNotEmpty($parameter, $value);

        return true;
    }
771190
public function isValid($value = null, array $options = []): bool
    {
        if (\count($options) > 0) {
            $this->setOptions($options);
        }
        $this->setValue($value);
        $this->errors = [];

        if (\strpos($this->value, '..') !== false || !\preg_match('/^(.+)@([^@]+)$/', $this->value, $matches)) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        if (!\filter_var($this->value, FILTER_VALIDATE_EMAIL) !== false) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        $host = $matches[2];
        if ($this->options['domain-check'] === true && @\gethostbyname($host) === $host) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INVALID_DOMAIN);
            return false;
        }
        if ($this->options['mx-check'] === true) {
            return $this->mxCheck($host);
        }

        return true;
    }
763293
protected function validateHex($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = trim((string)$value);

        if ($value === '') {
            return null;
        }

        if ($value[0] == '-') {
            $value = substr($value, 1);
        }

        if (!ctype_xdigit($value)) {
            return Message::getMessage(Message::HEX, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        return null;
    }
1085909
protected function _validate_bool($value)
    {
        if (is_bool($value)) {
            return (int)$value;
        }

        $trueValues = ['1', 'true', 'on'];
        $falseValues = ['0', 'false', 'off'];

        $value = strtolower($value);

        if (in_array($value, $trueValues, true)) {
            return 1;
        } elseif (in_array($value, $falseValues, true)) {
            return 0;
        } else {
            return null;
        }
    }
486958
protected function _validate_bool($value)
    {
        $trueValues = ['1', 'true'];
        $falseValues = ['0', 'false'];

        if (in_array($value, $trueValues, true)) {
            return true;
        } elseif (in_array($value, $falseValues, true)) {
            return false;
        } else {
            return null;
        }
    }
1231967
protected function verify($parameter, $value)
    {
        $type = array_get($this->model->getSearchParameters(), $parameter);

        switch ($type) {
            case 'array':
                $typeCheck = is_array($value) && ! empty(array_filter($value));
                break;
            case 'string':
                $typeCheck = ! is_numeric($value) && is_string($value) && $value !== '';
                break;
            case 'bool':
            case 'boolean':
                $typeCheck = $value != '' && (int)$value !== 2 && in_array((int)$value, [0, 1]);
                break;
            case 'int':
            case 'integer':
                $typeCheck = is_numeric($value) && (int)$value > 0;
                break;
        }

        return ! is_null($value) && $typeCheck;
    }