webservice/application/controllers/DocumentationController.php

211 lines
6.5 KiB
PHP
Raw Normal View History

2010-10-20 12:21:59 +00:00
<?php
class DocumentationController extends Zend_Controller_Action
{
2010-10-20 12:21:59 +00:00
/**
* Affichage de la documentation des webservices
*/
public function indexAction()
{
2011-02-03 14:04:40 +00:00
$request = $this->getRequest();
2012-07-17 08:54:02 +00:00
$ws = $request->getParam('ws','Entreprise');
$auth = Zend_Auth::getInstance();
//Si client possède un webservice particulier alors on redirige vers la doc clients
2012-07-17 10:07:18 +00:00
$clients = include APPLICATION_PATH . '/../library/WsScore/Clients/ClientsConfig.php';
foreach( $clients as $section => $params ){
if ($params['actif']) {
$wsClients[$params['idClient']] = $section;
}
2011-02-03 14:04:40 +00:00
}
if (array_key_exists($auth->getIdentity()->idClient, $wsClients)){
$this->_forward('clients', 'documentation', null, array(
'nom' => $wsClients[$auth->getIdentity()->idClient]
2012-07-17 08:54:02 +00:00
));
2012-07-17 08:54:02 +00:00
} else {
// Liste des webservices
2012-07-17 10:07:18 +00:00
$services = include APPLICATION_PATH . '/../library/WsScore/ServicesConfig.php';
2012-07-17 08:54:02 +00:00
foreach( $services 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) )
2012-07-17 08:54:02 +00:00
{
if ( isset($wsServices['idClient']) && $idClient!=$wsServices['idClient'] )
{
$this->renderScript('documentation/nodoc.phtml');
2012-07-17 08:54:02 +00:00
exit;
}
if ( isset($wsServices['user']) && !in_array($username, $wsServices['user']) )
{
$this->renderScript('documentation/nodoc.phtml');
exit;
}
}
// Gestion des versions
$serviceVersions = array();
$configServiceVersions = $wsServices[$ws]['versions'];
foreach( $configServiceVersions 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.'/';
2012-03-09 15:10:17 +00:00
//Génération du tableau de mapping
$classmap = array();
$wsConfig = new Zend_Config_Ini($pathClassService.ucfirst($ws).'.ini');
if ( $wsConfig->count()>0 ) {
2012-03-09 14:52:59 +00:00
foreach($wsConfig->Type->toArray() as $Type){
$classmap[$Type] = $Type;
}
2012-07-17 08:54:02 +00:00
}
//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';
2011-10-12 10:04:04 +00:00
$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);
2010-11-29 14:27:37 +00:00
}
2010-10-20 12:21:59 +00:00
}
public function clientsAction()
{
$request = $this->getRequest();
$client = $request->getParam('nom');
$ws = 'Entreprise';
// Gestion des versions
$clients = include APPLICATION_PATH . '/../library/WsScore/Clients/ClientsConfig.php';
$configServiceVersions = $clients[$client][$ws]['versions'];
foreach( $configServiceVersions 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
2011-10-12 10:04:55 +00:00
$pathClassService = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/';
2012-03-09 15:10:17 +00:00
//Génération du tableau de mapping
$classmap = array();
$wsConfig = new Zend_Config_Ini($pathClassService.$ws.'.ini');
if ( $wsConfig->count()>0 ) {
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);
}
2010-10-20 12:21:59 +00:00
/**
* Liste les exemples de code disponible pour chaque méthode
*/
public function exemplesAction()
{
}
2010-10-20 12:21:59 +00:00
/**
* 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','');
2010-11-29 14:27:37 +00:00
$fichier = APPLICATION_PATH .
2010-10-29 14:04:17 +00:00
'/../public/code/' . $element . '-' . $langage . '.txt';
2010-10-20 12:21:59 +00:00
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.');
}
}
2011-02-02 15:30:33 +00:00
/**
* Affichage de la liste des erreurs avec leur code
*/
public function erreurAction()
{
require_once 'WsScore/WsScore.php';
$ws = new WsScore();
$erreurs = $ws->listError;
2011-02-02 15:30:33 +00:00
$this->view->assign('erreurs', $erreurs);
}
2010-10-20 12:21:59 +00:00
}