application/Libraries/Core.php
/**
     * Check if URL parameters are valid
     * 
     * Use Reflection API to verify if param count is correct and types match
     * Check Whether the given number of parameters is <= total no. of params
     * AND >= required (minimum) arguments
     * 
     * Parameters are looped index based;
     * Methods must not contain optional params on left side of function due to
     * constant parameter order for function arguments in PHP
     * 
     * Check Whether expected parameter type and given parameter type match
     * (when expected type is hinted in method).
     * 
     * Cast Parameter values to strings when expecting. For eg:
     * /profile/true (pretty dull name) will cast true to bool however profile method expects type=string  
     * 
     * @param object $controller Controller Object
     * @param string $method Method to check params of 
     * @param array $params Parameters specified
     * 
     * @return bool Return true when parameters for called method are valid
     */
Check if URL parameters are valid

Use Reflection API to verify if param count is correct and types match
Check Whether the given number of parameters is <= total no. of params
AND >= required (minimum) arguments

Parameters are looped index based;
Methods must not contain optional params on left side of function due to
constant parameter order for function arguments in PHP

Check Whether expected parameter type and given parameter type match
(when expected type is hinted in method).

Cast Parameter values to strings when expecting. For eg:
/profile/true (pretty dull name) will cast true to bool however profile method expects type=string

@param object $controller Controller Object
@param string $method Method to check params of
@param array $params Parameters specified

@return bool Return true when parameters for called method are valid
Check if URL parameters are valid Use Reflection API to verify if param count is correct and types match Check Whether the given number of parameters is < = total no . of params AND > = required ( minimum ) arguments Parameters are looped index based ; Methods must not contain optional params on left side of function due to constant parameter order for function arguments in PHP Check Whether expected parameter type and given parameter type match ( when expected type is hinted in method ) . Cast Parameter values to strings when expecting . For eg : / profile / true ( pretty dull name ) will cast true to bool however profile method expects type = string @param object $controller Controller Object @param string $method Method to check params of @param array $params Parameters specified @return bool Return true when parameters for called method are valid
private function checkParams(object $controller, string $method, array $params): bool {
        $reflection = new ReflectionMethod($controller, $method);
        $requiredArgs = $this->requiredArgCount($controller, $method); 
        $totalArgs = $reflection->getNumberOfParameters(); 
        $givenArgs = count($params);
        if($givenArgs >= $requiredArgs && $givenArgs <= $totalArgs) {
            for($i = 0; $i < $givenArgs; $i++) { 
                $param = new ReflectionParameter(array($this->currentController, $this->currentMethod), $i);
                $paramType = $param->getType();
                if($paramType == 'string') $this->params[$i] = (string) $this->params[$i]; 
                $givenType = Utils::typeOf($this->params[$i]);
                if(!is_null($paramType) && $paramType != $givenType) { 
                    return false;
                }
            }
            return true;
        }
        return false;
    }
private function checkParams ( object $ controller , string $ method , array $ params ) : bool { $ reflection = new ReflectionMethod ( $ controller , $ method ) ; $ requiredArgs = $ this -> requiredArgCount ( $ controller , $ method ) ; $ totalArgs = $ reflection -> getNumberOfParameters ( ) ; $ givenArgs = count ( $ params ) ; if ( $ givenArgs >= $ requiredArgs && $ givenArgs <= $ totalArgs ) { for ( $ i = 0 ; $ i < $ givenArgs ; $ i ++ ) { $ param = new ReflectionParameter ( array ( $ this -> currentController , $ this -> currentMethod ) , $ i ) ; $ paramType = $ param -> getType ( ) ; if ( $ paramType == 'string' ) $ this -> params [ $ i ] = ( string ) $ this -> params [ $ i ] ; $ givenType = Utils :: typeOf ( $ this -> params [ $ i ] ) ; if ( ! is_null ( $ paramType ) && $ paramType != $ givenType ) { return false ; } } return true ; } return false ; }
Check if URL parameters are valid
Check if URL parameters are valid
// Only Required params not optional // Total no. of params in method // get params of index 1, 2, 3 ... $givenArgs // cast int/bool/float if expecting string // if type specified and dont match