diff --git a/build/api/core/Request.php b/build/api/core/Request.php index 1a6a1a8..2389d7e 100755 --- a/build/api/core/Request.php +++ b/build/api/core/Request.php @@ -119,9 +119,8 @@ $this->buildOptions(); - /* (8) Construction de l'objet (add http method to params) + /* (8) Construction de l'objet ---------------------------------------------------------*/ - $this->params['HTTP_METHOD'] = $this->http_method; $this->error->set(Err::Success); return true; // On retourne que tout s'est bien passe @@ -161,9 +160,14 @@ /* (1) Verification format general ---------------------------------------------------------*/ /* (1) If wrong format -> exit */ - if( !preg_match('@^\/[\w-]+(\/[\w-]+)*\/?$@', $uri, $matches) && $uri != '/' ) + if( !preg_match('@^\/[^\/]*(\/[^\/]+)*\/?$@', $uri) ) return $this->error->set(Err::WrongPathModule); + /* (2) Add ending '/' if not there */ + if( $uri[strlen($uri)-1] != '/' ) + $uri = "$uri/"; + + /* (2) Verification de l'existence du chemin (conf) ---------------------------------------------------------*/ @@ -174,9 +178,9 @@ foreach(Config::get()->index as $key=>$void){ $match_size = strlen($key); - /* (1.1) Look for the longer match */ - if( $match_size > $exists_size && substr($uri, 0, $match_size) == $key ){ - $exists_size = $match_size; + /* (1.1) Look for the longer ( match | '/' ) */ + if( $match_size > $exists_size && substr($uri, 0, $match_size+1) == "$key/" || $key == '/' ){ + $exists_size = $key == '/' ? 0 : $match_size; $path = $key; } @@ -191,12 +195,15 @@ ---------------------------------------------------------*/ /* (1) Extract URI string after @path */ $uri_end = substr($uri, $exists_size); + /* (2) Special case: add / if root uri arguments */ + if( strlen($uri_end) > 0 && $uri_end[0] != '/' ) + $uri_end = "/$uri_end"; - /* (2) If invalid format, return error */ + /* (3) If invalid format, return error */ if( !preg_match('@^((?:\/[^\/]+)*)\/?$@', $uri_end, $uri_match) ) return $this->error->set(Err::InvalidURI); - /* (3) Add each URI parameter to the parameter store */ + /* (4) Add each URI parameter to the parameter store */ $uri_args = array_slice( explode('/', $uri_match[1]), 1); foreach($uri_args as $index=>$value) @@ -320,10 +327,15 @@ if( isset($config['rename']) && is_string($config['rename']) && preg_match('@^\w+$@', $config['rename']) ) $rename = $config['rename']; - /* (2) On récupère si le paramètre est optionnel ou pas */ + /* (2) Gestion du paramètre DEFAULT */ + $default = null; + if( isset($config['default']) && is_string($config['default']) ) + $default = $config['default']; + + /* (3) On récupère si le paramètre est optionnel ou pas */ $optional = isset($config['optional']) && $config['optional'] === true; - /* (3) Si de type 'FILE' + fichier existe => on enregistre la ref. */ + /* (4) Si de type 'FILE' + fichier existe => on enregistre la ref. */ if( $config['type'] == 'FILE' && isset($_FILES[$name]) ) $this->params[$rename] = &$_FILES[$name]; @@ -337,11 +349,11 @@ /* (1) Si le paramètre est optionnel et manquant */ if( $optional && !isset($this->raw_params[$name]) ){ - // On le crée le param optionnel avec la valeur NULL - $this->params[$rename] = null; + // On le crée le param optionnel avec la valeur @default + $this->params[$rename] = $default; /* (2) Si le paramètre est renseigné (sauf FILE) */ - }elseif( $config['type'] != 'FILE'){ + }elseif( $config['type'] != 'FILE' ){ // Si la verification est fausse, on retourne faux if( !Checker::run($config['type'], $this->raw_params[$name]) ) @@ -439,7 +451,6 @@ return new Response($this->error); } - /* (4) On amorce la methode ---------------------------------------------------------*/ /* (1) On lance la fonction */ diff --git a/build/api/module/root.php b/build/api/module/root.php index f147bbc..4534cb4 100644 --- a/build/api/module/root.php +++ b/build/api/module/root.php @@ -13,7 +13,7 @@ public function get($args){ extract($args); - return [ 'bla' => uniqid() ]; + return [ 'args' => $args ]; } diff --git a/config/modules.json b/config/modules.json index 0a8ece1..de152cf 100755 --- a/config/modules.json +++ b/config/modules.json @@ -2,7 +2,9 @@ "GET": { "description": "Returns the API documentation", "permissions": [], - "parameters": {} + "parameters": { + "URL0": { "description": "Name of the project to release", "type": "alphanumeric", "rename": "var1", "optional": true, "default": "default_value" } + } }, "admin": {