114 lines
2.9 KiB
PHP
114 lines
2.9 KiB
PHP
<?php
|
|
class DemoController extends Zend_Controller_Action
|
|
{
|
|
protected $_username;
|
|
protected $_hash;
|
|
|
|
protected $methods = array(
|
|
'getIdentite' => array(
|
|
'ws' => 'entreprise/v0.2?wsdl-auto',
|
|
'form' => 'getIdentite',
|
|
),
|
|
);
|
|
|
|
public function init()
|
|
{
|
|
require_once 'Web/demo/getIdentite.php';
|
|
}
|
|
|
|
public function preDispatch()
|
|
{
|
|
//Vérification connexion utilisateur
|
|
$auth = Zend_Auth::getInstance();
|
|
if (!$auth->hasIdentity()){
|
|
$this->_redirect('/user/login');
|
|
} else {
|
|
$bootstrap = $this->getInvokeArg('bootstrap');
|
|
$this->appConfig = $bootstrap->getOptions();
|
|
$this->_username = $auth->getIdentity()->username;
|
|
$this->_hash = $auth->getIdentity()->hash;
|
|
}
|
|
}
|
|
|
|
public function indexAction()
|
|
{
|
|
$tabMethods = array();
|
|
foreach($this->methods as $method => $element){
|
|
$url = $this->view->url(array(
|
|
'controller' => 'demo',
|
|
'action' => 'method',
|
|
'name' => $method,
|
|
));
|
|
$tabMethods[] = array(
|
|
'nom' => $method,
|
|
'url' => $url,
|
|
);
|
|
}
|
|
|
|
$this->view->assign('methods', $tabMethods);
|
|
}
|
|
|
|
public function methodAction()
|
|
{
|
|
$method = $this->_getParam('name','');
|
|
$this->view->assign('method', $method);
|
|
//Affichage du formulaire
|
|
if (array_key_exists($method, $this->methods)){
|
|
$class = 'Form_'.$method;
|
|
if (class_exists($class)){
|
|
$form = new $class;
|
|
$form->addElement('hidden', 'method', array(
|
|
'value' => $method,
|
|
));
|
|
if ($this->_request->isPost()) {
|
|
$formData = $this->_request->getPost();
|
|
$form->populate($formData);
|
|
}
|
|
$this->view->assign('form', $form);
|
|
} else {
|
|
$this->view->assign('message',"Impossible d'afficher le formulaire !");
|
|
}
|
|
}
|
|
}
|
|
|
|
public function requeteAction()
|
|
{
|
|
if ($this->_request->isPost()) {
|
|
$formData = $this->_request->getPost();
|
|
$method = $formData['method'];
|
|
$class = 'Form_'.$method;
|
|
if (class_exists($class)) {
|
|
$form = new $class;
|
|
if ($form->isValid($formData)) {
|
|
$method = $formData['method'];
|
|
$siret = $formData['siret'];
|
|
$accesWs = $this->methods[$method]['ws'];
|
|
$hostName = $this->getRequest()->getHttpHost();
|
|
$options = array(
|
|
'login' => $this->_username,
|
|
'password' => $this->_hash,
|
|
'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS
|
|
);
|
|
$client = new Zend_Soap_Client('http://'.$hostName.'/'.$accesWs, $options);
|
|
$params = new StdClass();
|
|
$params->siret = $siret;
|
|
$soap = array(
|
|
'requete' => $params,
|
|
'reponse' => $client->getIdentite($params)
|
|
);
|
|
$this->view->assign('soap',$soap);
|
|
$xml = array(
|
|
'requete' => $client->getLastRequest(),
|
|
'reponse' => $client->getLastResponse()
|
|
);
|
|
$this->view->assign('xml',$xml);
|
|
} else {
|
|
$this->_forward('method', 'demo', null, array('name'=> 'getIdentite'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|