🔧 Place les différents parser en fichier de config
This commit is contained in:
		| @@ -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
									
								
							
							
						
						
									
										13
									
								
								config/parser.php
									
									
									
									
									
										Normal 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, | ||||
|     ], | ||||
| ]; | ||||
		Reference in New Issue
	
	Block a user