1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types=1); |
20
|
|
|
|
21
|
|
|
namespace ProxyManager\Factory\RemoteObject\Adapter; |
22
|
|
|
|
23
|
|
|
use ProxyManager\Factory\RemoteObject\AdapterInterface; |
24
|
|
|
use Zend\Server\Client; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Remote Object base adapter |
28
|
|
|
* |
29
|
|
|
* @author Vincent Blanchon <[email protected]> |
30
|
|
|
* @license MIT |
31
|
|
|
*/ |
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
|
|
|
|