107 lines
4.1 KiB
PHP
107 lines
4.1 KiB
PHP
<?php
|
|
class JsonrpcController extends Zend_Controller_Action
|
|
{
|
|
public function indexAction()
|
|
{
|
|
$this->_helper->layout->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
//Nom du service
|
|
$serviceName = strtolower($request->getParam('service', 'Entreprise'));
|
|
|
|
//Service spécifique client
|
|
if ($serviceName == 'clients') {
|
|
$client = $request->getParam('client', '');
|
|
//Liste des clients
|
|
$clients = array();
|
|
$listeClients = include APPLICATION_PATH . '/../library/WsScore/Clients/ClientsConfig.php';
|
|
foreach ($listeClients as $section => $params) {
|
|
if ($params['actif']) {
|
|
$clients[] = $section;
|
|
}
|
|
}
|
|
if (!in_array($client, $clients)) {
|
|
echo 'Service clients introuvable !';
|
|
exit;
|
|
}
|
|
$configServiceVersions = $clients[$client]['versions'];
|
|
} else {
|
|
//Service versions
|
|
$services = include APPLICATION_PATH . '/../library/WsScore/ServicesConfig.php';
|
|
$configServiceVersions = $services[$serviceName]['versions'];
|
|
}
|
|
|
|
//Liste des versions
|
|
foreach ($configServiceVersions as $section => $params) {
|
|
$serviceVersions[$section] = $params;
|
|
if ($params['defaut']) {
|
|
$defautVersion = $section;
|
|
}
|
|
}
|
|
$version = $request->getParam('version', 'v'.$defautVersion);
|
|
$version = substr($version, 1);
|
|
|
|
// 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
|
|
if ($serviceName == 'clients') {
|
|
$pathServiceClassIni = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.ini';
|
|
$pathServiceClassPhp = 'WsScore/Clients/'.ucfirst($client).'/v'.$version.'/Entreprise.php';
|
|
$pathServiceUrl = 'clients/'.$client.'/v'.$version.'?wsdl-auto';
|
|
//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';
|
|
$pathServiceUrl = $serviceName.'/v'.$version.'?wsdl-auto';
|
|
$fichierWsdl = ucfirst($serviceName).'-'.$version.'.wsdl';
|
|
}
|
|
|
|
//Génération du tableau de mapping
|
|
$wsConfig = new Zend_Config_Ini($pathServiceClassIni);
|
|
foreach ($wsConfig->Type->toArray() as $Type) {
|
|
$classmap[$Type] = $Type;
|
|
}
|
|
|
|
//Inclusion des classes de données
|
|
require_once $pathServiceClassPhp;
|
|
|
|
// Instance du server
|
|
$server = new Zend_Json_Server();
|
|
// Define class name
|
|
$server->setClass(ucfirst($serviceName));
|
|
|
|
// Gestion du SMD
|
|
if ($this->getRequest()->isGet()) {
|
|
// Indiquer URL endpoint
|
|
//$this->getHelper('url')->url(array('controller'=>'', 'action'=>'' ));
|
|
$server->setTarget('/jsonrpc/'.$serviceName.'/'.$version.'/')
|
|
->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
|
|
// Grab the SMD
|
|
$smd = $server->getServiceMap();
|
|
|
|
//Return the SMD to the client
|
|
if (!headers_sent()) {
|
|
header('Content-Type: application/json');
|
|
}
|
|
echo $smd;
|
|
return;
|
|
} else {
|
|
$server->setAutoEmitResponse(true);
|
|
$server->handle();
|
|
}
|
|
}
|
|
}
|