Skip to content

Commit 78f3dd9

Browse files
committed
wrap curl_getinfo into its own class instead of array
1 parent c42b2be commit 78f3dd9

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed

src/BrowserClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ public function setCookies($cookies)
7474

7575
public function clearCookies()
7676
{
77-
unlink($this->getCookieFile());
77+
@unlink($this->getCookieFile());
7878
}
7979
}

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function request($method, $uri, $params = array(), $headers = array(), $c
6565
$response->status = $info ? $info['http_code'] : 0;
6666
$response->body = $result;
6767
$response->error = curl_error($ch);
68-
$response->info = $info;
68+
$response->info = new CurlInfo($info);
6969

7070
curl_close($ch);
7171

src/CurlInfo.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace Curl;
4+
5+
/** @noinspection SpellCheckingInspection */
6+
7+
/**
8+
* @property-read string $url
9+
* @property-read string $content_type
10+
* @property-read int $http_code
11+
* @property-read int $header_size
12+
* @property-read int $request_size
13+
* @property-read int $filetime
14+
* @property-read int $ssl_verify_result
15+
* @property-read int $redirect_count
16+
*
17+
* @property-read double $total_time
18+
* @property-read double $namelookup_time
19+
* @property-read double $connect_time
20+
* @property-read double $pretransfer_time
21+
*
22+
* @property-read int $size_upload
23+
* @property-read int $size_download
24+
*
25+
* @property-read int $speed_download
26+
* @property-read int $speed_upload
27+
*
28+
* @property-read int $download_content_length
29+
* @property-read int $upload_content_length
30+
*
31+
* @property-read double $starttransfer_time
32+
* @property-read double $redirect_time
33+
*
34+
* @property-read array $certinfo
35+
*
36+
* @property-read string $primary_ip
37+
* @property-read int $primary_port
38+
*
39+
* @property-read string $local_ip
40+
* @property-read int $local_port
41+
*
42+
* @property-read string $redirect_url
43+
*/
44+
class CurlInfo implements \ArrayAccess
45+
{
46+
protected $info;
47+
48+
public function __construct($info)
49+
{
50+
$this->info = $info;
51+
}
52+
53+
public function toArray()
54+
{
55+
return $this->info;
56+
}
57+
58+
public function __get($prop)
59+
{
60+
return $this->offsetGet($prop);
61+
}
62+
63+
/**
64+
* Whether a offset exists
65+
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
66+
* @param mixed $offset <p>
67+
* An offset to check for.
68+
* </p>
69+
* @return boolean true on success or false on failure.
70+
* </p>
71+
* <p>
72+
* The return value will be casted to boolean if non-boolean was returned.
73+
* @since 5.0.0
74+
*/
75+
public function offsetExists($offset)
76+
{
77+
return array_key_exists($offset, $this->info);
78+
}
79+
80+
/**
81+
* Offset to retrieve
82+
* @link https://php.net/manual/en/arrayaccess.offsetget.php
83+
* @param mixed $offset <p>
84+
* The offset to retrieve.
85+
* </p>
86+
* @return mixed Can return all value types.
87+
* @since 5.0.0
88+
*/
89+
public function offsetGet($offset)
90+
{
91+
return $this->info[$offset];
92+
}
93+
94+
/**
95+
* Offset to set
96+
* @link https://php.net/manual/en/arrayaccess.offsetset.php
97+
* @param mixed $offset <p>
98+
* The offset to assign the value to.
99+
* </p>
100+
* @param mixed $value <p>
101+
* The value to set.
102+
* </p>
103+
* @return void
104+
* @since 5.0.0
105+
*/
106+
public function offsetSet($offset, $value)
107+
{
108+
// READONLY
109+
}
110+
111+
/**
112+
* Offset to unset
113+
* @link https://php.net/manual/en/arrayaccess.offsetunset.php
114+
* @param mixed $offset <p>
115+
* The offset to unset.
116+
* </p>
117+
* @return void
118+
* @since 5.0.0
119+
*/
120+
public function offsetUnset($offset)
121+
{
122+
// READONLY
123+
}
124+
}

src/Response.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ class Response
1010

1111
// usually empty
1212
public $error;
13+
14+
/** @var CurlInfo */
1315
public $info;
1416
}

0 commit comments

Comments
 (0)