You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
732 B

  1. <?php
  2. namespace p3k\XRay;
  3. use p3k\XRay\Formats;
  4. class Parser {
  5. private $http;
  6. public function __construct($http) {
  7. $this->http = $http;
  8. }
  9. public function parse($body, $url, $opts=[]) {
  10. if(isset($opts['timeout']))
  11. $this->http->set_timeout($opts['timeout']);
  12. if(isset($opts['max_redirects']))
  13. $this->http->set_max_redirects($opts['max_redirects']);
  14. // Check if the URL matches a special parser
  15. if(Formats\Instagram::matches($url)) {
  16. return Formats\Instagram::parse($this->http, $body, $url);
  17. }
  18. if(Formats\GitHub::matches($url)) {
  19. return Formats\GitHub::parse($body, $url);
  20. }
  21. return [
  22. 'data' => [
  23. 'type' => 'unknown'
  24. ]
  25. ];
  26. }
  27. }