53 lines
1.0 KiB
PHP
53 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App;
|
||
|
|
||
|
use App\Parser\LBC;
|
||
|
use App\Parser\Pap;
|
||
|
use App\Parser\SeLoger;
|
||
|
|
||
|
abstract class Parser
|
||
|
{
|
||
|
protected $client;
|
||
|
protected $url;
|
||
|
|
||
|
protected function __construct($url)
|
||
|
{
|
||
|
$this->url = $url;
|
||
|
$this->client = new \GuzzleHttp\Client([
|
||
|
'timeout' => 60,
|
||
|
'verify' => false,
|
||
|
'headers' => [
|
||
|
'user-agent' => 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; D5803 Build/MOB30M.Z1)',
|
||
|
],
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param string $url
|
||
|
*
|
||
|
* @return \App\Parser|null
|
||
|
*/
|
||
|
public static function factory(string $url)
|
||
|
{
|
||
|
if (false !== strpos($url, 'leboncoin.fr')) {
|
||
|
return new LBC($url);
|
||
|
}
|
||
|
|
||
|
if (false !== strpos($url, 'seloger.com')) {
|
||
|
return new SeLoger($url);
|
||
|
}
|
||
|
|
||
|
if (false !== strpos($url, 'pap.fr')) {
|
||
|
return new Pap($url);
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return \App\ParsedHome
|
||
|
*/
|
||
|
abstract public function parse(): ParsedHome;
|
||
|
}
|