@@ 733-762 (lines=30) @@ | ||
730 | * |
|
731 | * @return HtmlDomParser |
|
732 | */ |
|
733 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
734 | { |
|
735 | // reset |
|
736 | self::$domBrokenReplaceHelper = []; |
|
737 | ||
738 | if ( |
|
739 | !\preg_match("/^https?:\/\//i", $filePath) |
|
740 | && |
|
741 | !\file_exists($filePath) |
|
742 | ) { |
|
743 | throw new \RuntimeException("File ${filePath} not found"); |
|
744 | } |
|
745 | ||
746 | try { |
|
747 | if (\class_exists('\voku\helper\UTF8')) { |
|
748 | /** @noinspection PhpUndefinedClassInspection */ |
|
749 | $html = UTF8::file_get_contents($filePath); |
|
750 | } else { |
|
751 | $html = \file_get_contents($filePath); |
|
752 | } |
|
753 | } catch (\Exception $e) { |
|
754 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
755 | } |
|
756 | ||
757 | if ($html === false) { |
|
758 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
759 | } |
|
760 | ||
761 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
762 | } |
|
763 | ||
764 | /** |
|
765 | * Get the HTML as XML or plain XML if needed. |
@@ 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 |