@@ -98,6 +98,31 @@ public function __construct(Service $service, C\Config $config, $server, $login,
9898 protected function _initSoapAPI ($ key , $ server , $ urn , $ httpProxy , $ httpsProxy )
9999 {
100100 $ this ->_soapAPI ->{$ key } = new C \Soap ($ server .'/ ' .$ urn , 'DCIM_ ' .$ key , $ this ->_debug );
101+
102+ switch (substr ($ server , 0 , 6 ))
103+ {
104+ case 'http:/ ' :
105+ if (C \Tools::is ('string&&!empty ' , $ httpProxy )) {
106+ $ useHttpProxy = $ httpProxy ;
107+ }
108+ break ;
109+ case 'https: ' :
110+ if (C \Tools::is ('string&&!empty ' , $ httpsProxy )) {
111+ $ useHttpProxy = $ httpsProxy ;
112+ }
113+ break ;
114+ default :
115+ throw new Exception ("L'adresse du serveur DCIM doit commencer par http ou https " , E_USER_ERROR );
116+ }
117+
118+ if (isset ($ useHttpProxy ) && preg_match ('#^(http(?:s)?:\/\/[^:]*)(?::([0-9]*))?$#i ' , $ useHttpProxy , $ matches ))
119+ {
120+ $ this ->_soapAPI ->{$ key }->setOpt ('proxy_host ' , $ matches [1 ]);
121+
122+ if (isset ($ matches [2 ])) {
123+ $ this ->_soapAPI ->{$ key }->setOpt ('proxy_port ' , $ matches [2 ]);
124+ }
125+ }
101126 }
102127
103128 public function getServerId ()
@@ -242,7 +267,7 @@ public function getCabinetIdsByLocationId($locationId)
242267 $ cabinetIds = array ();
243268 $ cabinetLabels = $ this ->getCabinetLabelsByLocationId ($ locationId );
244269
245- foreach ($ cabinetLabels as $ index => $ cabinetLabel )
270+ foreach ($ cabinetLabels as $ cabinetLabel )
246271 {
247272 if ($ this ->isValidReturn ($ cabinetLabel ))
248273 {
@@ -269,6 +294,11 @@ public function getCabinetLabelsByLocationId($locationId)
269294 return $ this ->_castToString ($ cabinetLabels );
270295 }
271296
297+ /**
298+ * @param int $locationId
299+ * @param string $cabinetLabel
300+ * @return int|string Cabinet ID or string if an error occurs
301+ */
272302 public function getCabinetIdByLocationIdCabinetLabel ($ locationId , $ cabinetLabel )
273303 {
274304 $ args = $ this ->getArgs (array ($ cabinetLabel , $ locationId ));
@@ -765,23 +795,35 @@ public function getReportResults($reportName, array $wildCards = null)
765795 $ results = $ this ->_soapAPI ->search ->reportToClient ($ args );
766796
767797 // [ERROR] [ERROR] Incorrect format of the Wild Cards.
768- if ($ this ->isValidReturn ($ results )) {
798+ if ($ this ->isValidReturn ($ results ))
799+ {
769800 $ bytes = explode ('; ' , $ results ->return );
770801 //$csv = implode(array_map("chr", $bytes));
771802 $ csv = pack ('C* ' , ...$ bytes );
772803 $ csv = str_replace ("\n\000" , '' , $ csv );
773804 $ csv = explode ("\n" , $ csv );
805+
774806 array_walk ($ csv , function (&$ line , $ key ) {
775807 $ line = str_getcsv ($ line , $ this ->_reportCsvDelimiter );
776808 });
809+
777810 $ keys = array_shift ($ csv );
811+
778812 array_walk ($ keys , function (&$ key ) {
779813 $ key = mb_strtolower ($ key );
780814 $ key = str_replace (' ' , '_ ' , $ key );
781815 });
782- array_walk ($ csv , function (&$ value , $ key , $ keys ) {
783- $ value = array_combine ($ keys , $ value );
816+
817+ array_walk ($ csv , function (&$ value , $ key , $ keys )
818+ {
819+ if (count ($ keys ) === count ($ value )) {
820+ $ value = array_combine ($ keys , $ value );
821+ }
822+ else {
823+ throw new Exception ("DCIM report result is not valid, head field number ( " .count ($ keys ).") do not match value field number ( " .count ($ value ).") " , E_USER_ERROR );
824+ }
784825 }, $ keys );
826+
785827 return $ csv ;
786828
787829 }
0 commit comments