🔧 Place les différents parser en fichier de config

This commit is contained in:
Clement 2020-07-23 14:55:00 +02:00
parent 6119e6c6d7
commit 7bed68c4eb
2 changed files with 20 additions and 11 deletions

View File

@ -5,6 +5,7 @@ namespace App;
use App\Parser\LBC;
use App\Parser\Pap;
use App\Parser\SeLoger;
use Illuminate\Support\Facades\Config;
abstract class Parser
{
@ -28,18 +29,13 @@ abstract class Parser
*
* @return \App\Parser|null
*/
public static function factory(string $url)
public static function factory(string $url): ?Parser
{
if (false !== strpos($url, 'leboncoin.fr')) {
return new LBC($url);
$parsers = Config::get('parser.parsers', []);
foreach ($parsers as $domain => $parser) {
if (false !== strpos($url, $domain)) {
return new $parser($url);
}
if (false !== strpos($url, 'seloger.com')) {
return new SeLoger($url);
}
if (false !== strpos($url, 'pap.fr')) {
return new Pap($url);
}
return null;

13
config/parser.php Normal file
View File

@ -0,0 +1,13 @@
<?php
use App\Parser\LBC;
use App\Parser\Pap;
use App\Parser\SeLoger;
return [
'parsers' => [
'leboncoin.fr' => LBC::class,
'seloger.com' => SeLoger::class,
'pap.fr' => Pap::class,
],
];