| @@ 931-957 (lines=27) @@ | ||
| 928 | * |
|
| 929 | * @return HtmlDomParser |
|
| 930 | */ |
|
| 931 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
| 932 | { |
|
| 933 | if ( |
|
| 934 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 935 | && |
|
| 936 | !\file_exists($filePath) |
|
| 937 | ) { |
|
| 938 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 939 | } |
|
| 940 | ||
| 941 | try { |
|
| 942 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 943 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 944 | $html = UTF8::file_get_contents($filePath); |
|
| 945 | } else { |
|
| 946 | $html = \file_get_contents($filePath); |
|
| 947 | } |
|
| 948 | } catch (\Exception $e) { |
|
| 949 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 950 | } |
|
| 951 | ||
| 952 | if ($html === false) { |
|
| 953 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 954 | } |
|
| 955 | ||
| 956 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 957 | } |
|
| 958 | ||
| 959 | /** |
|
| 960 | * @param string $html |
|
| @@ 154-180 (lines=27) @@ | ||
| 151 | * |
|
| 152 | * @return XmlParser |
|
| 153 | */ |
|
| 154 | public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
| 155 | { |
|
| 156 | if ( |
|
| 157 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 158 | && |
|
| 159 | !\file_exists($filePath) |
|
| 160 | ) { |
|
| 161 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 162 | } |
|
| 163 | ||
| 164 | try { |
|
| 165 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 166 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 167 | $xml = UTF8::file_get_contents($filePath); |
|
| 168 | } else { |
|
| 169 | $xml = \file_get_contents($filePath); |
|
| 170 | } |
|
| 171 | } catch (\Exception $e) { |
|
| 172 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 173 | } |
|
| 174 | ||
| 175 | if ($xml === false) { |
|
| 176 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 177 | } |
|
| 178 | ||
| 179 | return $this->loadXml($xml, $libXMLExtraOptions); |
|
| 180 | } |
|
| 181 | ||
| 182 | /** |
|
| 183 | * @param callable $callback |
|