src/Koldy/Request.php
public static function requireParams(string ...$requiredParameters): array
    {
        if (KOLDY_CLI) {
            throw new ApplicationException('Unable to require parameters in CLI mode. Check \Koldy\Cli for that');
        }

        switch ($_SERVER['REQUEST_METHOD']) {
            default:
                $parameters = static::getInputVars();
                break;
            case 'GET':
                $parameters = $_GET;
                break;
            case 'POST':
                $parameters = $_POST;
                break;
        }

        $extractedParams = [];
        $missing = [];

        foreach ($requiredParameters as $param) {
            if (array_key_exists($param, $parameters)) {
                $extractedParams[$param] = $parameters[$param];
            } else {
                $missing[] = $param;
            }
        }

        if (count($missing) > 0) {
            $missingParameters = implode(', ', $missing);
            $passedParams = implode(', ', $requiredParameters);
            throw new BadRequestException("Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got " . (count($requiredParameters) > 0 ? $passedParams : '[nothing]'));
        }

        return $extractedParams;
    }
public static function requireParams(string ...$requiredParameters): array
    {
        if (KOLDY_CLI) {
            throw new ApplicationException('Unable to require parameters in CLI mode. Check \Koldy\Cli for that');
        }

        switch ($_SERVER['REQUEST_METHOD']) {
            default:
                $parameters = static::getInputVars();
                break;
            case 'GET':
                $parameters = $_GET;
                break;
            case 'POST':
                $parameters = $_POST;
                break;
        }

        $extractedParams = [];
        $missing = [];

        foreach ($requiredParameters as $param) {
            if (array_key_exists($param, $parameters)) {
                $extractedParams[$param] = $parameters[$param];
            } else {
                $missing[] = $param;
            }
        }

        if (count($missing) > 0) {
            $missingParameters = implode(', ', $missing);
            $passedParams = implode(', ', $requiredParameters);
            throw new BadRequestException("Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got " . (count($requiredParameters) > 0 ? $passedParams : '[nothing]'));
        }

        return $extractedParams;
    }
public static function requireParams ( string ... $ requiredParameters ) : array { if ( KOLDY_CLI ) { throw new ApplicationException ( 'Unable to require parameters in CLI mode. Check \Koldy\Cli for that' ) ; } switch ( $ _SERVER [ 'REQUEST_METHOD' ] ) { default : $ parameters = static :: getInputVars ( ) ; break ; case 'GET' : $ parameters = $ _GET ; break ; case 'POST' : $ parameters = $ _POST ; break ; } $ extractedParams = [ ] ; $ missing = [ ] ; foreach ( $ requiredParameters as $ param ) { if ( array_key_exists ( $ param , $ parameters ) ) { $ extractedParams [ $ param ] = $ parameters [ $ param ] ; } else { $ missing [ ] = $ param ; } } if ( count ( $ missing ) > 0 ) { $ missingParameters = implode ( ', ' , $ missing ) ; $ passedParams = implode ( ', ' , $ requiredParameters ) ; throw new BadRequestException ( "Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got " . ( count ( $ requiredParameters ) > 0 ? $ passedParams : '[nothing]' ) ) ; } return $ extractedParams ; }
Get the required parameters. Return bad request if any of them is missing.

@param string[] ...$requiredParameters

@return array
@throws BadRequestException
@throws Exception
@link http://koldy.net/docs/input#require

@example
$params = Input::requireParams('id', 'email');
echo $params->email;
Get the required parameters . Return bad request if any of them is missing .