1 | <?php |
||
14 | abstract class BaseAdapter implements AdapterInterface |
||
15 | { |
||
16 | protected Client $client; |
||
|
|||
17 | |||
18 | /** |
||
19 | * Service name mapping |
||
20 | * |
||
21 | * @var string[] |
||
22 | */ |
||
23 | protected array $map = []; |
||
24 | |||
25 | /** |
||
26 | * Constructor |
||
27 | * |
||
28 | * @param string[] $map map of service names to their aliases |
||
29 | */ |
||
30 | public function __construct(Client $client, array $map = []) |
||
31 | { |
||
32 | $this->client = $client; |
||
33 | $this->map = $map; |
||
34 | } |
||
35 | |||
36 | 5 | /** |
|
37 | * {@inheritDoc} |
||
38 | 5 | * |
|
39 | 5 | * @param mixed[] $params |
|
40 | 5 | */ |
|
41 | public function call(string $wrappedClass, string $method, array $params = []) |
||
42 | { |
||
43 | $serviceName = $this->getServiceName($wrappedClass, $method); |
||
44 | |||
45 | if (array_key_exists($serviceName, $this->map)) { |
||
46 | $serviceName = $this->map[$serviceName]; |
||
47 | 2 | } |
|
48 | |||
49 | 2 | return $this->client->call($serviceName, $params); |
|
50 | } |
||
51 | 2 | ||
52 | 1 | /** |
|
53 | * Get the service name will be used by the adapter |
||
54 | */ |
||
55 | 2 | abstract protected function getServiceName(string $wrappedClass, string $method) : string; |
|
56 | } |
||
57 |