From 7bed68c4eb2f14d35a4c946234c6430d80214846 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 23 Jul 2020 14:55:00 +0200 Subject: [PATCH] =?UTF-8?q?:wrench:=20Place=20les=20diff=C3=A9rents=20pars?= =?UTF-8?q?er=20en=20fichier=20de=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Parser.php | 18 +++++++----------- config/parser.php | 13 +++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 config/parser.php 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, + ], +];