2016-04-18 08:30:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
|
|
|
use \manager\ManagerError;
|
2016-04-30 09:33:01 +00:00
|
|
|
use \manager\ResourceDispatcher;
|
2016-04-18 08:30:40 +00:00
|
|
|
|
|
|
|
class module{
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
/* PERMET DE TESTER L'API
|
|
|
|
*
|
|
|
|
*/
|
2016-04-18 08:30:40 +00:00
|
|
|
public static function method(){
|
|
|
|
|
|
|
|
return array(
|
2016-04-18 09:30:38 +00:00
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'ReceivedArguments' => func_get_args()
|
2016-04-18 08:30:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
/* PERMET DE TESTER UNE L'ORDRE DES PARAMÈTRES
|
|
|
|
*
|
|
|
|
*/
|
2016-04-18 09:30:38 +00:00
|
|
|
public static function phpunitParams($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'p1' => $p1,
|
|
|
|
'p2' => $p2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
/* RENVOIE UNE DESCRIPTION EN MARKDOWN DES MODULES DE L'API
|
|
|
|
*
|
|
|
|
* @return markdown<String> Description des modules
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function markdown(){
|
|
|
|
/* [1] Récupération de la configuration
|
|
|
|
=========================================================*/
|
|
|
|
// On récupère le fichier et on le parse
|
|
|
|
$modules = json_decode( ResourceDispatcher::getResource('f/json/modules/conf'), true );
|
|
|
|
|
|
|
|
// Gestion de l'erreur de parsage
|
|
|
|
if( $modules == null )
|
|
|
|
return array( 'ModuleError' => ManagerError::ParsingFailed );
|
|
|
|
|
|
|
|
/* [2] Mise en forme de la liste des modules
|
|
|
|
=========================================================*/
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown = "## Module List\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
foreach($modules as $moduleName=>$moduleData)
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown .= "- $moduleName\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
/* [3] Mise en forme des méthodes des modules
|
|
|
|
=========================================================*/
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown .= "----\n## Method List & Description\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
$count = 1;
|
|
|
|
foreach($modules as $moduleName=>$moduleData){
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown .= "### $count - '$moduleName' methods\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
foreach($moduleData as $methodName=>$methodData)
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown .= "`$methodName` - ".$methodData['description']."\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-06-03 08:58:01 +00:00
|
|
|
$markdown .= "----\n";
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
2016-06-03 08:58:01 +00:00
|
|
|
'headers' => array(
|
|
|
|
'Content-Type' => 'text/markdown; charset=utf-8',
|
|
|
|
'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' => 'attachment; filename=NxTIC.apib',
|
|
|
|
'Pragma' => 'no-cache',
|
|
|
|
'Expires' => '0'
|
|
|
|
),
|
|
|
|
'body' => $markdown
|
2016-04-30 09:33:01 +00:00
|
|
|
);
|
|
|
|
}
|
2016-04-18 09:30:38 +00:00
|
|
|
|
2016-04-18 08:30:40 +00:00
|
|
|
|
2016-06-03 08:58:01 +00:00
|
|
|
/* RENVOIE UNE DOC API_BLUEPRINT DE L'API
|
|
|
|
*
|
|
|
|
* @return apiBlueprint<String> Description des modules au format API Blueprint
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function apiBlueprint(){
|
|
|
|
/* [1] Récupération de la configuration
|
|
|
|
=========================================================*/
|
|
|
|
// On récupère le fichier et on le parse
|
|
|
|
$modules = json_decode( ResourceDispatcher::getResource('f/json/modules/conf'), true );
|
2016-04-18 08:30:40 +00:00
|
|
|
|
2016-06-03 08:58:01 +00:00
|
|
|
// Gestion de l'erreur de parsage
|
|
|
|
if( $modules == null )
|
|
|
|
return array( 'ModuleError' => ManagerError::ParsingFailed );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Pour chaque module
|
|
|
|
=========================================================*/
|
|
|
|
$content = '';
|
|
|
|
foreach($modules as $module=>$methods){
|
|
|
|
|
|
|
|
$content .= "## $module [/$module] \n\n";
|
|
|
|
|
|
|
|
/* [3] Pour chaque méthode
|
|
|
|
=========================================================*/
|
|
|
|
foreach($methods as $methName=>$method){
|
2016-06-03 13:12:01 +00:00
|
|
|
|
|
|
|
/* (1) Description */
|
2016-06-03 08:58:01 +00:00
|
|
|
$content .= "### $methName [POST /$module/$methName]\n\n";
|
|
|
|
$content .= $method['description']."\n";
|
|
|
|
if( count($method['permissions']) > 0)
|
2016-06-03 13:12:01 +00:00
|
|
|
$content .= '> Permissions `'.implode('``', $method['permissions'])."`\n\n";
|
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
// Liste des paramètres
|
|
|
|
if( isset($method['parameters']) && count($method['parameters']) > 0 ){
|
|
|
|
// On explicite tous les paramètres
|
|
|
|
$content .= "+ Parameters\n\n";
|
|
|
|
foreach($method['parameters'] as $argName=>$argument){
|
|
|
|
$optional = isset($argument['optional']) && $argument['optional'] === true;
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " + $argName (${argument['type']}, ".( $optional ? 'optional' : 'required' ).") - ${argument['description']}\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
}
|
|
|
|
$content .= "\n";
|
|
|
|
}
|
|
|
|
|
2016-06-03 13:12:01 +00:00
|
|
|
|
|
|
|
/* (2) Requête */
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= "+ Request (multipart/form-data; boundary=xxxBOUNDARYxxx)\n\n";
|
2016-06-03 13:12:01 +00:00
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
// Header
|
|
|
|
$content .= " + Headers\n\n";
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " Authorization: Digest {yourAccessToken}\n";
|
|
|
|
$content .= " Cache-Control: no-cache\n";
|
2016-06-03 13:12:01 +00:00
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
if( isset($method['parameters']) && count($method['parameters']) > 0 ){
|
2016-06-03 13:12:01 +00:00
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
// Body
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " + Body\n\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
foreach($method['parameters'] as $argName=>$argument){
|
2016-06-04 09:06:36 +00:00
|
|
|
|
|
|
|
$content .= " --xxxBOUNDARYxxx\n";
|
|
|
|
$content .= " Content-Disposition: form-data; name=\"$argName\"\n";
|
|
|
|
$content .= " Content-Type: application/json\n\n";
|
2016-06-04 09:17:03 +00:00
|
|
|
$content .= " {".$argName."}\n";
|
2016-06-03 13:12:01 +00:00
|
|
|
}
|
2016-06-04 09:06:36 +00:00
|
|
|
|
2016-06-04 09:17:03 +00:00
|
|
|
$content .= " --xxxBOUNDARYxxx--\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
|
|
|
|
// Schema
|
|
|
|
$content .= " + Schema\n\n";
|
|
|
|
$content .= " {\n";
|
|
|
|
foreach($method['parameters'] as $argName=>$argData)
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " \"$argName\": @$argName\n";
|
|
|
|
$content .= " }\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
}
|
2016-06-03 08:58:01 +00:00
|
|
|
|
|
|
|
|
2016-06-03 13:12:01 +00:00
|
|
|
/* (3) Réponse */
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= "\n+ Response 200 (application/json)\n\n";
|
2016-06-03 13:28:17 +00:00
|
|
|
if( isset($method['output']) && count($method['output']) > 0 ){
|
2016-06-03 15:29:37 +00:00
|
|
|
|
|
|
|
// Body
|
|
|
|
$content .= " + Body\n\n";
|
2016-06-03 13:12:01 +00:00
|
|
|
$content .= " {\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
foreach($method['output'] as $outName=>$outData)
|
|
|
|
$content .= " \"$outName\": @$outName\n";
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " }\n";
|
2016-06-03 08:58:01 +00:00
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
// Schema
|
|
|
|
$content .= " + Schema\n\n";
|
|
|
|
$content .= " {\n";
|
|
|
|
foreach($method['output'] as $outName=>$outData)
|
|
|
|
$content .= " \"$outName\": @$outName\n";
|
2016-06-04 09:06:36 +00:00
|
|
|
$content .= " }\n";
|
2016-06-03 15:29:37 +00:00
|
|
|
|
|
|
|
// On explicite tous les paramètres
|
|
|
|
$content .= " + Attributes (object)\n\n";
|
|
|
|
foreach($method['output'] as $outName=>$outData)
|
|
|
|
$content .= " + $outName (${outData['type']}) - ${outData['description']}\n";
|
2016-06-03 13:28:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 15:29:37 +00:00
|
|
|
$content .= "\n\n";
|
|
|
|
|
2016-06-03 08:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'headers' => array(
|
|
|
|
'Content-Type' => 'application/octet-stream; charset=utf-8',
|
|
|
|
'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' => 'attachment; filename=NxTIC.apib',
|
|
|
|
'Pragma' => 'no-cache',
|
|
|
|
'Expires' => '0'
|
|
|
|
),
|
|
|
|
'body' => $content
|
|
|
|
);
|
|
|
|
}
|
2016-04-18 08:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-04-18 08:30:40 +00:00
|
|
|
?>
|