Browse code

removed Telnyx Plivo Twilio Flowroute appinfo/info.xml appinfo/signature.json README.md lib/Controller/AuthorApiController.php

DoubleBastionAdmin authored on 20/08/2022 16:26:33
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,253 +0,0 @@
1
-<?php
2
-
3
-namespace GuzzleHttp\Promise;
4
-
5
-/**
6
- * Represents a promise that iterates over many promises and invokes
7
- * side-effect functions in the process.
8
- */
9
-class EachPromise implements PromisorInterface
10
-{
11
-    private $pending = [];
12
-
13
-    /** @var \Iterator|null */
14
-    private $iterable;
15
-
16
-    /** @var callable|int|null */
17
-    private $concurrency;
18
-
19
-    /** @var callable|null */
20
-    private $onFulfilled;
21
-
22
-    /** @var callable|null */
23
-    private $onRejected;
24
-
25
-    /** @var Promise|null */
26
-    private $aggregate;
27
-
28
-    /** @var bool|null */
29
-    private $mutex;
30
-
31
-    /**
32
-     * Configuration hash can include the following key value pairs:
33
-     *
34
-     * - fulfilled: (callable) Invoked when a promise fulfills. The function
35
-     *   is invoked with three arguments: the fulfillment value, the index
36
-     *   position from the iterable list of the promise, and the aggregate
37
-     *   promise that manages all of the promises. The aggregate promise may
38
-     *   be resolved from within the callback to short-circuit the promise.
39
-     * - rejected: (callable) Invoked when a promise is rejected. The
40
-     *   function is invoked with three arguments: the rejection reason, the
41
-     *   index position from the iterable list of the promise, and the
42
-     *   aggregate promise that manages all of the promises. The aggregate
43
-     *   promise may be resolved from within the callback to short-circuit
44
-     *   the promise.
45
-     * - concurrency: (integer) Pass this configuration option to limit the
46
-     *   allowed number of outstanding concurrently executing promises,
47
-     *   creating a capped pool of promises. There is no limit by default.
48
-     *
49
-     * @param mixed $iterable Promises or values to iterate.
50
-     * @param array $config   Configuration options
51
-     */
52
-    public function __construct($iterable, array $config = [])
53
-    {
54
-        $this->iterable = Create::iterFor($iterable);
55
-
56
-        if (isset($config['concurrency'])) {
57
-            $this->concurrency = $config['concurrency'];
58
-        }
59
-
60
-        if (isset($config['fulfilled'])) {
61
-            $this->onFulfilled = $config['fulfilled'];
62
-        }
63
-
64
-        if (isset($config['rejected'])) {
65
-            $this->onRejected = $config['rejected'];
66
-        }
67
-    }
68
-
69
-    /** @psalm-suppress InvalidNullableReturnType */
70
-    public function promise()
71
-    {
72
-        if ($this->aggregate) {
73
-            return $this->aggregate;
74
-        }
75
-
76
-        try {
77
-            $this->createPromise();
78
-            /** @psalm-assert Promise $this->aggregate */
79
-            $this->iterable->rewind();
80
-            if (!$this->checkIfFinished()) {
81
-                $this->refillPending();
82
-            }
83
-        } catch (\Throwable $e) {
84
-            /**
85
-             * @psalm-suppress NullReference
86
-             * @phpstan-ignore-next-line
87
-             */
88
-            $this->aggregate->reject($e);
89
-        } catch (\Exception $e) {
90
-            /**
91
-             * @psalm-suppress NullReference
92
-             * @phpstan-ignore-next-line
93
-             */
94
-            $this->aggregate->reject($e);
95
-        }
96
-
97
-        /**
98
-         * @psalm-suppress NullableReturnStatement
99
-         * @phpstan-ignore-next-line
100
-         */
101
-        return $this->aggregate;
102
-    }
103
-
104
-    private function createPromise()
105
-    {
106
-        $this->mutex = false;
107
-        $this->aggregate = new Promise(function () {
108
-            reset($this->pending);
109
-            // Consume a potentially fluctuating list of promises while
110
-            // ensuring that indexes are maintained (precluding array_shift).
111
-            while ($promise = current($this->pending)) {
112
-                next($this->pending);
113
-                $promise->wait();
114
-                if (Is::settled($this->aggregate)) {
115
-                    return;
116
-                }
117
-            }
118
-        });
119
-
120
-        // Clear the references when the promise is resolved.
121
-        $clearFn = function () {
122
-            $this->iterable = $this->concurrency = $this->pending = null;
123
-            $this->onFulfilled = $this->onRejected = null;
124
-        };
125
-
126
-        $this->aggregate->then($clearFn, $clearFn);
127
-    }
128
-
129
-    private function refillPending()
130
-    {
131
-        if (!$this->concurrency) {
132
-            // Add all pending promises.
133
-            while ($this->addPending() && $this->advanceIterator());
134
-            return;
135
-        }
136
-
137
-        // Add only up to N pending promises.
138
-        $concurrency = is_callable($this->concurrency)
139
-            ? call_user_func($this->concurrency, count($this->pending))
140
-            : $this->concurrency;
141
-        $concurrency = max($concurrency - count($this->pending), 0);
142
-        // Concurrency may be set to 0 to disallow new promises.
143
-        if (!$concurrency) {
144
-            return;
145
-        }
146
-        // Add the first pending promise.
147
-        $this->addPending();
148
-        // Note this is special handling for concurrency=1 so that we do
149
-        // not advance the iterator after adding the first promise. This
150
-        // helps work around issues with generators that might not have the
151
-        // next value to yield until promise callbacks are called.
152
-        while (--$concurrency
153
-            && $this->advanceIterator()
154
-            && $this->addPending());
155
-    }
156
-
157
-    private function addPending()
158
-    {
159
-        if (!$this->iterable || !$this->iterable->valid()) {
160
-            return false;
161
-        }
162
-
163
-        $promise = Create::promiseFor($this->iterable->current());
164
-        $key = $this->iterable->key();
165
-
166
-        // Iterable keys may not be unique, so we add the promises at the end
167
-        // of the pending array and retrieve the array index being used
168
-        $this->pending[] = null;
169
-        end($this->pending);
170
-        $idx = key($this->pending);
171
-
172
-        $this->pending[$idx] = $promise->then(
173
-            function ($value) use ($idx, $key) {
174
-                if ($this->onFulfilled) {
175
-                    call_user_func(
176
-                        $this->onFulfilled,
177
-                        $value,
178
-                        $key,
179
-                        $this->aggregate
180
-                    );
181
-                }
182
-                $this->step($idx);
183
-            },
184
-            function ($reason) use ($idx, $key) {
185
-                if ($this->onRejected) {
186
-                    call_user_func(
187
-                        $this->onRejected,
188
-                        $reason,
189
-                        $key,
190
-                        $this->aggregate
191
-                    );
192
-                }
193
-                $this->step($idx);
194
-            }
195
-        );
196
-
197
-        return true;
198
-    }
199
-
200
-    private function advanceIterator()
201
-    {
202
-        // Place a lock on the iterator so that we ensure to not recurse,
203
-        // preventing fatal generator errors.
204
-        if ($this->mutex) {
205
-            return false;
206
-        }
207
-
208
-        $this->mutex = true;
209
-
210
-        try {
211
-            $this->iterable->next();
212
-            $this->mutex = false;
213
-            return true;
214
-        } catch (\Throwable $e) {
215
-            $this->aggregate->reject($e);
216
-            $this->mutex = false;
217
-            return false;
218
-        } catch (\Exception $e) {
219
-            $this->aggregate->reject($e);
220
-            $this->mutex = false;
221
-            return false;
222
-        }
223
-    }
224
-
225
-    private function step($idx)
226
-    {
227
-        // If the promise was already resolved, then ignore this step.
228
-        if (Is::settled($this->aggregate)) {
229
-            return;
230
-        }
231
-
232
-        unset($this->pending[$idx]);
233
-
234
-        // Only refill pending promises if we are not locked, preventing the
235
-        // EachPromise to recursively invoke the provided iterator, which
236
-        // cause a fatal error: "Cannot resume an already running generator"
237
-        if ($this->advanceIterator() && !$this->checkIfFinished()) {
238
-            // Add more pending promises if possible.
239
-            $this->refillPending();
240
-        }
241
-    }
242
-
243
-    private function checkIfFinished()
244
-    {
245
-        if (!$this->pending && !$this->iterable->valid()) {
246
-            // Resolve the promise if there's nothing left to do.
247
-            $this->aggregate->resolve(null);
248
-            return true;
249
-        }
250
-
251
-        return false;
252
-    }
253
-}
Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:47:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,253 @@
1
+<?php
2
+
3
+namespace GuzzleHttp\Promise;
4
+
5
+/**
6
+ * Represents a promise that iterates over many promises and invokes
7
+ * side-effect functions in the process.
8
+ */
9
+class EachPromise implements PromisorInterface
10
+{
11
+    private $pending = [];
12
+
13
+    /** @var \Iterator|null */
14
+    private $iterable;
15
+
16
+    /** @var callable|int|null */
17
+    private $concurrency;
18
+
19
+    /** @var callable|null */
20
+    private $onFulfilled;
21
+
22
+    /** @var callable|null */
23
+    private $onRejected;
24
+
25
+    /** @var Promise|null */
26
+    private $aggregate;
27
+
28
+    /** @var bool|null */
29
+    private $mutex;
30
+
31
+    /**
32
+     * Configuration hash can include the following key value pairs:
33
+     *
34
+     * - fulfilled: (callable) Invoked when a promise fulfills. The function
35
+     *   is invoked with three arguments: the fulfillment value, the index
36
+     *   position from the iterable list of the promise, and the aggregate
37
+     *   promise that manages all of the promises. The aggregate promise may
38
+     *   be resolved from within the callback to short-circuit the promise.
39
+     * - rejected: (callable) Invoked when a promise is rejected. The
40
+     *   function is invoked with three arguments: the rejection reason, the
41
+     *   index position from the iterable list of the promise, and the
42
+     *   aggregate promise that manages all of the promises. The aggregate
43
+     *   promise may be resolved from within the callback to short-circuit
44
+     *   the promise.
45
+     * - concurrency: (integer) Pass this configuration option to limit the
46
+     *   allowed number of outstanding concurrently executing promises,
47
+     *   creating a capped pool of promises. There is no limit by default.
48
+     *
49
+     * @param mixed $iterable Promises or values to iterate.
50
+     * @param array $config   Configuration options
51
+     */
52
+    public function __construct($iterable, array $config = [])
53
+    {
54
+        $this->iterable = Create::iterFor($iterable);
55
+
56
+        if (isset($config['concurrency'])) {
57
+            $this->concurrency = $config['concurrency'];
58
+        }
59
+
60
+        if (isset($config['fulfilled'])) {
61
+            $this->onFulfilled = $config['fulfilled'];
62
+        }
63
+
64
+        if (isset($config['rejected'])) {
65
+            $this->onRejected = $config['rejected'];
66
+        }
67
+    }
68
+
69
+    /** @psalm-suppress InvalidNullableReturnType */
70
+    public function promise()
71
+    {
72
+        if ($this->aggregate) {
73
+            return $this->aggregate;
74
+        }
75
+
76
+        try {
77
+            $this->createPromise();
78
+            /** @psalm-assert Promise $this->aggregate */
79
+            $this->iterable->rewind();
80
+            if (!$this->checkIfFinished()) {
81
+                $this->refillPending();
82
+            }
83
+        } catch (\Throwable $e) {
84
+            /**
85
+             * @psalm-suppress NullReference
86
+             * @phpstan-ignore-next-line
87
+             */
88
+            $this->aggregate->reject($e);
89
+        } catch (\Exception $e) {
90
+            /**
91
+             * @psalm-suppress NullReference
92
+             * @phpstan-ignore-next-line
93
+             */
94
+            $this->aggregate->reject($e);
95
+        }
96
+
97
+        /**
98
+         * @psalm-suppress NullableReturnStatement
99
+         * @phpstan-ignore-next-line
100
+         */
101
+        return $this->aggregate;
102
+    }
103
+
104
+    private function createPromise()
105
+    {
106
+        $this->mutex = false;
107
+        $this->aggregate = new Promise(function () {
108
+            reset($this->pending);
109
+            // Consume a potentially fluctuating list of promises while
110
+            // ensuring that indexes are maintained (precluding array_shift).
111
+            while ($promise = current($this->pending)) {
112
+                next($this->pending);
113
+                $promise->wait();
114
+                if (Is::settled($this->aggregate)) {
115
+                    return;
116
+                }
117
+            }
118
+        });
119
+
120
+        // Clear the references when the promise is resolved.
121
+        $clearFn = function () {
122
+            $this->iterable = $this->concurrency = $this->pending = null;
123
+            $this->onFulfilled = $this->onRejected = null;
124
+        };
125
+
126
+        $this->aggregate->then($clearFn, $clearFn);
127
+    }
128
+
129
+    private function refillPending()
130
+    {
131
+        if (!$this->concurrency) {
132
+            // Add all pending promises.
133
+            while ($this->addPending() && $this->advanceIterator());
134
+            return;
135
+        }
136
+
137
+        // Add only up to N pending promises.
138
+        $concurrency = is_callable($this->concurrency)
139
+            ? call_user_func($this->concurrency, count($this->pending))
140
+            : $this->concurrency;
141
+        $concurrency = max($concurrency - count($this->pending), 0);
142
+        // Concurrency may be set to 0 to disallow new promises.
143
+        if (!$concurrency) {
144
+            return;
145
+        }
146
+        // Add the first pending promise.
147
+        $this->addPending();
148
+        // Note this is special handling for concurrency=1 so that we do
149
+        // not advance the iterator after adding the first promise. This
150
+        // helps work around issues with generators that might not have the
151
+        // next value to yield until promise callbacks are called.
152
+        while (--$concurrency
153
+            && $this->advanceIterator()
154
+            && $this->addPending());
155
+    }
156
+
157
+    private function addPending()
158
+    {
159
+        if (!$this->iterable || !$this->iterable->valid()) {
160
+            return false;
161
+        }
162
+
163
+        $promise = Create::promiseFor($this->iterable->current());
164
+        $key = $this->iterable->key();
165
+
166
+        // Iterable keys may not be unique, so we add the promises at the end
167
+        // of the pending array and retrieve the array index being used
168
+        $this->pending[] = null;
169
+        end($this->pending);
170
+        $idx = key($this->pending);
171
+
172
+        $this->pending[$idx] = $promise->then(
173
+            function ($value) use ($idx, $key) {
174
+                if ($this->onFulfilled) {
175
+                    call_user_func(
176
+                        $this->onFulfilled,
177
+                        $value,
178
+                        $key,
179
+                        $this->aggregate
180
+                    );
181
+                }
182
+                $this->step($idx);
183
+            },
184
+            function ($reason) use ($idx, $key) {
185
+                if ($this->onRejected) {
186
+                    call_user_func(
187
+                        $this->onRejected,
188
+                        $reason,
189
+                        $key,
190
+                        $this->aggregate
191
+                    );
192
+                }
193
+                $this->step($idx);
194
+            }
195
+        );
196
+
197
+        return true;
198
+    }
199
+
200
+    private function advanceIterator()
201
+    {
202
+        // Place a lock on the iterator so that we ensure to not recurse,
203
+        // preventing fatal generator errors.
204
+        if ($this->mutex) {
205
+            return false;
206
+        }
207
+
208
+        $this->mutex = true;
209
+
210
+        try {
211
+            $this->iterable->next();
212
+            $this->mutex = false;
213
+            return true;
214
+        } catch (\Throwable $e) {
215
+            $this->aggregate->reject($e);
216
+            $this->mutex = false;
217
+            return false;
218
+        } catch (\Exception $e) {
219
+            $this->aggregate->reject($e);
220
+            $this->mutex = false;
221
+            return false;
222
+        }
223
+    }
224
+
225
+    private function step($idx)
226
+    {
227
+        // If the promise was already resolved, then ignore this step.
228
+        if (Is::settled($this->aggregate)) {
229
+            return;
230
+        }
231
+
232
+        unset($this->pending[$idx]);
233
+
234
+        // Only refill pending promises if we are not locked, preventing the
235
+        // EachPromise to recursively invoke the provided iterator, which
236
+        // cause a fatal error: "Cannot resume an already running generator"
237
+        if ($this->advanceIterator() && !$this->checkIfFinished()) {
238
+            // Add more pending promises if possible.
239
+            $this->refillPending();
240
+        }
241
+    }
242
+
243
+    private function checkIfFinished()
244
+    {
245
+        if (!$this->pending && !$this->iterable->valid()) {
246
+            // Resolve the promise if there's nothing left to do.
247
+            $this->aggregate->resolve(null);
248
+            return true;
249
+        }
250
+
251
+        return false;
252
+    }
253
+}