| @@ 860-889 (lines=30) @@ | ||
| 857 | * |
|
| 858 | * @return HtmlDomParser |
|
| 859 | */ |
|
| 860 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 861 | { |
|
| 862 | // reset |
|
| 863 | self::$domBrokenReplaceHelper = []; |
|
| 864 | ||
| 865 | if ( |
|
| 866 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 867 | && |
|
| 868 | !\file_exists($filePath) |
|
| 869 | ) { |
|
| 870 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 871 | } |
|
| 872 | ||
| 873 | try { |
|
| 874 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 875 | $html = \voku\helper\UTF8::file_get_contents($filePath); |
|
| 876 | } else { |
|
| 877 | $html = \file_get_contents($filePath); |
|
| 878 | } |
|
| 879 | } catch (\Exception $e) { |
|
| 880 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 881 | } |
|
| 882 | ||
| 883 | if ($html === false) { |
|
| 884 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 885 | } |
|
| 886 | ||
| 887 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 888 | } |
|
| 889 | ||
| 890 | /** |
|
| 891 | * Get the HTML as XML or plain XML if needed. |
|
| 892 | * |
|
| @@ 521-547 (lines=27) @@ | ||
| 518 | * |
|
| 519 | * @return XmlDomParser |
|
| 520 | */ |
|
| 521 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 522 | { |
|
| 523 | if ( |
|
| 524 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 525 | && |
|
| 526 | !\file_exists($filePath) |
|
| 527 | ) { |
|
| 528 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 529 | } |
|
| 530 | ||
| 531 | try { |
|
| 532 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 533 | $html = \voku\helper\UTF8::file_get_contents($filePath); |
|
| 534 | } else { |
|
| 535 | $html = \file_get_contents($filePath); |
|
| 536 | } |
|
| 537 | } catch (\Exception $e) { |
|
| 538 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 539 | } |
|
| 540 | ||
| 541 | if ($html === false) { |
|
| 542 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 543 | } |
|
| 544 | ||
| 545 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 546 | } |
|
| 547 | ||
| 548 | /** |
|
| 549 | * @param string $selector |
|
| 550 | * @param int $idx |
|
| @@ 598-624 (lines=27) @@ | ||
| 595 | * |
|
| 596 | * @return XmlDomParser |
|
| 597 | */ |
|
| 598 | public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
| 599 | { |
|
| 600 | if ( |
|
| 601 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 602 | && |
|
| 603 | !\file_exists($filePath) |
|
| 604 | ) { |
|
| 605 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 606 | } |
|
| 607 | ||
| 608 | try { |
|
| 609 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 610 | $xml = \voku\helper\UTF8::file_get_contents($filePath); |
|
| 611 | } else { |
|
| 612 | $xml = \file_get_contents($filePath); |
|
| 613 | } |
|
| 614 | } catch (\Exception $e) { |
|
| 615 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 616 | } |
|
| 617 | ||
| 618 | if ($xml === false) { |
|
| 619 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 620 | } |
|
| 621 | ||
| 622 | return $this->loadXml($xml, $libXMLExtraOptions); |
|
| 623 | } |
|
| 624 | ||
| 625 | /** |
|
| 626 | * @param callable $callback |
|
| 627 | * @param \DOMNode|null $domNode |
|