2010-08-30 07:49:44 +00:00
|
|
|
<?php
|
|
|
|
ini_set("soap.wsdl_cache_enabled", "0");
|
|
|
|
|
2010-11-05 09:54:50 +00:00
|
|
|
require_once 'framework/fwk.php';
|
|
|
|
|
2010-08-30 07:49:44 +00:00
|
|
|
class ServiceController extends Zend_Controller_Action
|
|
|
|
{
|
2010-09-20 09:38:18 +00:00
|
|
|
protected $classmap = array();
|
2011-02-03 14:04:40 +00:00
|
|
|
|
2011-02-04 13:46:11 +00:00
|
|
|
public function init(){}
|
2010-08-30 07:49:44 +00:00
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-02-04 13:46:11 +00:00
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
|
|
|
require_once 'Zend/Exception.php';
|
2010-08-30 07:49:44 +00:00
|
|
|
require_once 'Zend/Soap/AutoDiscover.php';
|
|
|
|
require_once 'Zend/Soap/Server.php';
|
|
|
|
require_once 'WsScore/WrappedServiceProxy.php';
|
2011-02-04 13:46:11 +00:00
|
|
|
|
2011-02-03 14:04:40 +00:00
|
|
|
$request = $this->getRequest();
|
2011-02-04 13:46:11 +00:00
|
|
|
|
|
|
|
// Liste des versions
|
|
|
|
$configServiceVersions = new Zend_Config_Ini('WsScore/Entreprise/Versions.ini');
|
|
|
|
foreach( $configServiceVersions->toArray() as $section => $params ){
|
|
|
|
$serviceVersions[$section] = $params;
|
|
|
|
if ($params['actif']) {
|
|
|
|
$defautVersion = $section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$version = $request->getParam('version', 'v'.$defautVersion);
|
2011-02-03 14:43:00 +00:00
|
|
|
$version = substr($version, 1);
|
2011-02-04 13:46:11 +00:00
|
|
|
|
|
|
|
// Version inexistante
|
|
|
|
if ( !array_key_exists($version, $serviceVersions) ) {
|
2011-02-03 17:11:26 +00:00
|
|
|
echo "Version inexistante.";
|
2011-02-03 14:04:40 +00:00
|
|
|
exit;
|
|
|
|
}
|
2011-02-04 13:46:11 +00:00
|
|
|
// Version désactivé
|
|
|
|
if ( !$serviceVersions[$version]['actif'] ) {
|
2011-02-03 17:11:26 +00:00
|
|
|
echo "Version désactivée.";
|
2011-02-03 14:04:40 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2011-02-04 13:46:11 +00:00
|
|
|
// Charger les classes et les types pour le service suivant la version
|
2011-02-04 11:32:55 +00:00
|
|
|
$pathClassService = 'WsScore/Entreprise/v'.$version.'/';
|
|
|
|
$wsConfig = new Zend_Config_Ini($pathClassService.'Entreprise.ini');
|
2011-02-03 14:04:40 +00:00
|
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
|
|
|
$this->classmap[$Type] = $Type;
|
|
|
|
}
|
2011-02-04 11:32:55 +00:00
|
|
|
require_once $pathClassService.'Entreprise.php';
|
2011-02-04 13:46:11 +00:00
|
|
|
$fichierWsdl = 'Entreprise-'.$version.'.wsdl';
|
2010-08-30 07:49:44 +00:00
|
|
|
|
|
|
|
// Fourniture du wsdl
|
2011-02-03 14:04:40 +00:00
|
|
|
if (isset($_GET['wsdl'])) {
|
|
|
|
if (file_exists($fichierWsdl)) {
|
2010-08-30 07:49:44 +00:00
|
|
|
if (!headers_sent()) {
|
|
|
|
header('Content-Type: text/xml');
|
|
|
|
}
|
|
|
|
echo file_get_contents($fichierWsdl);
|
2011-02-03 14:04:40 +00:00
|
|
|
} else {
|
2011-02-03 17:11:26 +00:00
|
|
|
echo "Erreur WSDL inexistant ";
|
2010-08-30 07:49:44 +00:00
|
|
|
}
|
2010-10-18 07:25:31 +00:00
|
|
|
}
|
2010-08-30 07:49:44 +00:00
|
|
|
// Génération du wsdl
|
2011-02-03 14:04:40 +00:00
|
|
|
elseif ( isset($_GET['wsdl-generate']) || isset($_GET['wsdl-auto']) ) {
|
|
|
|
|
2010-08-30 07:49:44 +00:00
|
|
|
// Définition du webservice
|
|
|
|
$wsdl = new Zend_Soap_AutoDiscover();
|
2010-12-15 16:18:24 +00:00
|
|
|
$wsdl->setComplexTypeStrategy('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
|
2010-08-30 07:49:44 +00:00
|
|
|
$wsdl->setOperationBodyStyle( array('use' => 'literal') );
|
|
|
|
$wsdl->setBindingStyle( array('style' => 'document') );
|
2011-02-04 11:32:55 +00:00
|
|
|
$wsdl->setClass('Entreprise');
|
2010-08-30 07:49:44 +00:00
|
|
|
|
|
|
|
// Enregistrement du WSDL dans un fichier
|
2011-02-03 14:04:40 +00:00
|
|
|
if ( isset($_GET['wsdl-generate']) ) {
|
|
|
|
if (!file_exists($fichierWsdl)) {
|
2010-09-08 13:30:33 +00:00
|
|
|
$wsdl->dump($fichierWsdl);
|
|
|
|
echo "Le fichier $fichierWsdl a été généré";
|
2011-02-03 14:04:40 +00:00
|
|
|
} else {
|
2010-09-08 13:30:33 +00:00
|
|
|
echo "ERREUR : Le fichier $fichierWsdl est déjà présent !";
|
|
|
|
}
|
2010-10-18 07:25:31 +00:00
|
|
|
}
|
2010-08-30 07:49:44 +00:00
|
|
|
// Envoi sur la sortie standard le wsdl
|
2011-02-03 14:04:40 +00:00
|
|
|
elseif ( isset($_GET['wsdl-auto']) ){
|
2010-08-30 07:49:44 +00:00
|
|
|
$wsdl->handle();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fourniture du service
|
|
|
|
} else {
|
|
|
|
|
2011-02-03 17:11:26 +00:00
|
|
|
// Données de configuration placé dans le registre - a supprimer
|
2010-09-13 09:54:49 +00:00
|
|
|
$webservicesConfig = new Zend_Config_Ini(APPLICATION_PATH .
|
|
|
|
'/configs/webservices.ini', APPLICATION_ENV);
|
|
|
|
Zend_Registry::set('webservicesConfig',$webservicesConfig);
|
2010-08-30 07:49:44 +00:00
|
|
|
|
|
|
|
// traitement
|
2010-10-18 07:25:31 +00:00
|
|
|
try
|
|
|
|
{
|
2010-09-08 13:30:33 +00:00
|
|
|
if (APPLICATION_ENV == 'production') {
|
|
|
|
// @todo Vérifier la présence du fichier sinon envoyer erreur
|
2011-01-19 17:10:26 +00:00
|
|
|
$server = new Zend_Soap_Server($fichierWsdl);
|
2010-09-08 13:30:33 +00:00
|
|
|
} else {
|
|
|
|
$hostName = $this->getRequest()->getHttpHost();
|
|
|
|
$server = new Zend_Soap_Server('http://'.$hostName.'/service?wsdl-auto');
|
|
|
|
}
|
2011-02-04 11:32:55 +00:00
|
|
|
$proxy = new WrappedService_Proxy('Entreprise', array(), array('wrappedParts' => true));
|
2010-08-30 07:49:44 +00:00
|
|
|
$server->setObject($proxy);
|
2010-09-20 09:38:18 +00:00
|
|
|
$server->setClassmap($this->classmap);
|
2010-11-08 17:23:08 +00:00
|
|
|
$server->handle();
|
|
|
|
}
|
|
|
|
catch (Zend_Exception $e)
|
|
|
|
{
|
2010-10-25 14:29:50 +00:00
|
|
|
Zend_Registry::get('log')->err("Service - ".$e->getMessage());
|
2010-08-30 07:49:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
2011-02-03 17:11:26 +00:00
|
|
|
|
2010-08-30 07:49:44 +00:00
|
|
|
}
|
|
|
|
|