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.

52 lines
1.0 KiB

  1. <?php
  2. namespace App;
  3. use App\Parser\LBC;
  4. use App\Parser\Pap;
  5. use App\Parser\SeLoger;
  6. abstract class Parser
  7. {
  8. protected $client;
  9. protected $url;
  10. protected function __construct($url)
  11. {
  12. $this->url = $url;
  13. $this->client = new \GuzzleHttp\Client([
  14. 'timeout' => 60,
  15. 'verify' => false,
  16. 'headers' => [
  17. 'user-agent' => 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; D5803 Build/MOB30M.Z1)',
  18. ],
  19. ]);
  20. }
  21. /**
  22. * @param string $url
  23. *
  24. * @return \App\Parser|null
  25. */
  26. public static function factory(string $url)
  27. {
  28. if (false !== strpos($url, 'leboncoin.fr')) {
  29. return new LBC($url);
  30. }
  31. if (false !== strpos($url, 'seloger.com')) {
  32. return new SeLoger($url);
  33. }
  34. if (false !== strpos($url, 'pap.fr')) {
  35. return new Pap($url);
  36. }
  37. return null;
  38. }
  39. /**
  40. * @return \App\ParsedHome
  41. */
  42. abstract public function parse(): ParsedHome;
  43. }