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; |
22
|
|
|
|
23
|
|
|
use ProxyManager\Configuration; |
24
|
|
|
use ProxyManager\Factory\RemoteObject\AdapterInterface; |
25
|
|
|
use ProxyManager\Proxy\RemoteObjectInterface; |
26
|
|
|
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; |
27
|
|
|
use ProxyManager\ProxyGenerator\RemoteObjectGenerator; |
28
|
|
|
use ProxyManager\Signature\Exception\InvalidSignatureException; |
29
|
|
|
use ProxyManager\Signature\Exception\MissingSignatureException; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Factory responsible of producing remote proxy objects |
33
|
|
|
* |
34
|
|
|
* @author Vincent Blanchon <[email protected]> |
35
|
|
|
* @license MIT |
36
|
|
|
*/ |
37
|
|
|
class RemoteObjectFactory extends AbstractBaseFactory |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @var AdapterInterface |
41
|
|
|
*/ |
42
|
|
|
protected $adapter; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \ProxyManager\ProxyGenerator\RemoteObjectGenerator|null |
46
|
|
|
*/ |
47
|
|
|
private $generator; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritDoc} |
51
|
|
|
* |
52
|
|
|
* @param AdapterInterface $adapter |
53
|
2 |
|
* @param Configuration $configuration |
54
|
|
|
*/ |
55
|
2 |
|
public function __construct(AdapterInterface $adapter, Configuration $configuration = null) |
56
|
|
|
{ |
57
|
2 |
|
parent::__construct($configuration); |
58
|
2 |
|
|
59
|
|
|
$this->adapter = $adapter; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string|object $instanceOrClassName |
64
|
|
|
* |
65
|
2 |
|
* @return RemoteObjectInterface |
66
|
|
|
* |
67
|
2 |
|
* @throws InvalidSignatureException |
68
|
2 |
|
* @throws MissingSignatureException |
69
|
|
|
* @throws \OutOfBoundsException |
70
|
|
|
*/ |
71
|
2 |
|
public function createProxy($instanceOrClassName) : RemoteObjectInterface |
72
|
|
|
{ |
73
|
|
|
$proxyClassName = $this->generateProxy( |
74
|
|
|
is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName |
75
|
|
|
); |
76
|
|
|
|
77
|
1 |
|
return $proxyClassName::staticProxyConstructor($this->adapter); |
78
|
|
|
} |
79
|
1 |
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritDoc} |
82
|
|
|
*/ |
83
|
|
|
protected function getGenerator() : ProxyGeneratorInterface |
84
|
|
|
{ |
85
|
|
|
return $this->generator ?: $this->generator = new RemoteObjectGenerator(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|