| @@ 691-720 (lines=30) @@ | ||
| 688 | * |
|
| 689 | * @return HtmlDomParser |
|
| 690 | */ |
|
| 691 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 692 | { |
|
| 693 | // reset |
|
| 694 | self::$domBrokenReplaceHelper = []; |
|
| 695 | ||
| 696 | if ( |
|
| 697 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 698 | && |
|
| 699 | !\file_exists($filePath) |
|
| 700 | ) { |
|
| 701 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 702 | } |
|
| 703 | ||
| 704 | try { |
|
| 705 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 706 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 707 | $html = UTF8::file_get_contents($filePath); |
|
| 708 | } else { |
|
| 709 | $html = \file_get_contents($filePath); |
|
| 710 | } |
|
| 711 | } catch (\Exception $e) { |
|
| 712 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 713 | } |
|
| 714 | ||
| 715 | if ($html === false) { |
|
| 716 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 717 | } |
|
| 718 | ||
| 719 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 720 | } |
|
| 721 | ||
| 722 | /** |
|
| 723 | * Get the HTML as XML or plain XML if needed. |
|
| @@ 432-458 (lines=27) @@ | ||
| 429 | * |
|
| 430 | * @return XmlDomParser |
|
| 431 | */ |
|
| 432 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 433 | { |
|
| 434 | if ( |
|
| 435 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 436 | && |
|
| 437 | !\file_exists($filePath) |
|
| 438 | ) { |
|
| 439 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 440 | } |
|
| 441 | ||
| 442 | try { |
|
| 443 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 444 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 445 | $html = UTF8::file_get_contents($filePath); |
|
| 446 | } else { |
|
| 447 | $html = \file_get_contents($filePath); |
|
| 448 | } |
|
| 449 | } catch (\Exception $e) { |
|
| 450 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 451 | } |
|
| 452 | ||
| 453 | if ($html === false) { |
|
| 454 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 455 | } |
|
| 456 | ||
| 457 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 458 | } |
|
| 459 | ||
| 460 | /** |
|
| 461 | * @param string $selector |
|
| @@ 496-522 (lines=27) @@ | ||
| 493 | * |
|
| 494 | * @return XmlDomParser |
|
| 495 | */ |
|
| 496 | public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
| 497 | { |
|
| 498 | if ( |
|
| 499 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 500 | && |
|
| 501 | !\file_exists($filePath) |
|
| 502 | ) { |
|
| 503 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 504 | } |
|
| 505 | ||
| 506 | try { |
|
| 507 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 508 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 509 | $xml = UTF8::file_get_contents($filePath); |
|
| 510 | } else { |
|
| 511 | $xml = \file_get_contents($filePath); |
|
| 512 | } |
|
| 513 | } catch (\Exception $e) { |
|
| 514 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 515 | } |
|
| 516 | ||
| 517 | if ($xml === false) { |
|
| 518 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 519 | } |
|
| 520 | ||
| 521 | return $this->loadXml($xml, $libXMLExtraOptions); |
|
| 522 | } |
|
| 523 | ||
| 524 | /** |
|
| 525 | * @param callable $callback |
|