|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* php-guard/curl <https://github.com/php-guard/curl> |
|
4
|
|
|
* Copyright (C) 2018 by Alexandre Le Borgne <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace PhpGuard\Curl; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class CurlResponseFactory |
|
24
|
|
|
{ |
|
25
|
12 |
|
public function create($result, array $info) |
|
26
|
|
|
{ |
|
27
|
12 |
|
$statusCode = $info['http_code']; |
|
28
|
12 |
|
$headerSize = $info['header_size']; |
|
29
|
12 |
|
$rawHeaders = substr($result, 0, $headerSize); |
|
30
|
12 |
|
$raw = substr($result, $headerSize); |
|
31
|
|
|
|
|
32
|
|
|
$headers = array_reduce(explode("\n", $rawHeaders), function ($headers, $header) { |
|
33
|
12 |
|
$parts = explode(':', $header); |
|
34
|
12 |
|
if (count($parts) == 2) { |
|
35
|
12 |
|
$headers[trim($parts[0])] = trim($parts[1]); |
|
36
|
|
|
} |
|
37
|
12 |
|
return $headers; |
|
38
|
12 |
|
}, []); |
|
39
|
|
|
|
|
40
|
12 |
|
return new CurlResponse($statusCode, $raw, $headers, $info); |
|
41
|
|
|
} |
|
42
|
|
|
} |