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 $wsdlName = 'WsEntreprise';
|
2011-01-24 12:52:32 +00:00
|
|
|
protected $wsdlVersion = '0.2';
|
2010-09-20 09:38:18 +00:00
|
|
|
protected $classmap = array();
|
2010-08-30 07:49:44 +00:00
|
|
|
|
2011-02-03 14:04:40 +00:00
|
|
|
protected $serviceVersions = array(
|
|
|
|
'0.2' => true,
|
|
|
|
);
|
|
|
|
|
2010-08-30 07:49:44 +00:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-02-03 14:04:40 +00:00
|
|
|
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-03 14:04:40 +00:00
|
|
|
|
|
|
|
$request = $this->getRequest();
|
2011-02-03 14:43:00 +00:00
|
|
|
$version = $request->getParam('version', 'v'.$this->wsdlVersion);
|
|
|
|
$version = substr($version, 1);
|
|
|
|
|
2011-02-03 14:04:40 +00:00
|
|
|
//Version inexistante
|
|
|
|
if ( !array_key_exists($version, $this->serviceVersions) ) {
|
|
|
|
if (isset($_GET['wsdl'])) {
|
|
|
|
echo "Version inexistante.";
|
|
|
|
} else {
|
|
|
|
require_once 'WsScore/WsScore.php';
|
|
|
|
$ws = new WsScore();
|
|
|
|
$ws->sendError('9004');
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
//Version désactivé
|
|
|
|
if ( !$this->serviceVersions[$version] ) {
|
|
|
|
if (isset($_GET['wsdl'])) {
|
|
|
|
echo "Version désactivée.";
|
|
|
|
} else {
|
|
|
|
require_once 'WsScore/WsScore.php';
|
|
|
|
$ws = new WsScore();
|
|
|
|
$ws->sendError('9003');
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Charger les classes et les types pour le service suivant la version
|
|
|
|
$pathClassService = 'WsScore/v'.$version.'/';
|
|
|
|
$wsConfig = new Zend_Config_Ini($pathClassService.'WsEntreprise.ini');
|
|
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
|
|
|
$this->classmap[$Type] = $Type;
|
|
|
|
}
|
|
|
|
require_once $pathClassService.'WsEntreprise.php';
|
|
|
|
$fichierWsdl = $this->wsdlName.'-'.$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 {
|
2010-09-08 13:30:33 +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') );
|
|
|
|
$wsdl->setClass('WsEntreprise');
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
2010-09-14 16:36:29 +00:00
|
|
|
// Données de configuration placé dans le registre
|
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');
|
|
|
|
}
|
|
|
|
$proxy = new WrappedService_Proxy('WsEntreprise', 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 14:04:40 +00:00
|
|
|
|
|
|
|
public function testpAction()
|
|
|
|
{
|
|
|
|
$request = $this->getRequest();
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($request->getParams());
|
|
|
|
echo "</pre>";
|
|
|
|
exit;
|
|
|
|
}
|
2010-08-30 07:49:44 +00:00
|
|
|
}
|
|
|
|
|