src/BaseValidator.php
protected function validateEnum($value, $parsedValue)
    {
        $return = new ValidateResult($parsedValue, false);

        //Check if $this->enum is set and it's not null since its optional
        if ($this->enum !== null) {
            if (is_object($value)) {
                throw new \Exception('Objects are not supported');
            }

            //Search current $value in enum
            foreach ($this->enum as $v) {
                if (is_object($v)) {
                    throw new \Exception('Objects are not supported');
                }

                if ($value == $v) {
                    if ($this->validateType && ($valueType = gettype($value)) !== ($vType = gettype($v))) {
                        continue;
                    }

                    //Success value is found

                    //Overwrite $return's value (get correct object type)
                    $return->value = $v;

                    //Set status to true
                    $return->status = true;

                    return $return;
                } elseif (is_array($value)
                    && is_array($v)
                    && ArrayValidator::equals($value, $v)
                ) {
                    //Type is same (arrays)
                    //Success value is found

                    //Overwrite $return's value (get correct object type)
                    $return->value = $v;

                    //Set status to true
                    $return->status = true;

                    return $return;
                }
            }

            $return->status = false;
            //Error
            $return->errorObject = new IncorrectParametersException([[
                'type' => static::getType(),
                'failure' => 'enum'
            ]]);
        }

        return $return;
    }
protected function validateEnum($value, $parsedValue)
    {
        $return = new ValidateResult($parsedValue, false);

        //Check if $this->enum is set and it's not null since its optional
        if ($this->enum !== null) {
            if (is_object($value)) {
                throw new \Exception('Objects are not supported');
            }

            //Search current $value in enum
            foreach ($this->enum as $v) {
                if (is_object($v)) {
                    throw new \Exception('Objects are not supported');
                }

                if ($value == $v) {
                    if ($this->validateType && ($valueType = gettype($value)) !== ($vType = gettype($v))) {
                        continue;
                    }

                    //Success value is found

                    //Overwrite $return's value (get correct object type)
                    $return->value = $v;

                    //Set status to true
                    $return->status = true;

                    return $return;
                } elseif (is_array($value)
                    && is_array($v)
                    && ArrayValidator::equals($value, $v)
                ) {
                    //Type is same (arrays)
                    //Success value is found

                    //Overwrite $return's value (get correct object type)
                    $return->value = $v;

                    //Set status to true
                    $return->status = true;

                    return $return;
                }
            }

            $return->status = false;
            //Error
            $return->errorObject = new IncorrectParametersException([[
                'type' => static::getType(),
                'failure' => 'enum'
            ]]);
        }

        return $return;
    }
protected function validateEnum ( $ value , $ parsedValue ) { $ return = new ValidateResult ( $ parsedValue , false ) ; //Check if $this->enum is set and it's not null since its optional if ( $ this -> enum !== null ) { if ( is_object ( $ value ) ) { throw new \ Exception ( 'Objects are not supported' ) ; } //Search current $value in enum foreach ( $ this -> enum as $ v ) { if ( is_object ( $ v ) ) { throw new \ Exception ( 'Objects are not supported' ) ; } if ( $ value == $ v ) { if ( $ this -> validateType && ( $ valueType = gettype ( $ value ) ) !== ( $ vType = gettype ( $ v ) ) ) { continue ; } //Success value is found //Overwrite $return's value (get correct object type) $ return -> value = $ v ; //Set status to true $ return -> status = true ; return $ return ; } elseif ( is_array ( $ value ) && is_array ( $ v ) && ArrayValidator :: equals ( $ value , $ v ) ) { //Type is same (arrays) //Success value is found //Overwrite $return's value (get correct object type) $ return -> value = $ v ; //Set status to true $ return -> status = true ; return $ return ; } } $ return -> status = false ; //Error $ return -> errorObject = new IncorrectParametersException ( [ [ 'type' => static :: getType ( ) , 'failure' => 'enum' ] ] ) ; } return $ return ; }
Common helper method to validate against "enum" keyword
@see 5.5.1. enum http://json-schema.org/latest/json-schema-validation.html#anchor75
@param  mixed $value Value to validate
@param  mixed $value Parsed value from previous validators
@return ValidateResult
@todo provide support for objects and arrays
Common helper method to validate against enum keyword