202 lines
6.4 KiB
PHP
202 lines
6.4 KiB
PHP
<?php
|
|
class DocumentationController extends Zend_Controller_Action
|
|
{
|
|
|
|
/**
|
|
* Affichage de la documentation des webservices
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$ws = $request->getParam('ws','Entreprise');
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
//Si client possède un webservice particulier alors on redirige vers la doc clients
|
|
$clients = new Zend_Config_Ini('WsScore/Clients/Clients.ini');
|
|
foreach( $clients->toArray() as $section => $params ){
|
|
if ($params['actif']) {
|
|
$wsClients[$params['idClient']] = $section;
|
|
}
|
|
}
|
|
|
|
if (array_key_exists($auth->getIdentity()->idClient, $wsClients)){
|
|
|
|
$this->_forward('clients', 'documentation', null, array(
|
|
'nom' => $wsClients[$auth->getIdentity()->idClient]
|
|
));
|
|
|
|
} else {
|
|
|
|
// Liste des webservices
|
|
$services = new Zend_Config_Ini('WsScore/Services.ini');
|
|
foreach( $services->toArray() as $section => $params ){
|
|
if ($params['actif']) {
|
|
$wsServices[$section] = $params;
|
|
}
|
|
}
|
|
|
|
// On vérifie que l'utilisateur peut accèder à la documentation
|
|
$username = $auth->getIdentity()->username;
|
|
$idClient = $auth->getIdentity()->idClient;
|
|
if ( array_key_exists($ws, $wsServices) )
|
|
{
|
|
if ( isset($wsServices['idClient']) && $idClient!=$wsServices['idClient'] )
|
|
{
|
|
$this->renderScript('documentation/nodoc.phtml');
|
|
exit;
|
|
}
|
|
if ( isset($wsServices['user']) && !in_array($username, $wsServices['user']) )
|
|
{
|
|
$this->renderScript('documentation/nodoc.phtml');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Gestion des versions
|
|
$configServiceVersions = new Zend_Config_Ini('WsScore/'.ucfirst($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/'.ucfirst($ws).'/v'.$version.'/';
|
|
|
|
// Gestion des classmap
|
|
$wsConfig = new Zend_Config_Ini($pathClassService.ucfirst($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.= '/'.$ws.'/v'.$version.'?wsdl';
|
|
} else {
|
|
$wsdl_url.= '/'.$ws.'/v'.$version.'?wsdl-auto';
|
|
}
|
|
// Affichage de la documentation
|
|
require_once 'Web/WebClassDoc.php';
|
|
$doc = new WebClassDoc(ucfirst($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/'.ucfirst($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/'.ucfirst($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);
|
|
}
|
|
}
|
|
|