14
14
final class Deferred implements Promise
15
15
{
16
16
private $ value ;
17
-
18
17
private $ failure ;
19
-
20
18
private $ state ;
21
-
22
19
private $ waitCallback ;
23
-
24
20
private $ onFulfilledCallbacks ;
25
-
26
21
private $ onRejectedCallbacks ;
27
22
28
23
public function __construct (callable $ waitCallback )
@@ -81,12 +76,12 @@ public function getState(): string
81
76
*/
82
77
public function resolve (ResponseInterface $ response ): void
83
78
{
84
- if (self ::PENDING !== $ this ->state ) {
79
+ if (Promise ::PENDING !== $ this ->state ) {
85
80
return ;
86
81
}
87
82
88
83
$ this ->value = $ response ;
89
- $ this ->state = self ::FULFILLED ;
84
+ $ this ->state = Promise ::FULFILLED ;
90
85
91
86
foreach ($ this ->onFulfilledCallbacks as $ onFulfilledCallback ) {
92
87
$ onFulfilledCallback ($ response );
@@ -98,12 +93,12 @@ public function resolve(ResponseInterface $response): void
98
93
*/
99
94
public function reject (Exception $ exception ): void
100
95
{
101
- if (self ::PENDING !== $ this ->state ) {
96
+ if (Promise ::PENDING !== $ this ->state ) {
102
97
return ;
103
98
}
104
99
105
100
$ this ->failure = $ exception ;
106
- $ this ->state = self ::REJECTED ;
101
+ $ this ->state = Promise ::REJECTED ;
107
102
108
103
foreach ($ this ->onRejectedCallbacks as $ onRejectedCallback ) {
109
104
$ onRejectedCallback ($ exception );
@@ -115,16 +110,16 @@ public function reject(Exception $exception): void
115
110
*/
116
111
public function wait ($ unwrap = true )
117
112
{
118
- if (self ::PENDING === $ this ->state ) {
113
+ if (Promise ::PENDING === $ this ->state ) {
119
114
$ callback = $ this ->waitCallback ;
120
115
$ callback ();
121
116
}
122
117
123
118
if (!$ unwrap ) {
124
- return ;
119
+ return null ;
125
120
}
126
121
127
- if (self ::FULFILLED === $ this ->state ) {
122
+ if (Promise ::FULFILLED === $ this ->state ) {
128
123
return $ this ->value ;
129
124
}
130
125
0 commit comments