|
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\Behavior\Async\MakesPromisesTrait; |
|
16
|
|
|
use React\Promise\Deferred; |
|
17
|
|
|
|
|
18
|
|
|
class DeferredAdapter implements DeferredInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use MakesPromisesTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Deferred |
|
24
|
|
|
*/ |
|
25
|
|
|
private $adaptee; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* DeferredAdapter constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \React\Promise\Deferred $adaptee |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(Deferred $adaptee) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setAdaptee($adaptee); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param \React\Promise\Deferred $adaptee |
|
39
|
|
|
*/ |
|
40
|
|
|
private function setAdaptee(Deferred $adaptee) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->adaptee = $adaptee; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return mixed |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getAdaptee() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->adaptee; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return PromiseAdapter |
|
55
|
|
|
*/ |
|
56
|
|
|
public function promise() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->makePromise(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param null $value |
|
63
|
|
|
*/ |
|
64
|
|
|
public function resolve($value = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->adaptee->resolve($value); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param null $reason |
|
71
|
|
|
*/ |
|
72
|
|
|
public function reject($reason = null) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->adaptee->reject($reason); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param null $update |
|
79
|
|
|
*/ |
|
80
|
|
|
public function notify($update = null) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->adaptee->notify($update); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function makePromise() |
|
86
|
|
|
{ |
|
87
|
|
|
if (!isset($this->promiseFactory)) { |
|
88
|
|
|
$this->promiseFactory = new PromiseFactory(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $this->getPromiseFactory()->createFromAdaptee( |
|
92
|
|
|
$this->adaptee->promise() |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|