1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<?php namespace PHPHtmlParser;
use PHPHtmlParser\Exceptions\NotLoadedException;
/** * Class StaticDom * * @package PHPHtmlParser */ final class StaticDom {
private static $dom = null;
/** * Attempts to call the given method on the most recent created dom * from bellow. * * @param string $method * @param array $arguments * @throws NotLoadedException * @return mixed */ public static function __callStatic($method, $arguments) { if (self::$dom instanceof Dom) { return call_user_func_array([self::$dom, $method], $arguments); } else { throw new NotLoadedException('The dom is not loaded. Can not call a dom method.'); } }
/** * Call this to mount the static facade. The facade allows you to use * this object as a $className. * * @param string $className * @param Dom $dom * @return bool */ public static function mount($className = 'Dom', Dom $dom = null) { if (class_exists($className)) { return false; } class_alias(__CLASS__, $className); if ($dom instanceof Dom) { self::$dom = $dom; }
return true; }
/** * Creates a new dom object and calls load() on the * new object. * * @param string $str * @return $this */ public static function load($str) { $dom = new Dom; self::$dom = $dom;
return $dom->load($str); }
/** * Creates a new dom object and calls loadFromFile() on the * new object. * * @param string $file * @return $this */ public static function loadFromFile($file) { $dom = new Dom; self::$dom = $dom;
return $dom->loadFromFile($file); }
/** * Creates a new dom object and calls loadFromUrl() on the * new object. * * @param string $url * @param array $options * @param CurlInterface $curl * @return $this */ public static function loadFromUrl($url, $options = [], CurlInterface $curl = null) { $dom = new Dom; self::$dom = $dom; if (is_null($curl)) { // use the default curl interface $curl = new Curl; }
return $dom->loadFromUrl($url, $options, $curl); }
/** * Sets the $dom variable to null. */ public static function unload() { self::$dom = null; } }
|