src/Koldy/Validator.php
protected function validateAnyOf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'anyOf' must have at least one defined value; parameter={$parameter}");
        }

        if ($args[0] == '') {
            throw new ValidatorConfigException("Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}");
        }

        foreach ($args as $i => $arg) {
            $args[$i] = urldecode(trim($arg));
        }

        //$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 (!in_array($value, $args)) {
            return Message::getMessage(Message::ANY_OF, [
                'param' => $parameter,
                'value' => $value,
                'allowedValues' => implode(', ', $args)
            ]);
        }

        return null;
    }
protected function validateAnyOf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'anyOf' must have at least one defined value; parameter={$parameter}");
        }

        if ($args[0] == '') {
            throw new ValidatorConfigException("Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}");
        }

        foreach ($args as $i => $arg) {
            $args[$i] = urldecode(trim($arg));
        }

        //$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 (!in_array($value, $args)) {
            return Message::getMessage(Message::ANY_OF, [
                'param' => $parameter,
                'value' => $value,
                'allowedValues' => implode(', ', $args)
            ]);
        }

        return null;
    }
protected function validateAnyOf ( $ value , string $ parameter , array $ args = [ ] , array $ rules = null , array $ context = null ) : ? string { if ( count ( $ args ) == 0 ) { throw new ValidatorConfigException ( "Validator 'anyOf' must have at least one defined value; parameter={$parameter}" ) ; } if ( $ args [ 0 ] == '' ) { throw new ValidatorConfigException ( "Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}" ) ; } foreach ( $ args as $ i => $ arg ) { $ args [ $ i ] = urldecode ( trim ( $ arg ) ) ; } //$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 ( ! in_array ( $ value , $ args ) ) { return Message :: getMessage ( Message :: ANY_OF , [ 'param' => $ parameter , 'value' => $ value , 'allowedValues' => implode ( ', ' , $ args ) ] ) ; } return null ; }
Validate if value is any of allowed values

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

@return null|string
@throws ValidatorConfigException
@example 'param' => 'anyOf:one,two,3,four'
@example 'param' => 'anyOf:one,two%2C maybe three' // if comma needs to be used, then urlencode it
Validate if value is any of allowed values