2010-08-30 07:49:44 +00:00
|
|
|
<?php
|
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
|
|
|
|
{
|
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-07 17:02:09 +00:00
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
2011-02-04 13:46:11 +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-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
|
|
|
|
2011-10-10 13:15:48 +00:00
|
|
|
//Nom du service
|
2011-10-13 18:42:45 +00:00
|
|
|
$serviceName = $request->getParam('service', 'Entreprise');
|
2011-10-10 13:15:48 +00:00
|
|
|
|
2012-01-28 18:32:26 +00:00
|
|
|
//Chemin du fichier de configuration des versions
|
2011-10-12 09:54:28 +00:00
|
|
|
$pathServiceVersion = 'WsScore/'.ucfirst($serviceName).'/Versions.ini';
|
2011-10-10 13:15:48 +00:00
|
|
|
|
|
|
|
//Service spécifique client
|
|
|
|
if (strtolower($serviceName) == 'clients') {
|
|
|
|
$client = $request->getParam('client', '');
|
|
|
|
//Liste des clients
|
|
|
|
$clients = array();
|
|
|
|
$listeClients = new Zend_Config_Ini('WsScore/Clients/Clients.ini');
|
|
|
|
foreach ( $listeClients->toArray() as $section => $params ){
|
|
|
|
if ($params['actif']){
|
|
|
|
$clients[] = $section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!in_array($client, $clients)){
|
|
|
|
echo 'Service clients introuvable !';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$pathServiceVersion = 'WsScore/Clients/'.ucfirst($client).'/Versions.ini';
|
|
|
|
}
|
|
|
|
|
2011-02-04 13:46:11 +00:00
|
|
|
// Liste des versions
|
2011-10-10 13:15:48 +00:00
|
|
|
$configServiceVersions = new Zend_Config_Ini($pathServiceVersion);
|
2011-02-04 13:46:11 +00:00
|
|
|
foreach( $configServiceVersions->toArray() as $section => $params ){
|
|
|
|
$serviceVersions[$section] = $params;
|
2011-02-04 13:56:16 +00:00
|
|
|
if ($params['defaut']) {
|
2011-02-04 13:46:11 +00:00
|
|
|
$defautVersion = $section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$version = $request->getParam('version', 'v'.$defautVersion);
|
2011-10-10 13:15:48 +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-10-12 12:09:45 +00:00
|
|
|
// Charger les classes et les types pour le service suivant la version
|
2011-10-10 13:15:48 +00:00
|
|
|
if (strtolower($serviceName) == 'clients') {
|
|
|
|
$pathServiceClassIni = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.ini';
|
|
|
|
$pathServiceClassPhp = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.php';
|
2012-01-28 18:32:26 +00:00
|
|
|
//Gestion du mode de génération du wsdl
|
2012-02-02 20:51:00 +00:00
|
|
|
if ( APPLICATION_ENV == 'development'
|
|
|
|
|| array_key_exists('mode', $serviceVersions[$version])
|
|
|
|
&& $serviceVersions[$version]['mode']=='auto') {
|
|
|
|
$pathServiceUrl = 'clients/'.$client.'/v'.$version.'?wsdl-auto';
|
2012-01-28 18:32:26 +00:00
|
|
|
} else {
|
|
|
|
$pathServiceUrl = 'clients/'.$client.'/v'.$version.'?wsdl';
|
|
|
|
}
|
2011-10-10 13:15:48 +00:00
|
|
|
//On redéfini le nom du service
|
|
|
|
$serviceName = 'Entreprise';
|
|
|
|
$fichierWsdl = ucfirst($client).'-'.$serviceName.'-'.$version.'.wsdl';
|
|
|
|
} else {
|
2011-10-13 18:42:45 +00:00
|
|
|
$pathServiceClassIni = 'WsScore/'.ucfirst($serviceName).'/v'.$version.'/'.ucfirst($serviceName).'.ini';
|
|
|
|
$pathServiceClassPhp = 'WsScore/'.ucfirst($serviceName).'/v'.$version.'/'.ucfirst($serviceName).'.php';
|
2012-01-28 18:32:26 +00:00
|
|
|
//Gestion du mode de génération du wsdl
|
2012-02-02 20:51:00 +00:00
|
|
|
if ( APPLICATION_ENV == 'development'
|
|
|
|
|| array_key_exists('mode', $serviceVersions[$version])
|
|
|
|
&& $serviceVersions[$version]['mode']=='auto') {
|
|
|
|
$pathServiceUrl = $serviceName.'/v'.$version.'?wsdl-auto';
|
2012-01-28 18:32:26 +00:00
|
|
|
} else {
|
|
|
|
$pathServiceUrl = $serviceName.'/v'.$version.'?wsdl';
|
|
|
|
}
|
2011-10-13 18:42:45 +00:00
|
|
|
$fichierWsdl = ucfirst($serviceName).'-'.$version.'.wsdl';
|
2011-10-10 13:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Génération du tableau de mapping
|
|
|
|
$wsConfig = new Zend_Config_Ini($pathServiceClassIni);
|
2011-02-03 14:04:40 +00:00
|
|
|
foreach($wsConfig->Type->toArray() as $Type){
|
2011-02-07 17:02:09 +00:00
|
|
|
$classmap[$Type] = $Type;
|
2011-02-03 14:04:40 +00:00
|
|
|
}
|
2011-10-10 13:15:48 +00:00
|
|
|
|
|
|
|
//Inclusion des classes de données
|
|
|
|
require_once $pathServiceClassPhp;
|
|
|
|
|
2012-01-28 18:32:26 +00:00
|
|
|
// Fourniture du wsdl
|
2011-04-08 15:27:44 +00:00
|
|
|
if ( isset($_GET['wsdl']) && file_exists($fichierWsdl) ) {
|
|
|
|
|
|
|
|
if (!headers_sent()) {
|
|
|
|
header('Content-Type: text/xml');
|
|
|
|
}
|
|
|
|
echo file_get_contents($fichierWsdl);
|
|
|
|
|
|
|
|
} elseif ( isset($_GET['wsdl']) && !file_exists($fichierWsdl)
|
|
|
|
|| isset($_GET['wsdl-generate'])
|
|
|
|
|| isset($_GET['wsdl-auto']) ) {
|
|
|
|
|
|
|
|
// Définition du webservice
|
|
|
|
$wsdl = new Zend_Soap_AutoDiscover();
|
|
|
|
$wsdl->setComplexTypeStrategy('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
|
|
|
|
$wsdl->setOperationBodyStyle( array('use' => 'literal') );
|
|
|
|
$wsdl->setBindingStyle( array('style' => 'document') );
|
2011-10-13 18:42:45 +00:00
|
|
|
$wsdl->setClass(ucfirst($serviceName));
|
2010-08-30 07:49:44 +00:00
|
|
|
|
2011-04-08 15:27:44 +00:00
|
|
|
// Enregistrement du WSDL dans un fichier
|
|
|
|
if ( isset($_GET['wsdl-generate']) ) {
|
|
|
|
if (file_exists($fichierWsdl)) {
|
|
|
|
unlink($fichierWsdl);
|
|
|
|
}
|
|
|
|
$wsdl->dump($fichierWsdl);
|
|
|
|
echo "Le fichier $fichierWsdl a été généré";
|
2012-01-28 18:32:26 +00:00
|
|
|
|
|
|
|
//Génération/Fourniture du wsdl
|
2011-04-08 15:27:44 +00:00
|
|
|
} elseif (isset($_GET['wsdl']) && !file_exists($fichierWsdl)) {
|
|
|
|
$wsdl->dump($fichierWsdl);
|
|
|
|
if (!headers_sent()) {
|
|
|
|
header('Content-Type: text/xml');
|
|
|
|
}
|
|
|
|
echo file_get_contents($fichierWsdl);
|
|
|
|
|
2012-01-28 18:32:26 +00:00
|
|
|
// Envoi sur la sortie standard le wsdl sans enregistrement dans un fichier
|
2011-04-08 15:27:44 +00:00
|
|
|
} elseif ( isset($_GET['wsdl-auto']) ){
|
|
|
|
$wsdl->handle();
|
|
|
|
}
|
|
|
|
|
2010-08-30 07:49:44 +00:00
|
|
|
// Fourniture du service
|
|
|
|
} else {
|
|
|
|
|
2012-01-30 09:29:28 +00:00
|
|
|
// Traitement
|
2011-08-04 09:13:12 +00:00
|
|
|
if (APPLICATION_ENV == 'production' && file_exists($fichierWsdl)) {
|
|
|
|
$server = new Zend_Soap_Server($fichierWsdl);
|
|
|
|
} else {
|
|
|
|
$hostName = $this->getRequest()->getHttpHost();
|
2011-10-10 13:15:48 +00:00
|
|
|
$server = new Zend_Soap_Server('http://'.$hostName.'/'.$pathServiceUrl);
|
2011-08-04 09:13:12 +00:00
|
|
|
}
|
2011-10-13 18:42:45 +00:00
|
|
|
$proxy = new WrappedService_Proxy(ucfirst($serviceName), array(), array('wrappedParts' => true));
|
2011-08-24 14:50:09 +00:00
|
|
|
$server->setSoapFeatures(SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS);
|
|
|
|
$server->setClassmap($classmap);
|
2011-08-04 09:13:12 +00:00
|
|
|
$server->setEncoding('UTF-8');
|
2011-09-21 13:30:55 +00:00
|
|
|
$server->registerFaultException(array('WsScores_Exception'));
|
|
|
|
$server->setObject($proxy);
|
2011-08-04 09:13:12 +00:00
|
|
|
$server->handle();
|
2011-08-16 09:07:26 +00:00
|
|
|
|
2011-10-07 14:47:56 +00:00
|
|
|
//Pour débuggage ultime
|
|
|
|
$debug = false;
|
|
|
|
if ($debug){
|
|
|
|
$request = $server->getLastRequest();
|
|
|
|
file_put_contents(APPLICATION_PATH . '/../request.log', $request);
|
|
|
|
$response = $server->getLastResponse();
|
|
|
|
file_put_contents(APPLICATION_PATH . '/../response.log', $response);
|
|
|
|
}
|
2010-08-30 07:49:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-21 13:30:55 +00:00
|
|
|
}
|