webservice/application/controllers/DocumentationController.php

101 lines
2.8 KiB
PHP
Raw Normal View History

2010-10-20 12:21:59 +00:00
<?php
class DocumentationController extends Zend_Controller_Action
{
protected $classmap = array();
2010-10-20 12:21:59 +00:00
public function init()
{
/* Initialize action controller here */
}
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();
$username = $auth->getIdentity();
if ( !in_array($username, $protectedWs[$ws]) )
{
$this->renderScript('documentation/nodoc.phtml');
exit;
}
}
$wsConfig = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/'.$ws.'.ini');
foreach ($wsConfig->Type as $type){
$this->classmap[$type] = $type;
}
2010-11-29 14:27:37 +00:00
//Définir l'url d'accès au WSDL
switch($ws){
case 'WsInterne':
$wsdl_url = $this->view->baseUrl . '/sinterne?wsdl';
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';
$doc = new WebClassDoc($ws, $this->classmap);
2010-10-20 12:21:59 +00:00
$tabServiceMethods = $doc->getServiceMethods();
$tabServiceTypes = $doc->getServiceTypes();
2010-11-29 14:27:37 +00:00
$this->view->assign('wsdl', $wsdl_url);
2010-10-20 12:21:59 +00:00
$this->view->assign('serviceMethods', $tabServiceMethods);
$this->view->assign('serviceTypes', $tabServiceTypes);
}
/**
* 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.');
}
}
}