File tree Expand file tree Collapse file tree 2 files changed +65
-3
lines changed
Expand file tree Collapse file tree 2 files changed +65
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace hmerritt \Dom ;
3+
4+ /**
5+ * Class Imdb
6+ *
7+ *
8+ * @package hmerritt/imdb-api
9+ * @author Harry Merritt
10+ */
11+ class Dom
12+ {
13+
14+ /**
15+ * Fetch and parse the DOM of a remote site
16+ *
17+ * @param string $url
18+ *
19+ * @return Dom
20+ */
21+ public function fetch (string $ url , array $ options ): Dom
22+ {
23+ $ dom = new Dom ;
24+ $ dom ->loadFromUrl ($ url , [
25+ "curlHeaders " => $ options ["curlHeaders " ]
26+ ]);
27+ return $ dom ;
28+ }
29+
30+ /**
31+ * Find object within DOM (if it exists) and reutrn an attribute
32+ *
33+ * @param object $dom
34+ * @param string $selection
35+ *
36+ * @return array
37+ */
38+ public function find (object $ dom , string $ selection ): array
39+ {
40+ $ found = $ dom ->find ($ selection );
41+ if (count ($ found ) > 0 ) {
42+ return $ found ;
43+ }
44+ else {
45+ return $ this ->emptyElement ();
46+ }
47+ }
48+
49+ /**
50+ * Create and parse an empty html string as a DOM element
51+ *
52+ * @return Dom
53+ */
54+ private function emptyElement (): Dom
55+ {
56+ $ dom = new Dom ;
57+ $ dom ->load ('<a src="" href="" data-video=""></a> ' );
58+ return $ dom ;
59+ }
60+
61+ }
Original file line number Diff line number Diff line change @@ -30,8 +30,9 @@ private function populateOptions(array $options = []): array
3030 {
3131 // Default options
3232 $ defaults = [
33- 'cache ' => true ,
34- 'techSpecs ' => true ,
33+ 'cache ' => true ,
34+ 'curlHeaders ' => [],
35+ 'techSpecs ' => true ,
3536 ];
3637
3738 // Merge any user options with the default ones
@@ -67,7 +68,7 @@ public function film(string $film, array $options = []): array
6768 * Searches IMDB for films, people and companies
6869 * @param string $search
6970 * @param array $options
70- * @return $searchData
71+ * @return array $searchData
7172 */
7273 public function search (string $ search , array $ options = []): array
7374 {
You can’t perform that action at this time.
0 commit comments