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){
|
|
|
|
$content .= "### $methName [POST /$module/$methName]\n\n";
|
|
|
|
$content .= $method['description']."\n";
|
|
|
|
if( count($method['permissions']) > 0)
|
|
|
|
$content .= '> Permissions `'.implode('`', $method['permissions'])."`\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
?>
|