Projet

Général

Profil

CurlModel.diff

Laurent GIOVANNONI, 02/07/2020 13:07

Voir les différences:

src/core/models/CurlModel.php
95 95
        ValidatorModel::notEmpty($aArgs, ['xmlPostString', 'url']);
96 96
        ValidatorModel::stringType($aArgs, ['xmlPostString', 'url', 'soapAction']);
97 97
        ValidatorModel::arrayType($aArgs, ['options']);
98

  
99 98
        $opts = [
100 99
            CURLOPT_URL             => $aArgs['url'],
101 100
            CURLOPT_RETURNTRANSFER  => true,
......
122 121
        $curl = curl_init();
123 122
        curl_setopt_array($curl, $opts);
124 123
        $rawResponse = curl_exec($curl);
124

  
125 125
        $error = curl_error($curl);
126 126
        $infos = curl_getinfo($curl);
127 127

  
128 128
        $cookies = [];
129 129
        if (!empty($aArgs['options'][CURLOPT_HEADER])) {
130 130
            preg_match_all('/Set-Cookie:\s*([;]*)/mi', $rawResponse, $matches);
131
            //preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $rawResponse, $matches);
131 132
            foreach ($matches[1] as $item) {
132 133
                $cookie = explode("=", $item);
133 134
                $cookies = array_merge($cookies, [$cookie[0] => $cookie[1]]);
134 135
            }
135 136
            $rawResponse = substr($rawResponse, $infos['header_size']);
136 137
        } elseif (!empty($aArgs['delete_header'])) { // Delete header for iparapheur
137
            $body = explode(PHP_EOL . PHP_EOL, $rawResponse)[1]; // put the header ahead
138
            $body = strstr($rawResponse, '<?xml');
139
            //$body = explode(PHP_EOL . PHP_EOL, $rawResponse)[1]; // put the header ahead
138 140
            if (empty($body)) {
139 141
                $body = explode(PHP_EOL, $rawResponse);
140 142
                // we remove the 4 starting item of the array (header)
......
171 173
            ]);
172 174
        }
173 175

  
174
        return ['response' => simplexml_load_string($rawResponse), 'infos' => $infos, 'cookies' => $cookies, 'raw' => $rawResponse, 'error' => $error];
176
        /*$testXml = simplexml_load_string($rawResponse);
177
        if ($testXml === false) {
178
            echo 'error XML' . PHP_EOL;
179
            var_dump($rawResponse);
180
            $rawResponse = "<?xml version='1.0'><ROOT><S:Envelope><S:Body><ns2:GetHistoDossierResponse><ns2:LogDossier><ns2:annotation>" . $rawResponse . "</ROOT>";
181
            return ['response' => simplexml_load_string($rawResponse), 'infos' => $infos, 'cookies' => $cookies, 'raw' => $rawResponse, 'error' => $error];
182
            //return false;
183
        } else {*/
184
            return ['response' => simplexml_load_string($rawResponse), 'infos' => $infos, 'cookies' => $cookies, 'raw' => $rawResponse, 'error' => $error];
185
        //}
175 186
    }
176 187

  
177 188
    public static function getConfigByCallId(array $aArgs)