Skip to content

Commit 56ac888

Browse files
committed
curl status code can be read from dom object
1 parent dc647f8 commit 56ac888

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/PHPHtmlParser/Curl.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
class Curl implements CurlInterface
1212
{
1313

14+
/**
15+
* The status code of the response.
16+
*
17+
* @var int
18+
*/
19+
public $statusCode;
20+
1421
/**
1522
* A simple curl implementation to get the content of the url.
1623
*
@@ -36,6 +43,8 @@ public function get($url)
3643
throw new CurlException('Error retrieving "'.$url.'" ('.$error.')');
3744
}
3845

46+
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
47+
3948
return $content;
4049
}
4150
}

src/PHPHtmlParser/Dom.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class Dom
3030
*/
3131
public $root;
3232

33+
/**
34+
* The status code if loaded via url.
35+
*
36+
* @var int
37+
*/
38+
public $statusCode;
39+
3340
/**
3441
* The raw version of the document string.
3542
*
@@ -160,6 +167,8 @@ public function loadFromUrl($url, $options = [], CurlInterface $curl = null)
160167
$curl = new Curl;
161168
}
162169
$content = $curl->get($url);
170+
171+
$this->statusCode = $curl->statusCode;
163172

164173
return $this->loadStr($content, $options);
165174
}

0 commit comments

Comments
 (0)