src/Koldy/Request.php
private static function get(string $resourceName, string $name, string $default = null, array $allowedValues = null)
    {
        switch ($resourceName) {
            case 'GET':
                $resource = $_GET;
                break;

            case 'POST':
                if (!isset($_POST)) {
                    return $default;
                }

                $resource = $_POST;
                break;

            case 'PUT':
                if ($_SERVER['REQUEST_METHOD'] !== 'PUT') {
                    return $default;
                }

                $resource = static::getInputVars();
                break;

            case 'DELETE':
                if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
                    return $default;
                }

                $resource = static::getInputVars();
                break;

            default:
                throw new RequestException("Invalid resource name={$resourceName}");
                break;
        }

        if (array_key_exists($name, $resource)) {

            if (is_array($resource[$name])) {
                return $resource[$name];
            }

            $value = trim($resource[$name]);

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

            if ($allowedValues !== null) {
                return (in_array($value, $allowedValues)) ? $value : $default;
            }

            return $value;
        } else {
            return $default;
        }
    }
private static function get(string $resourceName, string $name, string $default = null, array $allowedValues = null)
    {
        switch ($resourceName) {
            case 'GET':
                $resource = $_GET;
                break;

            case 'POST':
                if (!isset($_POST)) {
                    return $default;
                }

                $resource = $_POST;
                break;

            case 'PUT':
                if ($_SERVER['REQUEST_METHOD'] !== 'PUT') {
                    return $default;
                }

                $resource = static::getInputVars();
                break;

            case 'DELETE':
                if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
                    return $default;
                }

                $resource = static::getInputVars();
                break;

            default:
                throw new RequestException("Invalid resource name={$resourceName}");
                break;
        }

        if (array_key_exists($name, $resource)) {

            if (is_array($resource[$name])) {
                return $resource[$name];
            }

            $value = trim($resource[$name]);

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

            if ($allowedValues !== null) {
                return (in_array($value, $allowedValues)) ? $value : $default;
            }

            return $value;
        } else {
            return $default;
        }
    }
private static function get ( string $ resourceName , string $ name , string $ default = null , array $ allowedValues = null ) { switch ( $ resourceName ) { case 'GET' : $ resource = $ _GET ; break ; case 'POST' : if ( ! isset ( $ _POST ) ) { return $ default ; } $ resource = $ _POST ; break ; case 'PUT' : if ( $ _SERVER [ 'REQUEST_METHOD' ] !== 'PUT' ) { return $ default ; } $ resource = static :: getInputVars ( ) ; break ; case 'DELETE' : if ( $ _SERVER [ 'REQUEST_METHOD' ] !== 'DELETE' ) { return $ default ; } $ resource = static :: getInputVars ( ) ; break ; default : throw new RequestException ( "Invalid resource name={$resourceName}" ) ; break ; } if ( array_key_exists ( $ name , $ resource ) ) { if ( is_array ( $ resource [ $ name ] ) ) { return $ resource [ $ name ] ; } $ value = trim ( $ resource [ $ name ] ) ; if ( $ value == '' ) { return $ default ; } if ( $ allowedValues !== null ) { return ( in_array ( $ value , $ allowedValues ) ) ? $ value : $ default ; } return $ value ; } else { return $ default ; } }
Fetch the value from the resource

@param string $resourceName
@param string $name parameter name
@param string $default [optional] default value if parameter doesn't exists
@param array $allowedValues [optional] allowed values; if resource value doesn't contain one of values in this array, default is returned

@return string
@throws Exception
Fetch the value from the resource