webservice/application/controllers/DocumentationController.php

137 lines
3.9 KiB
PHP
Raw Normal View History

2010-10-20 12:21:59 +00:00
<?php
class DocumentationController extends Zend_Controller_Action
{
protected $classmap = array();
protected $serviceVersions = array();
public function init()
{
$configServiceVersions = new Zend_Config_Ini('WsScore/Versions.ini', null);
foreach( $configServiceVersions->toArray() as $section => $params ){
$this->serviceVersions[$section] = $params;
}
}
2010-10-20 12:21:59 +00:00
public function preDispatch()
{
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()){
$this->_redirect('/user/login');
}
}
/**
* Affichage de la documentation des webservices
*/
public function indexAction()
{
2011-02-03 14:04:40 +00:00
$request = $this->getRequest();
$ws = $request->getParam('ws','WsEntreprise');
$version = $request->getParam('version', '0.2');
//Liste de webservice protégé
2010-10-20 12:21:59 +00:00
$protectedWs = array(
'WsInterne' => array('mricois', 'ylenaour', 'sbeaugrand')
);
//On vérifie que l'utilisateur peut accèder à la documentation
if ( array_key_exists($ws, $protectedWs) )
{
$auth = Zend_Auth::getInstance();
2010-12-14 10:23:40 +00:00
$username = $auth->getIdentity()->username;
2010-10-20 12:21:59 +00:00
if ( !in_array($username, $protectedWs[$ws]) )
{
$this->renderScript('documentation/nodoc.phtml');
exit;
}
}
2011-02-03 14:04:40 +00:00
//Charger les classes et les types pour le service suivant la version
$pathClassService = 'WsScore/';
if ($ws == 'WsEntreprise'){
$pathClassService.= 'v'.$version.'/';
}
$wsConfig = new Zend_Config_Ini($pathClassService.$ws.'.ini');
foreach($wsConfig->Type->toArray() as $Type){
$this->classmap[$Type] = $Type;
}
2010-11-29 14:27:37 +00:00
//Définir l'url d'accès au WSDL
$wsdl_url = $this->view->baseUrl();
2010-11-29 14:27:37 +00:00
switch($ws){
case 'WsInterne':
$wsdl_url.= '/sinterne?wsdl';
2010-11-29 14:27:37 +00:00
break;
case 'WsEntreprise':
if (APPLICATION_ENV == 'production'){
$wsdl_url.= '/entreprise/v'.$version.'?wsdl';
2010-11-29 14:27:37 +00:00
} else {
$wsdl_url.= '/entreprise/v'.$version.'?wsdl-auto';
2010-11-29 14:27:37 +00:00
}
break;
}
2010-10-20 12:21:59 +00:00
//Affichage de la documentation
require_once 'Web/WebClassDoc.php';
2011-02-03 14:04:40 +00:00
$doc = new WebClassDoc($ws, $this->classmap, $pathClassService);
2010-10-20 12:21:59 +00:00
$tabServiceMethods = $doc->getServiceMethods();
2011-01-25 09:59:02 +00:00
// Tri des méthodes par ordre alphabétique
$tabServiceMethodsK = array();
foreach($tabServiceMethods as $method) {
$tabServiceMethodsK[$method['name']] = $method;
}
ksort($tabServiceMethodsK);
2010-10-20 12:21:59 +00:00
$tabServiceTypes = $doc->getServiceTypes();
2010-11-29 14:27:37 +00:00
$this->view->assign('wsdl', $wsdl_url);
2011-01-25 09:59:02 +00:00
$this->view->assign('serviceMethods', $tabServiceMethodsK);
2010-10-20 12:21:59 +00:00
$this->view->assign('serviceTypes', $tabServiceTypes);
}
/**
* 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
}