2010-10-20 12:21:59 +00:00
|
|
|
<?php
|
|
|
|
class DocumentationController extends Zend_Controller_Action
|
|
|
|
{
|
2010-10-25 12:57:14 +00:00
|
|
|
protected $classmap = array();
|
2010-10-20 12:21:59 +00:00
|
|
|
|
2010-12-07 15:46:10 +00:00
|
|
|
public function init(){}
|
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()
|
|
|
|
{
|
|
|
|
$ws = $this->_getParam('ws','WsEntreprise');
|
|
|
|
//Liste de webservice protégé
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
2010-10-25 12:57:14 +00:00
|
|
|
$wsConfig = new Zend_Config_Ini(APPLICATION_PATH .
|
|
|
|
'/configs/'.$ws.'.ini');
|
2011-01-19 09:02:18 +00:00
|
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
|
|
|
$this->classmap[$Type] = $Type;
|
|
|
|
}
|
2010-10-25 12:57:14 +00:00
|
|
|
|
2010-11-29 14:27:37 +00:00
|
|
|
//Définir l'url d'accès au WSDL
|
|
|
|
switch($ws){
|
|
|
|
case 'WsInterne':
|
2010-12-08 10:42:27 +00:00
|
|
|
$wsdl_url = $this->view->baseUrl() . '/sinterne?wsdl';
|
2010-11-29 14:27:37 +00:00
|
|
|
break;
|
|
|
|
case 'WsEntreprise':
|
|
|
|
if (APPLICATION_ENV == 'production'){
|
2010-12-03 13:26:11 +00:00
|
|
|
$wsdl_url = $this->view->baseUrl().'/service?wsdl';
|
2010-11-29 14:27:37 +00:00
|
|
|
} else {
|
2010-12-03 13:26:11 +00:00
|
|
|
$wsdl_url = $this->view->baseUrl().'/service?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';
|
2010-10-25 12:57:14 +00:00
|
|
|
$doc = new WebClassDoc($ws, $this->classmap);
|
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);
|
|
|
|
}
|
|
|
|
|
2010-12-07 15:46:10 +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->getCodeError();
|
|
|
|
$this->view->assign('erreurs', $erreurs);
|
|
|
|
}
|
2010-10-20 12:21:59 +00:00
|
|
|
}
|
|
|
|
|