upd: api.core.Request (shortened config keys)

This commit is contained in:
xdrm-brackets 2017-12-12 22:27:22 +01:00
parent ba6d721586
commit b1796535a3
2 changed files with 67 additions and 67 deletions

View File

@ -255,7 +255,7 @@
$method = Config::get()->index[$this->id['path']][$this->id['method']];
// Si aucune permission n'est definie
if( !isset($method['permissions']) || !is_array($method['permissions']) || count($method['permissions']) < 1 )
if( !isset($method['per']) || !is_array($method['per']) || count($method['per']) < 1 )
return true;
/* (2) Vérification des permissions et de l'authentification
@ -273,7 +273,7 @@
}
// Check permission using user-implemented AuthSystem
$granted = self::$authsystem::permission( $method['permissions'] );
$granted = self::$authsystem::permission( $method['per'] );
/* (1) On retourne FAUX si aucun droit n'a ete trouve */
if( $granted->get() !== Err::Success ){
@ -306,13 +306,13 @@
$method = Config::get()->index[$this->id['path']][$this->id['method']];
/* (3) Si pas 'parameters' dans la config */
if( !isset($method['parameters']) || !is_array($method['parameters']) )
if( !isset($method['par']) || !is_array($method['par']) )
return $this->error->set(Err::ConfigError);
/* (2) Si le type est defini, pour chaque param, on teste
---------------------------------------------------------*/
foreach($method['parameters'] as $name=>$config){
foreach($method['par'] as $name=>$config){
/* (2.1) Vérification des données
---------------------------------------------------------*/
@ -324,8 +324,8 @@
if( !is_array($config) )
return $this->error->set(Err::ConfigError);
/* (3) So @config['type] manquant ou incorrect */
if( !isset($config['type']) || !is_string($config['type']) )
/* (3) So @config['typ] manquant ou incorrect */
if( !isset($config['typ']) || !is_string($config['typ']) )
return $this->error->set(Err::ConfigError);
@ -333,30 +333,30 @@
---------------------------------------------------------*/
/* (1) On récupère le paramètre RENAME */
$rename = $name;
if( isset($config['rename']) && is_string($config['rename']) && preg_match('@^\w+$@', $config['rename']) )
$rename = $config['rename'];
if( isset($config['ren']) && is_string($config['ren']) && preg_match('@^\w+$@', $config['ren']) )
$rename = $config['ren'];
/* (2) On récupère si le paramètre est optionnel ou pas */
$optional = isset($config['optional']) && $config['optional'] === true;
$optional = isset($config['opt']) && $config['opt'] === true;
/* (3) Gestion du paramètre DEFAULT */
$default = null;
/* (3.1) Check if default NOT (NULL || FILE) -> matches TYPE */
if( isset($config['default']) ){
if( isset($config['def']) ){
/* (3.1.1) Set default value from config */
$default = $config['default'];
$default = $config['def'];
/* (3.1.2) If FILE and not null -> Check type */
if( $config['type'] != 'FILE' || $default != null )
if( !Checker::run($config['type'], $default) )
return $this->error->set(Err::WrongDefaultParam, $rename, $config['type']);
if( $config['typ'] != 'FILE' || $default != null )
if( !Checker::run($config['typ'], $default) )
return $this->error->set(Err::WrongDefaultParam, $rename, $config['typ']);
}
/* (4) Si de type 'FILE' + fichier existe => on enregistre la ref. */
if( $config['type'] == 'FILE' && isset($_FILES[$name]) )
if( $config['typ'] == 'FILE' && isset($_FILES[$name]) )
$this->params[$rename] = &$_FILES[$name];
/* (4) Si param obligatoire et manquant -> erreur */
@ -373,11 +373,11 @@
$this->params[$rename] = $default;
/* (2) Si le paramètre est renseigné (sauf FILE) */
}elseif( $config['type'] != 'FILE' ){
}elseif( $config['typ'] != 'FILE' ){
// Si la verification est fausse, on retourne faux
if( !Checker::run($config['type'], $this->raw_params[$name]) )
return $this->error->set(Err::WrongParam, $rename, $config['type']);
if( !Checker::run($config['typ'], $this->raw_params[$name]) )
return $this->error->set(Err::WrongParam, $rename, $config['typ']);
// Sinon, on ajoute aux params qu'on enverra à l'appel
else
@ -408,14 +408,14 @@
$method = Config::get()->index[$this->id['path']][$this->id['method']];
/* (1) Si 'option' n'est pas défini (ou incorrect), on met les valeurs par défaut */
if( !isset($method['options']) || !is_array($method['options']) )
if( !isset($method['opt']) || !is_array($method['opt']) )
return true;
/* (2) Par défaut on définit les options par défaut */
$this->options = self::$default_options;
/* (3) On récupère les options données */
$options = $method['options'];
$options = $method['opt'];
/* (2) Gestion des différentes options

View File

@ -1,47 +1,47 @@
{
"GET": {
"description": "Returns the API documentation",
"permissions": [],
"parameters": {
"URL0": { "description": "Method name", "type": "varchar(1,30)", "rename": "method_name", "optional": true, "default": null, "default": null }
"des": "Returns the API documentation",
"per": [],
"par": {
"URL0": { "des": "Method name", "typ": "varchar(1,30)", "rename": "method_name", "opt": true, "def": null }
}
},
"admin": {
"POST": {
"description": "Creates a new administrator",
"permissions": [["admin"]],
"parameters": {
"username": { "description": "The new administrator username", "type": "varchar(3,20,alphanumeric)" },
"mail": { "description": "The new administrator email address", "type": "mail" },
"password": { "description": "The new administrator passowrd", "type": "text" }
"des": "Creates a new administrator",
"per": [["admin"]],
"par": {
"username": { "des": "The new administrator username", "typ": "varchar(3,20,alphanumeric)" },
"mail": { "des": "The new administrator email address", "typ": "mail" },
"password": { "des": "The new administrator passowrd", "typ": "text" }
}
},
"PUT": {
"description": "Updates an existing administrator's data",
"permissions": [["admin"]],
"parameters": {
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "rename": "id_admin" },
"mail": { "description": "The new administrator email address", "type": "mail", "optional": true },
"password": { "description": "The new administrator passowrd", "type": "text", "optional": true }
"des": "Updates an existing administrator's data",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "rename": "id_admin" },
"mail": { "des": "The new administrator email address", "typ": "mail", "opt": true },
"password": { "des": "The new administrator passowrd", "typ": "text", "opt": true }
}
},
"DELETE": {
"description": "Deletes an administrator",
"permissions": [["admin"]],
"parameters": {
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "optional": true, "rename": "id_admin" }
"des": "Deletes an administrator",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "rename": "id_admin" }
}
},
"GET": {
"description": "Gets an administrator | Gets all administrators if no id defined",
"permissions": [["admin"]],
"parameters": {
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "optional": true, "rename": "id_admin" }
"des": "Gets an administrator | Gets all administrators if no id defined",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "rename": "id_admin" }
}
}
@ -51,11 +51,11 @@
"GET": {
"description": "Pulls project from git branch.",
"permissions": [["admin"]],
"parameters": {
"URL0": { "description": "Name of the project to release", "type": "alphanumeric", "rename": "project", "optional": true, "default": "self" },
"URL1": { "description": "Step to run, if not given, all steps will be run", "type": "id", "rename": "step", "optional": true }
"des": "Pulls project from git branch.",
"per": [["admin"]],
"par": {
"URL0": { "des": "Name of the project to release", "typ": "alphanumeric", "rename": "project", "opt": true, "def": "self" },
"URL1": { "des": "Step to run, if not given, all steps will be run", "typ": "id", "rename": "step", "opt": true }
}
}
@ -67,40 +67,40 @@
"c": {
"PUT": {
"description": "PUT A/B/C.",
"permissions": [],
"parameters": {}
"des": "PUT A/B/C.",
"per": [],
"par": {}
},
"DELETE": {
"description": "DELETE A/B/C.",
"permissions": [],
"parameters": {}
"des": "DELETE A/B/C.",
"per": [],
"par": {}
}
},
"PUT": {
"description": "PUT A/B.",
"permissions": [],
"parameters": {}
"des": "PUT A/B.",
"per": [],
"par": {}
},
"DELETE": {
"description": "DELETE A/B.",
"permissions": [],
"parameters": {}
"des": "DELETE A/B.",
"per": [],
"par": {}
}
},
"GET": {
"description": "GET A.",
"permissions": [],
"parameters": {}
"des": "GET A.",
"per": [],
"par": {}
},
"POST": {
"description": "POST A.",
"permissions": [],
"parameters": {}
"des": "POST A.",
"per": [],
"par": {}
}
}
}