1 | <?php |
||
32 | abstract class BaseAdapter implements AdapterInterface |
||
33 | { |
||
34 | /** |
||
35 | * Adapter client |
||
36 | * |
||
37 | * @var \Zend\Server\Client |
||
38 | */ |
||
39 | protected $client; |
||
40 | |||
41 | /** |
||
42 | * Service name mapping |
||
43 | * |
||
44 | * @var string[] |
||
45 | */ |
||
46 | protected $map = []; |
||
47 | |||
48 | /** |
||
49 | * Constructor |
||
50 | * |
||
51 | * @param Client $client |
||
52 | * @param array $map map of service names to their aliases |
||
53 | */ |
||
54 | public function __construct(Client $client, array $map = []) |
||
55 | { |
||
56 | $this->client = $client; |
||
57 | $this->map = $map; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritDoc} |
||
62 | */ |
||
63 | public function call(string $wrappedClass, string $method, array $params = []) |
||
64 | { |
||
65 | $serviceName = $this->getServiceName($wrappedClass, $method); |
||
66 | |||
67 | if (isset($this->map[$serviceName])) { |
||
68 | $serviceName = $this->map[$serviceName]; |
||
69 | } |
||
70 | |||
71 | return $this->client->call($serviceName, $params); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get the service name will be used by the adapter |
||
76 | * |
||
77 | * @param string $wrappedClass |
||
78 | * @param string $method |
||
79 | * |
||
80 | * @return string Service name |
||
81 | */ |
||
82 | abstract protected function getServiceName(string $wrappedClass, string $method) : string; |
||
83 | } |
||
84 |