Use class of Zend where proxy is integrated to deliver .NET compatible service
This commit is contained in:
parent
bbfe653421
commit
6b699461ea
@ -3,35 +3,31 @@ require_once 'framework/fwk.php';
|
||||
|
||||
class ServiceController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
public function init(){}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
require_once 'Zend/Exception.php';
|
||||
require_once 'Zend/Soap/AutoDiscover.php';
|
||||
require_once 'Zend/Soap/Server.php';
|
||||
require_once 'WsScore/WrappedServiceProxy.php';
|
||||
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
//Nom du service
|
||||
$serviceName = $request->getParam('service', 'Entreprise');
|
||||
|
||||
//Chemin du fichier de configuration des versions
|
||||
$pathServiceVersion = 'WsScore/'.ucfirst($serviceName).'/Versions.ini';
|
||||
|
||||
//Service spécifique client
|
||||
if (strtolower($serviceName) == 'clients') {
|
||||
$client = $request->getParam('client', '');
|
||||
//Liste des clients
|
||||
|
||||
//Get the service name, make sure the string is in lower case
|
||||
$serviceName = strtolower($request->getParam('service', 'Entreprise'));
|
||||
|
||||
//ClassName and Directory with first letter capitalized
|
||||
$serviceClassName = ucfirst($serviceName);
|
||||
|
||||
//path of file where versions of service is store
|
||||
$pathServiceVersion = 'WsScore/'.$serviceClassName.'/Versions.ini';
|
||||
|
||||
//Customize service for customers
|
||||
if ('clients' == $serviceName ) {
|
||||
$client = strtolower($request->getParam('client', ''));
|
||||
$clientClassName = ucfirst($client);
|
||||
//Get list of customers
|
||||
$clients = array();
|
||||
$listeClients = new Zend_Config_Ini('WsScore/Clients/Clients.ini');
|
||||
foreach ( $listeClients->toArray() as $section => $params ){
|
||||
if ($params['actif']){
|
||||
if ($params['actif']) {
|
||||
$clients[] = $section;
|
||||
}
|
||||
}
|
||||
@ -39,9 +35,9 @@ class ServiceController extends Zend_Controller_Action
|
||||
echo 'Service clients introuvable !';
|
||||
exit;
|
||||
}
|
||||
$pathServiceVersion = 'WsScore/Clients/'.ucfirst($client).'/Versions.ini';
|
||||
$pathServiceVersion = 'WsScore/Clients/'.$clientClassName.'/Versions.ini';
|
||||
}
|
||||
|
||||
|
||||
// Liste des versions
|
||||
$configServiceVersions = new Zend_Config_Ini($pathServiceVersion);
|
||||
foreach( $configServiceVersions->toArray() as $section => $params ){
|
||||
@ -52,7 +48,7 @@ class ServiceController extends Zend_Controller_Action
|
||||
}
|
||||
$version = $request->getParam('version', 'v'.$defautVersion);
|
||||
$version = substr($version, 1);
|
||||
|
||||
|
||||
// Version inexistante
|
||||
if ( !array_key_exists($version, $serviceVersions) ) {
|
||||
echo "Version inexistante.";
|
||||
@ -63,14 +59,14 @@ class ServiceController extends Zend_Controller_Action
|
||||
echo "Version désactivée.";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Charger les classes et les types pour le service suivant la version
|
||||
if (strtolower($serviceName) == 'clients') {
|
||||
$pathServiceClassIni = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.ini';
|
||||
$pathServiceClassPhp = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.php';
|
||||
|
||||
// Charger les classes et les types pour le service suivant la version
|
||||
if ('clients' == $serviceName) {
|
||||
$pathServiceClassIni = 'WsScore/Clients/'.$clientClassName.'/v'.$version.'/Entreprise.ini';
|
||||
$pathServiceClassPhp = 'WsScore/Clients/'.$clientClassName.'/v'.$version.'/Entreprise.php';
|
||||
//Gestion du mode de génération du wsdl
|
||||
if ( APPLICATION_ENV == 'development'
|
||||
|| array_key_exists('mode', $serviceVersions[$version])
|
||||
if ( APPLICATION_ENV == 'development'
|
||||
|| array_key_exists('mode', $serviceVersions[$version])
|
||||
&& $serviceVersions[$version]['mode']=='auto') {
|
||||
$pathServiceUrl = 'clients/'.$client.'/v'.$version.'?wsdl-auto';
|
||||
} else {
|
||||
@ -78,21 +74,21 @@ class ServiceController extends Zend_Controller_Action
|
||||
}
|
||||
//On redéfini le nom du service
|
||||
$serviceName = 'Entreprise';
|
||||
$fichierWsdl = ucfirst($client).'-'.$serviceName.'-'.$version.'.wsdl';
|
||||
} else {
|
||||
$pathServiceClassIni = 'WsScore/'.ucfirst($serviceName).'/v'.$version.'/'.ucfirst($serviceName).'.ini';
|
||||
$pathServiceClassPhp = 'WsScore/'.ucfirst($serviceName).'/v'.$version.'/'.ucfirst($serviceName).'.php';
|
||||
$fichierWsdl = $clientClassName.'-'.$serviceName.'-'.$version.'.wsdl';
|
||||
} else {
|
||||
$pathServiceClassIni = 'WsScore/'.$serviceClassName.'/v'.$version.'/'.$serviceClassName.'.ini';
|
||||
$pathServiceClassPhp = 'WsScore/'.$serviceClassName.'/v'.$version.'/'.$serviceClassName.'.php';
|
||||
//Gestion du mode de génération du wsdl
|
||||
if ( APPLICATION_ENV == 'development'
|
||||
|| array_key_exists('mode', $serviceVersions[$version])
|
||||
if ( APPLICATION_ENV == 'development'
|
||||
|| array_key_exists('mode', $serviceVersions[$version])
|
||||
&& $serviceVersions[$version]['mode']=='auto') {
|
||||
$pathServiceUrl = $serviceName.'/v'.$version.'?wsdl-auto';
|
||||
} else {
|
||||
$pathServiceUrl = $serviceName.'/v'.$version.'?wsdl';
|
||||
}
|
||||
$fichierWsdl = ucfirst($serviceName).'-'.$version.'.wsdl';
|
||||
$fichierWsdl = $serviceClassName.'-'.$version.'.wsdl';
|
||||
}
|
||||
|
||||
|
||||
//Génération du tableau de mapping
|
||||
$classmap = array();
|
||||
$wsConfig = new Zend_Config_Ini($pathServiceClassIni);
|
||||
@ -103,25 +99,25 @@ class ServiceController extends Zend_Controller_Action
|
||||
}
|
||||
//Inclusion des classes de données
|
||||
require_once $pathServiceClassPhp;
|
||||
|
||||
|
||||
// Fourniture du wsdl
|
||||
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') );
|
||||
$wsdl->setClass(ucfirst($serviceName));
|
||||
$wsdl->setClass($serviceClassName);
|
||||
|
||||
// Enregistrement du WSDL dans un fichier
|
||||
if ( isset($_GET['wsdl-generate']) ) {
|
||||
@ -138,12 +134,12 @@ class ServiceController extends Zend_Controller_Action
|
||||
header('Content-Type: text/xml');
|
||||
}
|
||||
echo file_get_contents($fichierWsdl);
|
||||
|
||||
|
||||
// Envoi sur la sortie standard le wsdl sans enregistrement dans un fichier
|
||||
} elseif ( isset($_GET['wsdl-auto']) ){
|
||||
$wsdl->handle();
|
||||
}
|
||||
|
||||
|
||||
// Fourniture du service
|
||||
} else {
|
||||
|
||||
@ -154,20 +150,21 @@ class ServiceController extends Zend_Controller_Action
|
||||
$hostName = $this->getRequest()->getHttpHost();
|
||||
$server = new Zend_Soap_Server('http://'.$hostName.'/'.$pathServiceUrl);
|
||||
}
|
||||
$proxy = new WrappedService_Proxy(ucfirst($serviceName), array(), array('wrappedParts' => true));
|
||||
|
||||
$server->setSoapFeatures(SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS);
|
||||
$server->setClassmap($classmap);
|
||||
$server->setEncoding('UTF-8');
|
||||
$server->registerFaultException(array('WsScores_Exception'));
|
||||
$server->setObject($proxy);
|
||||
$server->setWsiCompliant(true);
|
||||
$server->setObject(new $serviceClassName());
|
||||
$server->handle();
|
||||
|
||||
|
||||
//Pour débuggage ultime
|
||||
$debug = false;
|
||||
if ($debug){
|
||||
$request = $server->getLastRequest();
|
||||
file_put_contents(APPLICATION_PATH . '/../request.log', $request);
|
||||
$response = $server->getLastResponse();
|
||||
$response = $server->getLastResponse();
|
||||
file_put_contents(APPLICATION_PATH . '/../response.log', $response);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user