|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* * This file is part of the Tidal/WampWatch package. |
|
5
|
|
|
* * (c) 2016 Timo Michna <timomichna/yahoo.de> |
|
6
|
|
|
* * |
|
7
|
|
|
* * For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* * file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tidal\WampWatch\Adapter\React; |
|
13
|
|
|
|
|
14
|
|
|
use Tidal\WampWatch\Async\DeferredInterface; |
|
15
|
|
|
use Tidal\WampWatch\Async\PromiseInterface; |
|
16
|
|
|
|
|
17
|
|
|
use React\Promise\Deferred; |
|
18
|
|
|
|
|
19
|
|
|
class DeferredAdapter implements DeferredInterface |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Deferred |
|
24
|
|
|
*/ |
|
25
|
|
|
private $adaptee; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string fully qualified class name of the promise to create. |
|
29
|
|
|
*/ |
|
30
|
|
|
private $promiseClass = PromiseAdapter::class; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* DeferredAdapter constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \React\Promise\Deferred $adaptee |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(Deferred $adaptee) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->setAdaptee($adaptee); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param \React\Promise\Deferred $adaptee |
|
44
|
|
|
*/ |
|
45
|
|
|
private function setAdaptee(Deferred $adaptee) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->adaptee = $adaptee; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return mixed |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getAdaptee() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->adaptee; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $promiseClass |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setPromiseClass($promiseClass) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->promiseClass = $promiseClass; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getPromiseClass() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->promiseClass; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return PromiseInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
public function promise() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->createPromise(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param null $value |
|
84
|
|
|
*/ |
|
85
|
|
|
public function resolve($value = null) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->adaptee->resolve($value); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param null $reason |
|
92
|
|
|
*/ |
|
93
|
|
|
public function reject($reason = null) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->adaptee->reject($reason); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param null $update |
|
100
|
|
|
*/ |
|
101
|
|
|
public function notify($update = null) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->adaptee->notify($update); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return PromiseInterface |
|
108
|
|
|
*/ |
|
109
|
|
|
private function createPromise() |
|
110
|
|
|
{ |
|
111
|
|
|
return new $this->promiseClass( |
|
112
|
|
|
$this->adaptee->promise() |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |