|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\UrlBuilder; |
|
4
|
|
|
|
|
5
|
|
|
use App\Enum\Provider; |
|
6
|
|
|
use App\Exception\UrlBuilderNotFoundException; |
|
7
|
|
|
use Psr\Container\ContainerInterface; |
|
8
|
|
|
use Symfony\Contracts\Service\ServiceSubscriberInterface; |
|
9
|
|
|
|
|
10
|
|
|
class UrlBuilderLocator implements ServiceSubscriberInterface |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct( |
|
13
|
|
|
private ContainerInterface $locator |
|
14
|
|
|
) {} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritDoc} |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public static function getSubscribedServices(): array |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
1 |
|
Provider::BIENICI => BienIciUrlBuilder::class, |
|
23
|
|
|
Provider::LEBONCOIN => LeBonCoinUrlBuilder::class, |
|
24
|
|
|
Provider::LOGIC_IMMO => LogicImmoUrlBuilder::class, |
|
25
|
|
|
Provider::LOGIC_IMMO_NEUF => LogicImmoNeufUrlBuilder::class, |
|
26
|
|
|
Provider::OUESTFRANCE_IMMO => OuestFranceImmoUrlBuilder::class, |
|
27
|
|
|
Provider::OUESTFRANCE_IMMO_NEUF => OuestFranceImmoNeufUrlBuilder::class, |
|
28
|
|
|
Provider::PAP => PapUrlBuilder::class, |
|
29
|
|
|
Provider::PAP_NEUF => PapNeufUrlBuilder::class, |
|
30
|
|
|
Provider::SELOGER => SeLogerUrlBuilder::class, |
|
31
|
|
|
Provider::SELOGER_NEUF => SeLogerNeufUrlBuilder::class, |
|
32
|
|
|
Provider::SUPERIMMO => SuperimmoUrlBuilder::class, |
|
33
|
|
|
Provider::SUPERIMMO_NEUF => SuperimmoNeufUrlBuilder::class |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @throws UrlBuilderNotFoundException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function get(string $provider): UrlBuilderInterface |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$this->locator->has($provider)) { |
|
43
|
|
|
throw new UrlBuilderNotFoundException('No URL builder found for the provider: ' . $provider); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $this->locator->get($provider); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|