201 lines
5.9 KiB
PHP
201 lines
5.9 KiB
PHP
<?php
|
|
class DocumentationController extends Zend_Controller_Action
|
|
{
|
|
|
|
public function init() {}
|
|
|
|
public function preDispatch()
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if (!$auth->hasIdentity()){
|
|
$this->_redirect('/user/login');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Affichage de la documentation des webservices
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$ws = $request->getParam('ws','Entreprise');
|
|
|
|
// Liste de webservice protégé
|
|
$protectedWs = array(
|
|
'Interne' => array('mricois', 'ylenaour', 'dlasserre')
|
|
);
|
|
|
|
// On vérifie que l'utilisateur peut accèder à la documentation
|
|
if ( array_key_exists($ws, $protectedWs) )
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
$username = $auth->getIdentity()->username;
|
|
if ( !in_array($username, $protectedWs[$ws]) )
|
|
{
|
|
$this->renderScript('documentation/nodoc.phtml');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Gestion des versions
|
|
$configServiceVersions = new Zend_Config_Ini('WsScore/'.$ws.'/Versions.ini');
|
|
foreach( $configServiceVersions->toArray() as $section => $params ){
|
|
$serviceVersions[$section] = $params;
|
|
if ($params['defaut']) {
|
|
$defautVersion = $section;
|
|
}
|
|
}
|
|
$version = $request->getParam('version', $defautVersion);
|
|
|
|
// Charger les classes et les types pour le service suivant la version
|
|
$pathClassService = 'WsScore/';
|
|
switch($ws){
|
|
case 'Entreprise':
|
|
$pathClassService.= 'Entreprise/v'.$version.'/';
|
|
break;
|
|
case 'Interne':
|
|
$pathClassService.= 'Interne/v'.$version.'/';
|
|
break;
|
|
}
|
|
|
|
// Gestion des classmap
|
|
$wsConfig = new Zend_Config_Ini($pathClassService.$ws.'.ini');
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
|
$classmap[$Type] = $Type;
|
|
}
|
|
|
|
//Définir l'url d'accès au WSDL
|
|
$wsdl_url = $this->view->baseUrl();
|
|
switch($ws){
|
|
case 'Interne':
|
|
$wsdl_url.= '/sinterne?wsdl';
|
|
break;
|
|
case 'Entreprise':
|
|
if (APPLICATION_ENV == 'production'){
|
|
$wsdl_url.= '/entreprise/v'.$version.'?wsdl';
|
|
} else {
|
|
$wsdl_url.= '/entreprise/v'.$version.'?wsdl-auto';
|
|
}
|
|
break;
|
|
}
|
|
// Affichage de la documentation
|
|
require_once 'Web/WebClassDoc.php';
|
|
$doc = new WebClassDoc($ws, $classmap, $pathClassService);
|
|
$tabServiceMethods = $doc->getServiceMethods();
|
|
// Tri des méthodes par ordre alphabétique
|
|
$tabServiceMethodsK = array();
|
|
foreach($tabServiceMethods as $method) {
|
|
$tabServiceMethodsK[$method['name']] = $method;
|
|
}
|
|
ksort($tabServiceMethodsK);
|
|
$tabServiceTypes = $doc->getServiceTypes();
|
|
$this->view->assign('wsdl', $wsdl_url);
|
|
$this->view->assign('serviceMethods', $tabServiceMethodsK);
|
|
$this->view->assign('serviceTypes', $tabServiceTypes);
|
|
}
|
|
|
|
public function clientsAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$client = $request->getParam('nom');
|
|
$ws = 'Entreprise';
|
|
|
|
// Gestion des versions
|
|
$configServiceVersions = new Zend_Config_Ini('WsScore/Clients/'.$client.'/Versions.ini');
|
|
foreach( $configServiceVersions->toArray() as $section => $params ){
|
|
$serviceVersions[$section] = $params;
|
|
if ($params['defaut']) {
|
|
$defautVersion = $section;
|
|
}
|
|
}
|
|
$version = $request->getParam('version', $defautVersion);
|
|
|
|
// Charger les classes et les types pour le service suivant la version
|
|
$pathClassService = 'WsScore/Clients/'.$client.'/v'.$version.'/';
|
|
|
|
|
|
// Gestion des classmap
|
|
$wsConfig = new Zend_Config_Ini($pathClassService.$ws.'.ini');
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
|
$classmap[$Type] = $Type;
|
|
}
|
|
|
|
//Définir l'url d'accès au WSDL
|
|
$wsdl_url = $this->view->baseUrl();
|
|
|
|
if (APPLICATION_ENV == 'production'){
|
|
$wsdl_url.= '/clients/'.$client.'/v'.$version.'?wsdl';
|
|
} else {
|
|
$wsdl_url.= '/clients/'.$client.'/v'.$version.'?wsdl-auto';
|
|
}
|
|
|
|
// Affichage de la documentation
|
|
require_once 'Web/WebClassDoc.php';
|
|
$doc = new WebClassDoc($ws, $classmap, $pathClassService);
|
|
$tabServiceMethods = $doc->getServiceMethods();
|
|
// Tri des méthodes par ordre alphabétique
|
|
$tabServiceMethodsK = array();
|
|
foreach($tabServiceMethods as $method) {
|
|
$tabServiceMethodsK[$method['name']] = $method;
|
|
}
|
|
ksort($tabServiceMethodsK);
|
|
$tabServiceTypes = $doc->getServiceTypes();
|
|
$this->view->assign('wsdl', $wsdl_url);
|
|
$this->view->assign('serviceMethods', $tabServiceMethodsK);
|
|
$this->view->assign('serviceTypes', $tabServiceTypes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Liste les exemples de code disponible pour chaque méthode
|
|
*/
|
|
public function exemplesAction()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Affichage exemple de code avec coloration syntaxique
|
|
* Le code doit être placé dans public/code et doit être nommé
|
|
* [nom de la méthode]-langage.txt
|
|
*/
|
|
public function codeAction()
|
|
{
|
|
$langage = strtolower($this->_getParam('langage',''));
|
|
$element = $this->_getParam('element','');
|
|
|
|
$fichier = APPLICATION_PATH .
|
|
'/../public/code/' . $element . '-' . $langage . '.txt';
|
|
if (file_exists($fichier)){
|
|
$sourceCode = file_get_contents($fichier);
|
|
|
|
require_once 'geshi/geshi.php';
|
|
$geshi = new GeSHi($sourceCode, $langage);
|
|
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
|
$sourceHighlight = $geshi->parse_code();
|
|
|
|
$this->view->assign('langage', strtoupper($langage));
|
|
$this->view->assign('code', $sourceHighlight);
|
|
} else {
|
|
$this->view->assign('langage',
|
|
'Element non traités, Vous pouvez aussi nous fournir des exemples.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Affichage de la liste des erreurs avec leur code
|
|
*/
|
|
public function erreurAction()
|
|
{
|
|
require_once 'WsScore/WsScore.php';
|
|
$ws = new WsScore();
|
|
$erreurs = $ws->listError;
|
|
$this->view->assign('erreurs', $erreurs);
|
|
}
|
|
}
|
|
|