diff --git a/app/Parser.php b/app/Parser.php index a47d729..f0c4489 100644 --- a/app/Parser.php +++ b/app/Parser.php @@ -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); - } - - if (false !== strpos($url, 'seloger.com')) { - return new SeLoger($url); - } - - if (false !== strpos($url, 'pap.fr')) { - return new Pap($url); + $parsers = Config::get('parser.parsers', []); + foreach ($parsers as $domain => $parser) { + if (false !== strpos($url, $domain)) { + return new $parser($url); + } } return null; diff --git a/config/parser.php b/config/parser.php new file mode 100644 index 0000000..e89a5a7 --- /dev/null +++ b/config/parser.php @@ -0,0 +1,13 @@ + [ + 'leboncoin.fr' => LBC::class, + 'seloger.com' => SeLoger::class, + 'pap.fr' => Pap::class, + ], +];