src/Validate.php
public static function enum($input, $values, $field_name = 'enum')
    {

        //Check if array was given for $values value
        if (!is_array($values)) {
            throw new \Exception('Array is expected as values');
        }

        //Define trivial model
        $model = [
            $field_name => [
                'type' => Validate::TYPE_ENUM, 'values' => $values, Validate::REQUIRED
            ]
        ];

        $parameters = [$field_name => $input];
        Validate::model($parameters, $model);

        return $parameters[$field_name];
    }
public static function enum($input, $values, $field_name = 'enum')
    {

        //Check if array was given for $values value
        if (!is_array($values)) {
            throw new \Exception('Array is expected as values');
        }

        //Define trivial model
        $model = [
            $field_name => [
                'type' => Validate::TYPE_ENUM, 'values' => $values, Validate::REQUIRED
            ]
        ];

        $parameters = [$field_name => $input];
        Validate::model($parameters, $model);

        return $parameters[$field_name];
    }
public static function enum ( $ input , $ values , $ field_name = 'enum' ) { //Check if array was given for $values value if ( ! is_array ( $ values ) ) { throw new \ Exception ( 'Array is expected as values' ) ; } //Define trivial model $ model = [ $ field_name => [ 'type' => Validate :: TYPE_ENUM , 'values' => $ values , Validate :: REQUIRED ] ] ; $ parameters = [ $ field_name => $ input ] ; Validate :: model ( $ parameters , $ model ) ; return $ parameters [ $ field_name ] ; }
Check if input value is in allowed values
@param string|integer $input Input array to check
@param array $values Array of strings or number, defines the allowed input values
@param string $field_name [optional] Field's name, used in IncorrectParametersException.
Optional default is enum
@throws IncorrectParameters If valu type is not correct.
@return returns the value of the input value
Check if input value is in allowed values