126 lines
3.8 KiB
PHP
126 lines
3.8 KiB
PHP
|
<?php
|
||
|
class SclientsController extends Zend_Controller_Action
|
||
|
{
|
||
|
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();
|
||
|
$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 '...';
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Liste des versions
|
||
|
$serviceVersions = array();
|
||
|
$configServiceVersions = new Zend_Config_Ini('WsScore/Clients/'.$client.'/Versions.ini');
|
||
|
foreach ( $configServiceVersions->toArray() as $section => $params ){
|
||
|
$serviceVersions[$section] = $params;
|
||
|
if ($params['defaut']) {
|
||
|
$defautVersion = $section;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$version = $request->getParam('version', 'v'.$defautVersion);
|
||
|
$version = substr($version, 1);
|
||
|
|
||
|
if (empty($version)) { $version = $defautVersion; }
|
||
|
|
||
|
// Version inexistante
|
||
|
if ( !array_key_exists($version, $serviceVersions) ) {
|
||
|
echo "Version inexistante.";
|
||
|
exit;
|
||
|
}
|
||
|
// Version désactivé
|
||
|
if ( !$serviceVersions[$version]['actif'] ) {
|
||
|
echo "Version désactivée.";
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Charger les classes et les types pour le service suivant la version
|
||
|
$pathClassService = 'WsScore/Clients/'.$client.'/v'.$version.'/';
|
||
|
$wsConfig = new Zend_Config_Ini($pathClassService.'Entreprise.ini');
|
||
|
foreach($wsConfig->Type->toArray() as $Type){
|
||
|
$classmap[$Type] = $Type;
|
||
|
}
|
||
|
require_once $pathClassService.'Entreprise.php';
|
||
|
// @todo : modifier le nom du fichier
|
||
|
$fichierWsdl = 'Entreprise-'.$version.'.wsdl';
|
||
|
|
||
|
// Fourniture du wsdl
|
||
|
if (isset($_GET['wsdl'])) {
|
||
|
if (file_exists($fichierWsdl)) {
|
||
|
if (!headers_sent()) {
|
||
|
header('Content-Type: text/xml');
|
||
|
}
|
||
|
echo file_get_contents($fichierWsdl);
|
||
|
} else {
|
||
|
echo "Erreur WSDL inexistant ";
|
||
|
}
|
||
|
}
|
||
|
// Génération du wsdl
|
||
|
elseif ( 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('Entreprise');
|
||
|
|
||
|
// Enregistrement du WSDL dans un fichier
|
||
|
if ( isset($_GET['wsdl-generate']) ) {
|
||
|
if (!file_exists($fichierWsdl)) {
|
||
|
$wsdl->dump($fichierWsdl);
|
||
|
echo "Le fichier $fichierWsdl a été généré";
|
||
|
} else {
|
||
|
echo "ERREUR : Le fichier $fichierWsdl est déjà présent !";
|
||
|
}
|
||
|
}
|
||
|
// Envoi sur la sortie standard le wsdl
|
||
|
elseif ( isset($_GET['wsdl-auto']) ){
|
||
|
$wsdl->handle();
|
||
|
}
|
||
|
|
||
|
// Fourniture du service
|
||
|
} else {
|
||
|
|
||
|
// traitement
|
||
|
try
|
||
|
{
|
||
|
if (APPLICATION_ENV == 'production') {
|
||
|
// @todo Vérifier la présence du fichier sinon envoyer erreur
|
||
|
$server = new Zend_Soap_Server($fichierWsdl);
|
||
|
} else {
|
||
|
$hostName = $this->getRequest()->getHttpHost();
|
||
|
$server = new Zend_Soap_Server('http://'.$hostName.'/clients/'.$client.'?wsdl-auto');
|
||
|
}
|
||
|
$proxy = new WrappedService_Proxy('Entreprise', array(), array('wrappedParts' => true));
|
||
|
$server->setObject($proxy);
|
||
|
$server->setClassmap($this->classmap);
|
||
|
$server->handle();
|
||
|
}
|
||
|
catch (Zend_Exception $e)
|
||
|
{
|
||
|
Zend_Registry::get('log')->err("Service - ".$e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
exit;
|
||
|
}
|
||
|
}
|