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

View File

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