MyHomeCollection/app/Parser.php
Shikiryu fdcc1de825 Ajoute le parser Ouest-France (#13)
Fix #11

Co-authored-by: Clement <clement@desmidt.fr>
Reviewed-on: #13
2020-07-27 12:52:46 +02:00

47 lines
977 B
PHP

<?php
namespace App;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Config;
abstract class Parser
{
protected $client;
protected $url;
protected function __construct($url)
{
$this->url = $url;
$this->client = new 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): ?Parser
{
$parsers = Config::get('parser.parsers', []);
foreach ($parsers as $domain => $parser) {
if (false !== strpos($url, $domain)) {
return new $parser($url);
}
}
return null;
}
/**
* @return \App\ParsedHome
*/
abstract public function parse(): ParsedHome;
}