@@ 434-460 (lines=27) @@ | ||
431 | * |
|
432 | * @return XmlDomParser |
|
433 | */ |
|
434 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
435 | { |
|
436 | if ( |
|
437 | !\preg_match("/^https?:\/\//i", $filePath) |
|
438 | && |
|
439 | !\file_exists($filePath) |
|
440 | ) { |
|
441 | throw new \RuntimeException("File ${filePath} not found"); |
|
442 | } |
|
443 | ||
444 | try { |
|
445 | if (\class_exists('\voku\helper\UTF8')) { |
|
446 | /** @noinspection PhpUndefinedClassInspection */ |
|
447 | $html = UTF8::file_get_contents($filePath); |
|
448 | } else { |
|
449 | $html = \file_get_contents($filePath); |
|
450 | } |
|
451 | } catch (\Exception $e) { |
|
452 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
453 | } |
|
454 | ||
455 | if ($html === false) { |
|
456 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
457 | } |
|
458 | ||
459 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
460 | } |
|
461 | ||
462 | /** |
|
463 | * @param string $selector |
|
@@ 498-524 (lines=27) @@ | ||
495 | * |
|
496 | * @return XmlDomParser |
|
497 | */ |
|
498 | public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
499 | { |
|
500 | if ( |
|
501 | !\preg_match("/^https?:\/\//i", $filePath) |
|
502 | && |
|
503 | !\file_exists($filePath) |
|
504 | ) { |
|
505 | throw new \RuntimeException("File ${filePath} not found"); |
|
506 | } |
|
507 | ||
508 | try { |
|
509 | if (\class_exists('\voku\helper\UTF8')) { |
|
510 | /** @noinspection PhpUndefinedClassInspection */ |
|
511 | $xml = UTF8::file_get_contents($filePath); |
|
512 | } else { |
|
513 | $xml = \file_get_contents($filePath); |
|
514 | } |
|
515 | } catch (\Exception $e) { |
|
516 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
517 | } |
|
518 | ||
519 | if ($xml === false) { |
|
520 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
521 | } |
|
522 | ||
523 | return $this->loadXml($xml, $libXMLExtraOptions); |
|
524 | } |
|
525 | ||
526 | /** |
|
527 | * @param callable $callback |
@@ 754-783 (lines=30) @@ | ||
751 | * |
|
752 | * @return HtmlDomParser |
|
753 | */ |
|
754 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
755 | { |
|
756 | // reset |
|
757 | self::$domBrokenReplaceHelper = []; |
|
758 | ||
759 | if ( |
|
760 | !\preg_match("/^https?:\/\//i", $filePath) |
|
761 | && |
|
762 | !\file_exists($filePath) |
|
763 | ) { |
|
764 | throw new \RuntimeException("File ${filePath} not found"); |
|
765 | } |
|
766 | ||
767 | try { |
|
768 | if (\class_exists('\voku\helper\UTF8')) { |
|
769 | /** @noinspection PhpUndefinedClassInspection */ |
|
770 | $html = UTF8::file_get_contents($filePath); |
|
771 | } else { |
|
772 | $html = \file_get_contents($filePath); |
|
773 | } |
|
774 | } catch (\Exception $e) { |
|
775 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
776 | } |
|
777 | ||
778 | if ($html === false) { |
|
779 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
780 | } |
|
781 | ||
782 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
783 | } |
|
784 | ||
785 | /** |
|
786 | * Get the HTML as XML or plain XML if needed. |