| @@ 635-661 (lines=27) @@ | ||
| 632 | * |
|
| 633 | * @return HtmlDomParser |
|
| 634 | */ |
|
| 635 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 636 | { |
|
| 637 | if ( |
|
| 638 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 639 | && |
|
| 640 | !\file_exists($filePath) |
|
| 641 | ) { |
|
| 642 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 643 | } |
|
| 644 | ||
| 645 | try { |
|
| 646 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 647 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 648 | $html = UTF8::file_get_contents($filePath); |
|
| 649 | } else { |
|
| 650 | $html = \file_get_contents($filePath); |
|
| 651 | } |
|
| 652 | } catch (\Exception $e) { |
|
| 653 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 654 | } |
|
| 655 | ||
| 656 | if ($html === false) { |
|
| 657 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 658 | } |
|
| 659 | ||
| 660 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 661 | } |
|
| 662 | ||
| 663 | /** |
|
| 664 | * @param string $html |
|
| @@ 395-421 (lines=27) @@ | ||
| 392 | * |
|
| 393 | * @return XmlDomParser |
|
| 394 | */ |
|
| 395 | public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface |
|
| 396 | { |
|
| 397 | if ( |
|
| 398 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 399 | && |
|
| 400 | !\file_exists($filePath) |
|
| 401 | ) { |
|
| 402 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 403 | } |
|
| 404 | ||
| 405 | try { |
|
| 406 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 407 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 408 | $html = UTF8::file_get_contents($filePath); |
|
| 409 | } else { |
|
| 410 | $html = \file_get_contents($filePath); |
|
| 411 | } |
|
| 412 | } catch (\Exception $e) { |
|
| 413 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 414 | } |
|
| 415 | ||
| 416 | if ($html === false) { |
|
| 417 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 418 | } |
|
| 419 | ||
| 420 | return $this->loadHtml($html, $libXMLExtraOptions); |
|
| 421 | } |
|
| 422 | ||
| 423 | /** |
|
| 424 | * @param string $selector |
|
| @@ 459-485 (lines=27) @@ | ||
| 456 | * |
|
| 457 | * @return XmlDomParser |
|
| 458 | */ |
|
| 459 | public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self |
|
| 460 | { |
|
| 461 | if ( |
|
| 462 | !\preg_match("/^https?:\/\//i", $filePath) |
|
| 463 | && |
|
| 464 | !\file_exists($filePath) |
|
| 465 | ) { |
|
| 466 | throw new \RuntimeException("File ${filePath} not found"); |
|
| 467 | } |
|
| 468 | ||
| 469 | try { |
|
| 470 | if (\class_exists('\voku\helper\UTF8')) { |
|
| 471 | /** @noinspection PhpUndefinedClassInspection */ |
|
| 472 | $xml = UTF8::file_get_contents($filePath); |
|
| 473 | } else { |
|
| 474 | $xml = \file_get_contents($filePath); |
|
| 475 | } |
|
| 476 | } catch (\Exception $e) { |
|
| 477 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 478 | } |
|
| 479 | ||
| 480 | if ($xml === false) { |
|
| 481 | throw new \RuntimeException("Could not load file ${filePath}"); |
|
| 482 | } |
|
| 483 | ||
| 484 | return $this->loadXml($xml, $libXMLExtraOptions); |
|
| 485 | } |
|
| 486 | ||
| 487 | /** |
|
| 488 | * @param callable $callback |
|