From 9aa7adf95d8dcc8465a696cb15379370d9c2efb5 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Thu, 2 Aug 2018 17:29:05 +0200
Subject: [PATCH] External SB controller curlSOAP

---
 modules/visa/class/IxbusController.php |  2 +-
 src/core/models/CurlModel.php          | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/modules/visa/class/IxbusController.php b/modules/visa/class/IxbusController.php
index 759ae4fe225..49be2965392 100755
--- a/modules/visa/class/IxbusController.php
+++ b/modules/visa/class/IxbusController.php
@@ -55,7 +55,7 @@ class IxbusController
             'soapAction'    => 'http://www.srci.fr/CreateSession'
         ]);
 
-        $response = $data->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children()->CreateSessionResponse;
+        $response = $data['response']->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children()->CreateSessionResponse;
 
         return $response;
     }
diff --git a/src/core/models/CurlModel.php b/src/core/models/CurlModel.php
index 6bddbd0d677..15306e16404 100644
--- a/src/core/models/CurlModel.php
+++ b/src/core/models/CurlModel.php
@@ -66,7 +66,7 @@ class CurlModel
 
     public static function execSOAP(array $aArgs)
     {
-        ValidatorModel::notEmpty($aArgs, ['xmlPostString', 'url', 'soapAction']);
+        ValidatorModel::notEmpty($aArgs, ['xmlPostString', 'url']);
         ValidatorModel::stringType($aArgs, ['xmlPostString', 'url', 'soapAction']);
         ValidatorModel::arrayType($aArgs, ['options']);
 
@@ -81,19 +81,23 @@ class CurlModel
                 'Cache-Control: no-cache',
                 'Pragma: no-cache',
                 'Content-length: ' . strlen($aArgs['xmlPostString']),
-                "SOAPAction: \"{$aArgs['soapAction']}\""
             ]
         ];
 
+        if (!empty($aArgs['soapAction'])) {
+            $opts[CURLOPT_HTTPHEADER][] = "SOAPAction: \"{$aArgs['soapAction']}\"";
+        }
         if (!empty($aArgs['options'])) {
-            $opts = array_merge($opts, $aArgs['options']);
+            foreach ($aArgs['options'] as $key => $option) {
+                $opts[$key] = $option;
+            }
         }
 
         $curl = curl_init();
         curl_setopt_array($curl, $opts);
         $rawResponse = curl_exec($curl);
 
-        return simplexml_load_string($rawResponse);
+        return ['response' => simplexml_load_string($rawResponse), 'infos' => curl_getinfo($curl)];
     }
 
     public static function getConfigByCallId(array $aArgs)
-- 
GitLab