@@ -5,52 +5,52 @@ |
||
5 | 5 | |
6 | 6 | final class Each |
7 | 7 | { |
8 | - /** |
|
9 | - * Given an iterator that yields promises or values, returns a promise that |
|
10 | - * is fulfilled with a null value when the iterator has been consumed or |
|
11 | - * the aggregate promise has been fulfilled or rejected. |
|
12 | - * |
|
13 | - * $onFulfilled is a function that accepts the fulfilled value, iterator |
|
14 | - * index, and the aggregate promise. The callback can invoke any necessary |
|
15 | - * side effects and choose to resolve or reject the aggregate if needed. |
|
16 | - * |
|
17 | - * $onRejected is a function that accepts the rejection reason, iterator |
|
18 | - * index, and the aggregate promise. The callback can invoke any necessary |
|
19 | - * side effects and choose to resolve or reject the aggregate if needed. |
|
20 | - * |
|
21 | - * @param mixed $iterable Iterator or array to iterate over. |
|
22 | - */ |
|
23 | - public static function of($iterable, callable $onFulfilled = null, callable $onRejected = null) : PromiseInterface |
|
24 | - { |
|
25 | - return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise(); |
|
26 | - } |
|
27 | - /** |
|
28 | - * Like of, but only allows a certain number of outstanding promises at any |
|
29 | - * given time. |
|
30 | - * |
|
31 | - * $concurrency may be an integer or a function that accepts the number of |
|
32 | - * pending promises and returns a numeric concurrency limit value to allow |
|
33 | - * for dynamic a concurrency size. |
|
34 | - * |
|
35 | - * @param mixed $iterable |
|
36 | - * @param int|callable $concurrency |
|
37 | - */ |
|
38 | - public static function ofLimit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null) : PromiseInterface |
|
39 | - { |
|
40 | - return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise(); |
|
41 | - } |
|
42 | - /** |
|
43 | - * Like limit, but ensures that no promise in the given $iterable argument |
|
44 | - * is rejected. If any promise is rejected, then the aggregate promise is |
|
45 | - * rejected with the encountered rejection. |
|
46 | - * |
|
47 | - * @param mixed $iterable |
|
48 | - * @param int|callable $concurrency |
|
49 | - */ |
|
50 | - public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null) : PromiseInterface |
|
51 | - { |
|
52 | - return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate) : void { |
|
53 | - $aggregate->reject($reason); |
|
54 | - }); |
|
55 | - } |
|
8 | + /** |
|
9 | + * Given an iterator that yields promises or values, returns a promise that |
|
10 | + * is fulfilled with a null value when the iterator has been consumed or |
|
11 | + * the aggregate promise has been fulfilled or rejected. |
|
12 | + * |
|
13 | + * $onFulfilled is a function that accepts the fulfilled value, iterator |
|
14 | + * index, and the aggregate promise. The callback can invoke any necessary |
|
15 | + * side effects and choose to resolve or reject the aggregate if needed. |
|
16 | + * |
|
17 | + * $onRejected is a function that accepts the rejection reason, iterator |
|
18 | + * index, and the aggregate promise. The callback can invoke any necessary |
|
19 | + * side effects and choose to resolve or reject the aggregate if needed. |
|
20 | + * |
|
21 | + * @param mixed $iterable Iterator or array to iterate over. |
|
22 | + */ |
|
23 | + public static function of($iterable, callable $onFulfilled = null, callable $onRejected = null) : PromiseInterface |
|
24 | + { |
|
25 | + return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise(); |
|
26 | + } |
|
27 | + /** |
|
28 | + * Like of, but only allows a certain number of outstanding promises at any |
|
29 | + * given time. |
|
30 | + * |
|
31 | + * $concurrency may be an integer or a function that accepts the number of |
|
32 | + * pending promises and returns a numeric concurrency limit value to allow |
|
33 | + * for dynamic a concurrency size. |
|
34 | + * |
|
35 | + * @param mixed $iterable |
|
36 | + * @param int|callable $concurrency |
|
37 | + */ |
|
38 | + public static function ofLimit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null) : PromiseInterface |
|
39 | + { |
|
40 | + return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise(); |
|
41 | + } |
|
42 | + /** |
|
43 | + * Like limit, but ensures that no promise in the given $iterable argument |
|
44 | + * is rejected. If any promise is rejected, then the aggregate promise is |
|
45 | + * rejected with the encountered rejection. |
|
46 | + * |
|
47 | + * @param mixed $iterable |
|
48 | + * @param int|callable $concurrency |
|
49 | + */ |
|
50 | + public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null) : PromiseInterface |
|
51 | + { |
|
52 | + return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate) : void { |
|
53 | + $aggregate->reject($reason); |
|
54 | + }); |
|
55 | + } |
|
56 | 56 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare (strict_types=1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Promise; |
5 | 5 | |
6 | 6 | final class Each |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null) : PromiseInterface |
51 | 51 | { |
52 | - return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate) : void { |
|
52 | + return self::ofLimit($iterable, $concurrency, $onFulfilled, function($reason, $idx, PromiseInterface $aggregate) : void { |
|
53 | 53 | $aggregate->reject($reason); |
54 | 54 | }); |
55 | 55 | } |
@@ -3,8 +3,7 @@ |
||
3 | 3 | declare (strict_types=1); |
4 | 4 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Promise; |
5 | 5 | |
6 | -final class Each |
|
7 | -{ |
|
6 | +final class Each { |
|
8 | 7 | /** |
9 | 8 | * Given an iterator that yields promises or values, returns a promise that |
10 | 9 | * is fulfilled with a null value when the iterator has been consumed or |
@@ -8,8 +8,8 @@ |
||
8 | 8 | */ |
9 | 9 | class AggregateException extends RejectionException |
10 | 10 | { |
11 | - public function __construct(string $msg, array $reasons) |
|
12 | - { |
|
13 | - parent::__construct($reasons, \sprintf('%s; %d rejected promises', $msg, \count($reasons))); |
|
14 | - } |
|
11 | + public function __construct(string $msg, array $reasons) |
|
12 | + { |
|
13 | + parent::__construct($reasons, \sprintf('%s; %d rejected promises', $msg, \count($reasons))); |
|
14 | + } |
|
15 | 15 | } |
@@ -6,8 +6,7 @@ |
||
6 | 6 | /** |
7 | 7 | * Exception thrown when too many errors occur in the some() or any() methods. |
8 | 8 | */ |
9 | -class AggregateException extends RejectionException |
|
10 | -{ |
|
9 | +class AggregateException extends RejectionException { |
|
11 | 10 | public function __construct(string $msg, array $reasons) |
12 | 11 | { |
13 | 12 | parent::__construct($reasons, \sprintf('%s; %d rejected promises', $msg, \count($reasons))); |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare (strict_types=1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Promise; |
5 | 5 | |
6 | 6 | /** |
@@ -5,213 +5,213 @@ |
||
5 | 5 | |
6 | 6 | final class Utils |
7 | 7 | { |
8 | - /** |
|
9 | - * Get the global task queue used for promise resolution. |
|
10 | - * |
|
11 | - * This task queue MUST be run in an event loop in order for promises to be |
|
12 | - * settled asynchronously. It will be automatically run when synchronously |
|
13 | - * waiting on a promise. |
|
14 | - * |
|
15 | - * <code> |
|
16 | - * while ($eventLoop->isRunning()) { |
|
17 | - * GuzzleHttp\Promise\Utils::queue()->run(); |
|
18 | - * } |
|
19 | - * </code> |
|
20 | - * |
|
21 | - * @param TaskQueueInterface|null $assign Optionally specify a new queue instance. |
|
22 | - */ |
|
23 | - public static function queue(TaskQueueInterface $assign = null) : TaskQueueInterface |
|
24 | - { |
|
25 | - static $queue; |
|
26 | - if ($assign) { |
|
27 | - $queue = $assign; |
|
28 | - } elseif (!$queue) { |
|
29 | - $queue = new TaskQueue(); |
|
30 | - } |
|
31 | - return $queue; |
|
32 | - } |
|
33 | - /** |
|
34 | - * Adds a function to run in the task queue when it is next `run()` and |
|
35 | - * returns a promise that is fulfilled or rejected with the result. |
|
36 | - * |
|
37 | - * @param callable $task Task function to run. |
|
38 | - */ |
|
39 | - public static function task(callable $task) : PromiseInterface |
|
40 | - { |
|
41 | - $queue = self::queue(); |
|
42 | - $promise = new Promise([$queue, 'run']); |
|
43 | - $queue->add(function () use($task, $promise) : void { |
|
44 | - try { |
|
45 | - if (Is::pending($promise)) { |
|
46 | - $promise->resolve($task()); |
|
47 | - } |
|
48 | - } catch (\Throwable $e) { |
|
49 | - $promise->reject($e); |
|
50 | - } |
|
51 | - }); |
|
52 | - return $promise; |
|
53 | - } |
|
54 | - /** |
|
55 | - * Synchronously waits on a promise to resolve and returns an inspection |
|
56 | - * state array. |
|
57 | - * |
|
58 | - * Returns a state associative array containing a "state" key mapping to a |
|
59 | - * valid promise state. If the state of the promise is "fulfilled", the |
|
60 | - * array will contain a "value" key mapping to the fulfilled value of the |
|
61 | - * promise. If the promise is rejected, the array will contain a "reason" |
|
62 | - * key mapping to the rejection reason of the promise. |
|
63 | - * |
|
64 | - * @param PromiseInterface $promise Promise or value. |
|
65 | - */ |
|
66 | - public static function inspect(PromiseInterface $promise) : array |
|
67 | - { |
|
68 | - try { |
|
69 | - return ['state' => PromiseInterface::FULFILLED, 'value' => $promise->wait()]; |
|
70 | - } catch (RejectionException $e) { |
|
71 | - return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()]; |
|
72 | - } catch (\Throwable $e) { |
|
73 | - return ['state' => PromiseInterface::REJECTED, 'reason' => $e]; |
|
74 | - } |
|
75 | - } |
|
76 | - /** |
|
77 | - * Waits on all of the provided promises, but does not unwrap rejected |
|
78 | - * promises as thrown exception. |
|
79 | - * |
|
80 | - * Returns an array of inspection state arrays. |
|
81 | - * |
|
82 | - * @see inspect for the inspection state array format. |
|
83 | - * |
|
84 | - * @param PromiseInterface[] $promises Traversable of promises to wait upon. |
|
85 | - */ |
|
86 | - public static function inspectAll($promises) : array |
|
87 | - { |
|
88 | - $results = []; |
|
89 | - foreach ($promises as $key => $promise) { |
|
90 | - $results[$key] = self::inspect($promise); |
|
91 | - } |
|
92 | - return $results; |
|
93 | - } |
|
94 | - /** |
|
95 | - * Waits on all of the provided promises and returns the fulfilled values. |
|
96 | - * |
|
97 | - * Returns an array that contains the value of each promise (in the same |
|
98 | - * order the promises were provided). An exception is thrown if any of the |
|
99 | - * promises are rejected. |
|
100 | - * |
|
101 | - * @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on. |
|
102 | - * |
|
103 | - * @throws \Throwable on error |
|
104 | - */ |
|
105 | - public static function unwrap($promises) : array |
|
106 | - { |
|
107 | - $results = []; |
|
108 | - foreach ($promises as $key => $promise) { |
|
109 | - $results[$key] = $promise->wait(); |
|
110 | - } |
|
111 | - return $results; |
|
112 | - } |
|
113 | - /** |
|
114 | - * Given an array of promises, return a promise that is fulfilled when all |
|
115 | - * the items in the array are fulfilled. |
|
116 | - * |
|
117 | - * The promise's fulfillment value is an array with fulfillment values at |
|
118 | - * respective positions to the original array. If any promise in the array |
|
119 | - * rejects, the returned promise is rejected with the rejection reason. |
|
120 | - * |
|
121 | - * @param mixed $promises Promises or values. |
|
122 | - * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution. |
|
123 | - */ |
|
124 | - public static function all($promises, bool $recursive = \false) : PromiseInterface |
|
125 | - { |
|
126 | - $results = []; |
|
127 | - $promise = Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
128 | - $results[$idx] = $value; |
|
129 | - }, function ($reason, $idx, Promise $aggregate) : void { |
|
130 | - $aggregate->reject($reason); |
|
131 | - })->then(function () use(&$results) { |
|
132 | - \ksort($results); |
|
133 | - return $results; |
|
134 | - }); |
|
135 | - if (\true === $recursive) { |
|
136 | - $promise = $promise->then(function ($results) use($recursive, &$promises) { |
|
137 | - foreach ($promises as $promise) { |
|
138 | - if (Is::pending($promise)) { |
|
139 | - return self::all($promises, $recursive); |
|
140 | - } |
|
141 | - } |
|
142 | - return $results; |
|
143 | - }); |
|
144 | - } |
|
145 | - return $promise; |
|
146 | - } |
|
147 | - /** |
|
148 | - * Initiate a competitive race between multiple promises or values (values |
|
149 | - * will become immediately fulfilled promises). |
|
150 | - * |
|
151 | - * When count amount of promises have been fulfilled, the returned promise |
|
152 | - * is fulfilled with an array that contains the fulfillment values of the |
|
153 | - * winners in order of resolution. |
|
154 | - * |
|
155 | - * This promise is rejected with a {@see AggregateException} if the number |
|
156 | - * of fulfilled promises is less than the desired $count. |
|
157 | - * |
|
158 | - * @param int $count Total number of promises. |
|
159 | - * @param mixed $promises Promises or values. |
|
160 | - */ |
|
161 | - public static function some(int $count, $promises) : PromiseInterface |
|
162 | - { |
|
163 | - $results = []; |
|
164 | - $rejections = []; |
|
165 | - return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void { |
|
166 | - if (Is::settled($p)) { |
|
167 | - return; |
|
168 | - } |
|
169 | - $results[$idx] = $value; |
|
170 | - if (\count($results) >= $count) { |
|
171 | - $p->resolve(null); |
|
172 | - } |
|
173 | - }, function ($reason) use(&$rejections) : void { |
|
174 | - $rejections[] = $reason; |
|
175 | - })->then(function () use(&$results, &$rejections, $count) { |
|
176 | - if (\count($results) !== $count) { |
|
177 | - throw new AggregateException('Not enough promises to fulfill count', $rejections); |
|
178 | - } |
|
179 | - \ksort($results); |
|
180 | - return \array_values($results); |
|
181 | - }); |
|
182 | - } |
|
183 | - /** |
|
184 | - * Like some(), with 1 as count. However, if the promise fulfills, the |
|
185 | - * fulfillment value is not an array of 1 but the value directly. |
|
186 | - * |
|
187 | - * @param mixed $promises Promises or values. |
|
188 | - */ |
|
189 | - public static function any($promises) : PromiseInterface |
|
190 | - { |
|
191 | - return self::some(1, $promises)->then(function ($values) { |
|
192 | - return $values[0]; |
|
193 | - }); |
|
194 | - } |
|
195 | - /** |
|
196 | - * Returns a promise that is fulfilled when all of the provided promises have |
|
197 | - * been fulfilled or rejected. |
|
198 | - * |
|
199 | - * The returned promise is fulfilled with an array of inspection state arrays. |
|
200 | - * |
|
201 | - * @see inspect for the inspection state array format. |
|
202 | - * |
|
203 | - * @param mixed $promises Promises or values. |
|
204 | - */ |
|
205 | - public static function settle($promises) : PromiseInterface |
|
206 | - { |
|
207 | - $results = []; |
|
208 | - return Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
209 | - $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value]; |
|
210 | - }, function ($reason, $idx) use(&$results) : void { |
|
211 | - $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason]; |
|
212 | - })->then(function () use(&$results) { |
|
213 | - \ksort($results); |
|
214 | - return $results; |
|
215 | - }); |
|
216 | - } |
|
8 | + /** |
|
9 | + * Get the global task queue used for promise resolution. |
|
10 | + * |
|
11 | + * This task queue MUST be run in an event loop in order for promises to be |
|
12 | + * settled asynchronously. It will be automatically run when synchronously |
|
13 | + * waiting on a promise. |
|
14 | + * |
|
15 | + * <code> |
|
16 | + * while ($eventLoop->isRunning()) { |
|
17 | + * GuzzleHttp\Promise\Utils::queue()->run(); |
|
18 | + * } |
|
19 | + * </code> |
|
20 | + * |
|
21 | + * @param TaskQueueInterface|null $assign Optionally specify a new queue instance. |
|
22 | + */ |
|
23 | + public static function queue(TaskQueueInterface $assign = null) : TaskQueueInterface |
|
24 | + { |
|
25 | + static $queue; |
|
26 | + if ($assign) { |
|
27 | + $queue = $assign; |
|
28 | + } elseif (!$queue) { |
|
29 | + $queue = new TaskQueue(); |
|
30 | + } |
|
31 | + return $queue; |
|
32 | + } |
|
33 | + /** |
|
34 | + * Adds a function to run in the task queue when it is next `run()` and |
|
35 | + * returns a promise that is fulfilled or rejected with the result. |
|
36 | + * |
|
37 | + * @param callable $task Task function to run. |
|
38 | + */ |
|
39 | + public static function task(callable $task) : PromiseInterface |
|
40 | + { |
|
41 | + $queue = self::queue(); |
|
42 | + $promise = new Promise([$queue, 'run']); |
|
43 | + $queue->add(function () use($task, $promise) : void { |
|
44 | + try { |
|
45 | + if (Is::pending($promise)) { |
|
46 | + $promise->resolve($task()); |
|
47 | + } |
|
48 | + } catch (\Throwable $e) { |
|
49 | + $promise->reject($e); |
|
50 | + } |
|
51 | + }); |
|
52 | + return $promise; |
|
53 | + } |
|
54 | + /** |
|
55 | + * Synchronously waits on a promise to resolve and returns an inspection |
|
56 | + * state array. |
|
57 | + * |
|
58 | + * Returns a state associative array containing a "state" key mapping to a |
|
59 | + * valid promise state. If the state of the promise is "fulfilled", the |
|
60 | + * array will contain a "value" key mapping to the fulfilled value of the |
|
61 | + * promise. If the promise is rejected, the array will contain a "reason" |
|
62 | + * key mapping to the rejection reason of the promise. |
|
63 | + * |
|
64 | + * @param PromiseInterface $promise Promise or value. |
|
65 | + */ |
|
66 | + public static function inspect(PromiseInterface $promise) : array |
|
67 | + { |
|
68 | + try { |
|
69 | + return ['state' => PromiseInterface::FULFILLED, 'value' => $promise->wait()]; |
|
70 | + } catch (RejectionException $e) { |
|
71 | + return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()]; |
|
72 | + } catch (\Throwable $e) { |
|
73 | + return ['state' => PromiseInterface::REJECTED, 'reason' => $e]; |
|
74 | + } |
|
75 | + } |
|
76 | + /** |
|
77 | + * Waits on all of the provided promises, but does not unwrap rejected |
|
78 | + * promises as thrown exception. |
|
79 | + * |
|
80 | + * Returns an array of inspection state arrays. |
|
81 | + * |
|
82 | + * @see inspect for the inspection state array format. |
|
83 | + * |
|
84 | + * @param PromiseInterface[] $promises Traversable of promises to wait upon. |
|
85 | + */ |
|
86 | + public static function inspectAll($promises) : array |
|
87 | + { |
|
88 | + $results = []; |
|
89 | + foreach ($promises as $key => $promise) { |
|
90 | + $results[$key] = self::inspect($promise); |
|
91 | + } |
|
92 | + return $results; |
|
93 | + } |
|
94 | + /** |
|
95 | + * Waits on all of the provided promises and returns the fulfilled values. |
|
96 | + * |
|
97 | + * Returns an array that contains the value of each promise (in the same |
|
98 | + * order the promises were provided). An exception is thrown if any of the |
|
99 | + * promises are rejected. |
|
100 | + * |
|
101 | + * @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on. |
|
102 | + * |
|
103 | + * @throws \Throwable on error |
|
104 | + */ |
|
105 | + public static function unwrap($promises) : array |
|
106 | + { |
|
107 | + $results = []; |
|
108 | + foreach ($promises as $key => $promise) { |
|
109 | + $results[$key] = $promise->wait(); |
|
110 | + } |
|
111 | + return $results; |
|
112 | + } |
|
113 | + /** |
|
114 | + * Given an array of promises, return a promise that is fulfilled when all |
|
115 | + * the items in the array are fulfilled. |
|
116 | + * |
|
117 | + * The promise's fulfillment value is an array with fulfillment values at |
|
118 | + * respective positions to the original array. If any promise in the array |
|
119 | + * rejects, the returned promise is rejected with the rejection reason. |
|
120 | + * |
|
121 | + * @param mixed $promises Promises or values. |
|
122 | + * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution. |
|
123 | + */ |
|
124 | + public static function all($promises, bool $recursive = \false) : PromiseInterface |
|
125 | + { |
|
126 | + $results = []; |
|
127 | + $promise = Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
128 | + $results[$idx] = $value; |
|
129 | + }, function ($reason, $idx, Promise $aggregate) : void { |
|
130 | + $aggregate->reject($reason); |
|
131 | + })->then(function () use(&$results) { |
|
132 | + \ksort($results); |
|
133 | + return $results; |
|
134 | + }); |
|
135 | + if (\true === $recursive) { |
|
136 | + $promise = $promise->then(function ($results) use($recursive, &$promises) { |
|
137 | + foreach ($promises as $promise) { |
|
138 | + if (Is::pending($promise)) { |
|
139 | + return self::all($promises, $recursive); |
|
140 | + } |
|
141 | + } |
|
142 | + return $results; |
|
143 | + }); |
|
144 | + } |
|
145 | + return $promise; |
|
146 | + } |
|
147 | + /** |
|
148 | + * Initiate a competitive race between multiple promises or values (values |
|
149 | + * will become immediately fulfilled promises). |
|
150 | + * |
|
151 | + * When count amount of promises have been fulfilled, the returned promise |
|
152 | + * is fulfilled with an array that contains the fulfillment values of the |
|
153 | + * winners in order of resolution. |
|
154 | + * |
|
155 | + * This promise is rejected with a {@see AggregateException} if the number |
|
156 | + * of fulfilled promises is less than the desired $count. |
|
157 | + * |
|
158 | + * @param int $count Total number of promises. |
|
159 | + * @param mixed $promises Promises or values. |
|
160 | + */ |
|
161 | + public static function some(int $count, $promises) : PromiseInterface |
|
162 | + { |
|
163 | + $results = []; |
|
164 | + $rejections = []; |
|
165 | + return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void { |
|
166 | + if (Is::settled($p)) { |
|
167 | + return; |
|
168 | + } |
|
169 | + $results[$idx] = $value; |
|
170 | + if (\count($results) >= $count) { |
|
171 | + $p->resolve(null); |
|
172 | + } |
|
173 | + }, function ($reason) use(&$rejections) : void { |
|
174 | + $rejections[] = $reason; |
|
175 | + })->then(function () use(&$results, &$rejections, $count) { |
|
176 | + if (\count($results) !== $count) { |
|
177 | + throw new AggregateException('Not enough promises to fulfill count', $rejections); |
|
178 | + } |
|
179 | + \ksort($results); |
|
180 | + return \array_values($results); |
|
181 | + }); |
|
182 | + } |
|
183 | + /** |
|
184 | + * Like some(), with 1 as count. However, if the promise fulfills, the |
|
185 | + * fulfillment value is not an array of 1 but the value directly. |
|
186 | + * |
|
187 | + * @param mixed $promises Promises or values. |
|
188 | + */ |
|
189 | + public static function any($promises) : PromiseInterface |
|
190 | + { |
|
191 | + return self::some(1, $promises)->then(function ($values) { |
|
192 | + return $values[0]; |
|
193 | + }); |
|
194 | + } |
|
195 | + /** |
|
196 | + * Returns a promise that is fulfilled when all of the provided promises have |
|
197 | + * been fulfilled or rejected. |
|
198 | + * |
|
199 | + * The returned promise is fulfilled with an array of inspection state arrays. |
|
200 | + * |
|
201 | + * @see inspect for the inspection state array format. |
|
202 | + * |
|
203 | + * @param mixed $promises Promises or values. |
|
204 | + */ |
|
205 | + public static function settle($promises) : PromiseInterface |
|
206 | + { |
|
207 | + $results = []; |
|
208 | + return Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
209 | + $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value]; |
|
210 | + }, function ($reason, $idx) use(&$results) : void { |
|
211 | + $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason]; |
|
212 | + })->then(function () use(&$results) { |
|
213 | + \ksort($results); |
|
214 | + return $results; |
|
215 | + }); |
|
216 | + } |
|
217 | 217 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare (strict_types=1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Promise; |
5 | 5 | |
6 | 6 | final class Utils |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | $queue = self::queue(); |
42 | 42 | $promise = new Promise([$queue, 'run']); |
43 | - $queue->add(function () use($task, $promise) : void { |
|
43 | + $queue->add(function() use($task, $promise) : void { |
|
44 | 44 | try { |
45 | 45 | if (Is::pending($promise)) { |
46 | 46 | $promise->resolve($task()); |
@@ -124,16 +124,16 @@ discard block |
||
124 | 124 | public static function all($promises, bool $recursive = \false) : PromiseInterface |
125 | 125 | { |
126 | 126 | $results = []; |
127 | - $promise = Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
127 | + $promise = Each::of($promises, function($value, $idx) use(&$results) : void { |
|
128 | 128 | $results[$idx] = $value; |
129 | - }, function ($reason, $idx, Promise $aggregate) : void { |
|
129 | + }, function($reason, $idx, Promise $aggregate) : void { |
|
130 | 130 | $aggregate->reject($reason); |
131 | - })->then(function () use(&$results) { |
|
131 | + })->then(function() use(&$results) { |
|
132 | 132 | \ksort($results); |
133 | 133 | return $results; |
134 | 134 | }); |
135 | 135 | if (\true === $recursive) { |
136 | - $promise = $promise->then(function ($results) use($recursive, &$promises) { |
|
136 | + $promise = $promise->then(function($results) use($recursive, &$promises) { |
|
137 | 137 | foreach ($promises as $promise) { |
138 | 138 | if (Is::pending($promise)) { |
139 | 139 | return self::all($promises, $recursive); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | $results = []; |
164 | 164 | $rejections = []; |
165 | - return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void { |
|
165 | + return Each::of($promises, function($value, $idx, PromiseInterface $p) use(&$results, $count) : void { |
|
166 | 166 | if (Is::settled($p)) { |
167 | 167 | return; |
168 | 168 | } |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | if (\count($results) >= $count) { |
171 | 171 | $p->resolve(null); |
172 | 172 | } |
173 | - }, function ($reason) use(&$rejections) : void { |
|
173 | + }, function($reason) use(&$rejections) : void { |
|
174 | 174 | $rejections[] = $reason; |
175 | - })->then(function () use(&$results, &$rejections, $count) { |
|
175 | + })->then(function() use(&$results, &$rejections, $count) { |
|
176 | 176 | if (\count($results) !== $count) { |
177 | 177 | throw new AggregateException('Not enough promises to fulfill count', $rejections); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public static function any($promises) : PromiseInterface |
190 | 190 | { |
191 | - return self::some(1, $promises)->then(function ($values) { |
|
191 | + return self::some(1, $promises)->then(function($values) { |
|
192 | 192 | return $values[0]; |
193 | 193 | }); |
194 | 194 | } |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | public static function settle($promises) : PromiseInterface |
206 | 206 | { |
207 | 207 | $results = []; |
208 | - return Each::of($promises, function ($value, $idx) use(&$results) : void { |
|
208 | + return Each::of($promises, function($value, $idx) use(&$results) : void { |
|
209 | 209 | $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value]; |
210 | - }, function ($reason, $idx) use(&$results) : void { |
|
210 | + }, function($reason, $idx) use(&$results) : void { |
|
211 | 211 | $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason]; |
212 | - })->then(function () use(&$results) { |
|
212 | + })->then(function() use(&$results) { |
|
213 | 213 | \ksort($results); |
214 | 214 | return $results; |
215 | 215 | }); |
@@ -3,8 +3,7 @@ |
||
3 | 3 | declare (strict_types=1); |
4 | 4 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Promise; |
5 | 5 | |
6 | -final class Utils |
|
7 | -{ |
|
6 | +final class Utils { |
|
8 | 7 | /** |
9 | 8 | * Get the global task queue used for promise resolution. |
10 | 9 | * |
@@ -5,19 +5,19 @@ |
||
5 | 5 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\MessageInterface; |
6 | 6 | final class BodySummarizer implements BodySummarizerInterface |
7 | 7 | { |
8 | - /** |
|
9 | - * @var int|null |
|
10 | - */ |
|
11 | - private $truncateAt; |
|
12 | - public function __construct(int $truncateAt = null) |
|
13 | - { |
|
14 | - $this->truncateAt = $truncateAt; |
|
15 | - } |
|
16 | - /** |
|
17 | - * Returns a summarized message body. |
|
18 | - */ |
|
19 | - public function summarize(MessageInterface $message) : ?string |
|
20 | - { |
|
21 | - return $this->truncateAt === null ? \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Message::bodySummary($message) : \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $this->truncateAt); |
|
22 | - } |
|
8 | + /** |
|
9 | + * @var int|null |
|
10 | + */ |
|
11 | + private $truncateAt; |
|
12 | + public function __construct(int $truncateAt = null) |
|
13 | + { |
|
14 | + $this->truncateAt = $truncateAt; |
|
15 | + } |
|
16 | + /** |
|
17 | + * Returns a summarized message body. |
|
18 | + */ |
|
19 | + public function summarize(MessageInterface $message) : ?string |
|
20 | + { |
|
21 | + return $this->truncateAt === null ? \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Message::bodySummary($message) : \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $this->truncateAt); |
|
22 | + } |
|
23 | 23 | } |
@@ -3,8 +3,7 @@ |
||
3 | 3 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp; |
4 | 4 | |
5 | 5 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\MessageInterface; |
6 | -final class BodySummarizer implements BodySummarizerInterface |
|
7 | -{ |
|
6 | +final class BodySummarizer implements BodySummarizerInterface { |
|
8 | 7 | /** |
9 | 8 | * @var int|null |
10 | 9 | */ |
@@ -18,57 +18,57 @@ |
||
18 | 18 | */ |
19 | 19 | interface CookieJarInterface extends \Countable, \IteratorAggregate |
20 | 20 | { |
21 | - /** |
|
22 | - * Create a request with added cookie headers. |
|
23 | - * |
|
24 | - * If no matching cookies are found in the cookie jar, then no Cookie |
|
25 | - * header is added to the request and the same request is returned. |
|
26 | - * |
|
27 | - * @param RequestInterface $request Request object to modify. |
|
28 | - * |
|
29 | - * @return RequestInterface returns the modified request. |
|
30 | - */ |
|
31 | - public function withCookieHeader(RequestInterface $request) : RequestInterface; |
|
32 | - /** |
|
33 | - * Extract cookies from an HTTP response and store them in the CookieJar. |
|
34 | - * |
|
35 | - * @param RequestInterface $request Request that was sent |
|
36 | - * @param ResponseInterface $response Response that was received |
|
37 | - */ |
|
38 | - public function extractCookies(RequestInterface $request, ResponseInterface $response) : void; |
|
39 | - /** |
|
40 | - * Sets a cookie in the cookie jar. |
|
41 | - * |
|
42 | - * @param SetCookie $cookie Cookie to set. |
|
43 | - * |
|
44 | - * @return bool Returns true on success or false on failure |
|
45 | - */ |
|
46 | - public function setCookie(SetCookie $cookie) : bool; |
|
47 | - /** |
|
48 | - * Remove cookies currently held in the cookie jar. |
|
49 | - * |
|
50 | - * Invoking this method without arguments will empty the whole cookie jar. |
|
51 | - * If given a $domain argument only cookies belonging to that domain will |
|
52 | - * be removed. If given a $domain and $path argument, cookies belonging to |
|
53 | - * the specified path within that domain are removed. If given all three |
|
54 | - * arguments, then the cookie with the specified name, path and domain is |
|
55 | - * removed. |
|
56 | - * |
|
57 | - * @param string|null $domain Clears cookies matching a domain |
|
58 | - * @param string|null $path Clears cookies matching a domain and path |
|
59 | - * @param string|null $name Clears cookies matching a domain, path, and name |
|
60 | - */ |
|
61 | - public function clear(string $domain = null, string $path = null, string $name = null) : void; |
|
62 | - /** |
|
63 | - * Discard all sessions cookies. |
|
64 | - * |
|
65 | - * Removes cookies that don't have an expire field or a have a discard |
|
66 | - * field set to true. To be called when the user agent shuts down according |
|
67 | - * to RFC 2965. |
|
68 | - */ |
|
69 | - public function clearSessionCookies() : void; |
|
70 | - /** |
|
71 | - * Converts the cookie jar to an array. |
|
72 | - */ |
|
73 | - public function toArray() : array; |
|
21 | + /** |
|
22 | + * Create a request with added cookie headers. |
|
23 | + * |
|
24 | + * If no matching cookies are found in the cookie jar, then no Cookie |
|
25 | + * header is added to the request and the same request is returned. |
|
26 | + * |
|
27 | + * @param RequestInterface $request Request object to modify. |
|
28 | + * |
|
29 | + * @return RequestInterface returns the modified request. |
|
30 | + */ |
|
31 | + public function withCookieHeader(RequestInterface $request) : RequestInterface; |
|
32 | + /** |
|
33 | + * Extract cookies from an HTTP response and store them in the CookieJar. |
|
34 | + * |
|
35 | + * @param RequestInterface $request Request that was sent |
|
36 | + * @param ResponseInterface $response Response that was received |
|
37 | + */ |
|
38 | + public function extractCookies(RequestInterface $request, ResponseInterface $response) : void; |
|
39 | + /** |
|
40 | + * Sets a cookie in the cookie jar. |
|
41 | + * |
|
42 | + * @param SetCookie $cookie Cookie to set. |
|
43 | + * |
|
44 | + * @return bool Returns true on success or false on failure |
|
45 | + */ |
|
46 | + public function setCookie(SetCookie $cookie) : bool; |
|
47 | + /** |
|
48 | + * Remove cookies currently held in the cookie jar. |
|
49 | + * |
|
50 | + * Invoking this method without arguments will empty the whole cookie jar. |
|
51 | + * If given a $domain argument only cookies belonging to that domain will |
|
52 | + * be removed. If given a $domain and $path argument, cookies belonging to |
|
53 | + * the specified path within that domain are removed. If given all three |
|
54 | + * arguments, then the cookie with the specified name, path and domain is |
|
55 | + * removed. |
|
56 | + * |
|
57 | + * @param string|null $domain Clears cookies matching a domain |
|
58 | + * @param string|null $path Clears cookies matching a domain and path |
|
59 | + * @param string|null $name Clears cookies matching a domain, path, and name |
|
60 | + */ |
|
61 | + public function clear(string $domain = null, string $path = null, string $name = null) : void; |
|
62 | + /** |
|
63 | + * Discard all sessions cookies. |
|
64 | + * |
|
65 | + * Removes cookies that don't have an expire field or a have a discard |
|
66 | + * field set to true. To be called when the user agent shuts down according |
|
67 | + * to RFC 2965. |
|
68 | + */ |
|
69 | + public function clearSessionCookies() : void; |
|
70 | + /** |
|
71 | + * Converts the cookie jar to an array. |
|
72 | + */ |
|
73 | + public function toArray() : array; |
|
74 | 74 | } |
@@ -10,147 +10,147 @@ discard block |
||
10 | 10 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\UriInterface; |
11 | 11 | final class Utils |
12 | 12 | { |
13 | - /** |
|
14 | - * Debug function used to describe the provided value type and class. |
|
15 | - * |
|
16 | - * @param mixed $input |
|
17 | - * |
|
18 | - * @return string Returns a string containing the type of the variable and |
|
19 | - * if a class is provided, the class name. |
|
20 | - */ |
|
21 | - public static function describeType($input) : string |
|
22 | - { |
|
23 | - switch (\gettype($input)) { |
|
24 | - case 'object': |
|
25 | - return 'object(' . \get_class($input) . ')'; |
|
26 | - case 'array': |
|
27 | - return 'array(' . \count($input) . ')'; |
|
28 | - default: |
|
29 | - \ob_start(); |
|
30 | - \var_dump($input); |
|
31 | - // normalize float vs double |
|
32 | - /** @var string $varDumpContent */ |
|
33 | - $varDumpContent = \ob_get_clean(); |
|
34 | - return \str_replace('double(', 'float(', \rtrim($varDumpContent)); |
|
35 | - } |
|
36 | - } |
|
37 | - /** |
|
38 | - * Parses an array of header lines into an associative array of headers. |
|
39 | - * |
|
40 | - * @param iterable $lines Header lines array of strings in the following |
|
41 | - * format: "Name: Value" |
|
42 | - */ |
|
43 | - public static function headersFromLines(iterable $lines) : array |
|
44 | - { |
|
45 | - $headers = []; |
|
46 | - foreach ($lines as $line) { |
|
47 | - $parts = \explode(':', $line, 2); |
|
48 | - $headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null; |
|
49 | - } |
|
50 | - return $headers; |
|
51 | - } |
|
52 | - /** |
|
53 | - * Returns a debug stream based on the provided variable. |
|
54 | - * |
|
55 | - * @param mixed $value Optional value |
|
56 | - * |
|
57 | - * @return resource |
|
58 | - */ |
|
59 | - public static function debugResource($value = null) |
|
60 | - { |
|
61 | - if (\is_resource($value)) { |
|
62 | - return $value; |
|
63 | - } |
|
64 | - if (\defined('STDOUT')) { |
|
65 | - return \STDOUT; |
|
66 | - } |
|
67 | - return \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w'); |
|
68 | - } |
|
69 | - /** |
|
70 | - * Chooses and creates a default handler to use based on the environment. |
|
71 | - * |
|
72 | - * The returned handler is not wrapped by any default middlewares. |
|
73 | - * |
|
74 | - * @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system. |
|
75 | - * |
|
76 | - * @throws \RuntimeException if no viable Handler is available. |
|
77 | - */ |
|
78 | - public static function chooseHandler() : callable |
|
79 | - { |
|
80 | - $handler = null; |
|
81 | - if (\defined('CURLOPT_CUSTOMREQUEST')) { |
|
82 | - if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) { |
|
83 | - $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler()); |
|
84 | - } elseif (\function_exists('curl_exec')) { |
|
85 | - $handler = new CurlHandler(); |
|
86 | - } elseif (\function_exists('curl_multi_exec')) { |
|
87 | - $handler = new CurlMultiHandler(); |
|
88 | - } |
|
89 | - } |
|
90 | - if (\ini_get('allow_url_fopen')) { |
|
91 | - $handler = $handler ? Proxy::wrapStreaming($handler, new StreamHandler()) : new StreamHandler(); |
|
92 | - } elseif (!$handler) { |
|
93 | - throw new \RuntimeException('GuzzleHttp requires cURL, the allow_url_fopen ini setting, or a custom HTTP handler.'); |
|
94 | - } |
|
95 | - return $handler; |
|
96 | - } |
|
97 | - /** |
|
98 | - * Get the default User-Agent string to use with Guzzle. |
|
99 | - */ |
|
100 | - public static function defaultUserAgent() : string |
|
101 | - { |
|
102 | - return \sprintf('GuzzleHttp/%d', ClientInterface::MAJOR_VERSION); |
|
103 | - } |
|
104 | - /** |
|
105 | - * Returns the default cacert bundle for the current system. |
|
106 | - * |
|
107 | - * First, the openssl.cafile and curl.cainfo php.ini settings are checked. |
|
108 | - * If those settings are not configured, then the common locations for |
|
109 | - * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X |
|
110 | - * and Windows are checked. If any of these file locations are found on |
|
111 | - * disk, they will be utilized. |
|
112 | - * |
|
113 | - * Note: the result of this function is cached for subsequent calls. |
|
114 | - * |
|
115 | - * @throws \RuntimeException if no bundle can be found. |
|
116 | - * |
|
117 | - * @deprecated Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+. |
|
118 | - */ |
|
119 | - public static function defaultCaBundle() : string |
|
120 | - { |
|
121 | - static $cached = null; |
|
122 | - static $cafiles = [ |
|
123 | - // Red Hat, CentOS, Fedora (provided by the ca-certificates package) |
|
124 | - '/etc/pki/tls/certs/ca-bundle.crt', |
|
125 | - // Ubuntu, Debian (provided by the ca-certificates package) |
|
126 | - '/etc/ssl/certs/ca-certificates.crt', |
|
127 | - // FreeBSD (provided by the ca_root_nss package) |
|
128 | - '/usr/local/share/certs/ca-root-nss.crt', |
|
129 | - // SLES 12 (provided by the ca-certificates package) |
|
130 | - '/var/lib/ca-certificates/ca-bundle.pem', |
|
131 | - // OS X provided by homebrew (using the default path) |
|
132 | - '/usr/local/etc/openssl/cert.pem', |
|
133 | - // Google app engine |
|
134 | - '/etc/ca-certificates.crt', |
|
135 | - // Windows? |
|
136 | - 'C:\\windows\\system32\\curl-ca-bundle.crt', |
|
137 | - 'C:\\windows\\curl-ca-bundle.crt', |
|
138 | - ]; |
|
139 | - if ($cached) { |
|
140 | - return $cached; |
|
141 | - } |
|
142 | - if ($ca = \ini_get('openssl.cafile')) { |
|
143 | - return $cached = $ca; |
|
144 | - } |
|
145 | - if ($ca = \ini_get('curl.cainfo')) { |
|
146 | - return $cached = $ca; |
|
147 | - } |
|
148 | - foreach ($cafiles as $filename) { |
|
149 | - if (\file_exists($filename)) { |
|
150 | - return $cached = $filename; |
|
151 | - } |
|
152 | - } |
|
153 | - throw new \RuntimeException(<<<EOT |
|
13 | + /** |
|
14 | + * Debug function used to describe the provided value type and class. |
|
15 | + * |
|
16 | + * @param mixed $input |
|
17 | + * |
|
18 | + * @return string Returns a string containing the type of the variable and |
|
19 | + * if a class is provided, the class name. |
|
20 | + */ |
|
21 | + public static function describeType($input) : string |
|
22 | + { |
|
23 | + switch (\gettype($input)) { |
|
24 | + case 'object': |
|
25 | + return 'object(' . \get_class($input) . ')'; |
|
26 | + case 'array': |
|
27 | + return 'array(' . \count($input) . ')'; |
|
28 | + default: |
|
29 | + \ob_start(); |
|
30 | + \var_dump($input); |
|
31 | + // normalize float vs double |
|
32 | + /** @var string $varDumpContent */ |
|
33 | + $varDumpContent = \ob_get_clean(); |
|
34 | + return \str_replace('double(', 'float(', \rtrim($varDumpContent)); |
|
35 | + } |
|
36 | + } |
|
37 | + /** |
|
38 | + * Parses an array of header lines into an associative array of headers. |
|
39 | + * |
|
40 | + * @param iterable $lines Header lines array of strings in the following |
|
41 | + * format: "Name: Value" |
|
42 | + */ |
|
43 | + public static function headersFromLines(iterable $lines) : array |
|
44 | + { |
|
45 | + $headers = []; |
|
46 | + foreach ($lines as $line) { |
|
47 | + $parts = \explode(':', $line, 2); |
|
48 | + $headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null; |
|
49 | + } |
|
50 | + return $headers; |
|
51 | + } |
|
52 | + /** |
|
53 | + * Returns a debug stream based on the provided variable. |
|
54 | + * |
|
55 | + * @param mixed $value Optional value |
|
56 | + * |
|
57 | + * @return resource |
|
58 | + */ |
|
59 | + public static function debugResource($value = null) |
|
60 | + { |
|
61 | + if (\is_resource($value)) { |
|
62 | + return $value; |
|
63 | + } |
|
64 | + if (\defined('STDOUT')) { |
|
65 | + return \STDOUT; |
|
66 | + } |
|
67 | + return \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w'); |
|
68 | + } |
|
69 | + /** |
|
70 | + * Chooses and creates a default handler to use based on the environment. |
|
71 | + * |
|
72 | + * The returned handler is not wrapped by any default middlewares. |
|
73 | + * |
|
74 | + * @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system. |
|
75 | + * |
|
76 | + * @throws \RuntimeException if no viable Handler is available. |
|
77 | + */ |
|
78 | + public static function chooseHandler() : callable |
|
79 | + { |
|
80 | + $handler = null; |
|
81 | + if (\defined('CURLOPT_CUSTOMREQUEST')) { |
|
82 | + if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) { |
|
83 | + $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler()); |
|
84 | + } elseif (\function_exists('curl_exec')) { |
|
85 | + $handler = new CurlHandler(); |
|
86 | + } elseif (\function_exists('curl_multi_exec')) { |
|
87 | + $handler = new CurlMultiHandler(); |
|
88 | + } |
|
89 | + } |
|
90 | + if (\ini_get('allow_url_fopen')) { |
|
91 | + $handler = $handler ? Proxy::wrapStreaming($handler, new StreamHandler()) : new StreamHandler(); |
|
92 | + } elseif (!$handler) { |
|
93 | + throw new \RuntimeException('GuzzleHttp requires cURL, the allow_url_fopen ini setting, or a custom HTTP handler.'); |
|
94 | + } |
|
95 | + return $handler; |
|
96 | + } |
|
97 | + /** |
|
98 | + * Get the default User-Agent string to use with Guzzle. |
|
99 | + */ |
|
100 | + public static function defaultUserAgent() : string |
|
101 | + { |
|
102 | + return \sprintf('GuzzleHttp/%d', ClientInterface::MAJOR_VERSION); |
|
103 | + } |
|
104 | + /** |
|
105 | + * Returns the default cacert bundle for the current system. |
|
106 | + * |
|
107 | + * First, the openssl.cafile and curl.cainfo php.ini settings are checked. |
|
108 | + * If those settings are not configured, then the common locations for |
|
109 | + * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X |
|
110 | + * and Windows are checked. If any of these file locations are found on |
|
111 | + * disk, they will be utilized. |
|
112 | + * |
|
113 | + * Note: the result of this function is cached for subsequent calls. |
|
114 | + * |
|
115 | + * @throws \RuntimeException if no bundle can be found. |
|
116 | + * |
|
117 | + * @deprecated Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+. |
|
118 | + */ |
|
119 | + public static function defaultCaBundle() : string |
|
120 | + { |
|
121 | + static $cached = null; |
|
122 | + static $cafiles = [ |
|
123 | + // Red Hat, CentOS, Fedora (provided by the ca-certificates package) |
|
124 | + '/etc/pki/tls/certs/ca-bundle.crt', |
|
125 | + // Ubuntu, Debian (provided by the ca-certificates package) |
|
126 | + '/etc/ssl/certs/ca-certificates.crt', |
|
127 | + // FreeBSD (provided by the ca_root_nss package) |
|
128 | + '/usr/local/share/certs/ca-root-nss.crt', |
|
129 | + // SLES 12 (provided by the ca-certificates package) |
|
130 | + '/var/lib/ca-certificates/ca-bundle.pem', |
|
131 | + // OS X provided by homebrew (using the default path) |
|
132 | + '/usr/local/etc/openssl/cert.pem', |
|
133 | + // Google app engine |
|
134 | + '/etc/ca-certificates.crt', |
|
135 | + // Windows? |
|
136 | + 'C:\\windows\\system32\\curl-ca-bundle.crt', |
|
137 | + 'C:\\windows\\curl-ca-bundle.crt', |
|
138 | + ]; |
|
139 | + if ($cached) { |
|
140 | + return $cached; |
|
141 | + } |
|
142 | + if ($ca = \ini_get('openssl.cafile')) { |
|
143 | + return $cached = $ca; |
|
144 | + } |
|
145 | + if ($ca = \ini_get('curl.cainfo')) { |
|
146 | + return $cached = $ca; |
|
147 | + } |
|
148 | + foreach ($cafiles as $filename) { |
|
149 | + if (\file_exists($filename)) { |
|
150 | + return $cached = $filename; |
|
151 | + } |
|
152 | + } |
|
153 | + throw new \RuntimeException(<<<EOT |
|
154 | 154 | No system CA bundle could be found in any of the the common system locations. |
155 | 155 | PHP versions earlier than 5.6 are not properly configured to use the system's |
156 | 156 | CA bundle by default. In order to verify peer certificates, you will need to |
@@ -164,176 +164,176 @@ discard block |
||
164 | 164 | https://curl.haxx.se/docs/sslcerts.html for more information. |
165 | 165 | EOT |
166 | 166 | ); |
167 | - } |
|
168 | - /** |
|
169 | - * Creates an associative array of lowercase header names to the actual |
|
170 | - * header casing. |
|
171 | - */ |
|
172 | - public static function normalizeHeaderKeys(array $headers) : array |
|
173 | - { |
|
174 | - $result = []; |
|
175 | - foreach (\array_keys($headers) as $key) { |
|
176 | - $result[\strtolower($key)] = $key; |
|
177 | - } |
|
178 | - return $result; |
|
179 | - } |
|
180 | - /** |
|
181 | - * Returns true if the provided host matches any of the no proxy areas. |
|
182 | - * |
|
183 | - * This method will strip a port from the host if it is present. Each pattern |
|
184 | - * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a |
|
185 | - * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" == |
|
186 | - * "baz.foo.com", but ".foo.com" != "foo.com"). |
|
187 | - * |
|
188 | - * Areas are matched in the following cases: |
|
189 | - * 1. "*" (without quotes) always matches any hosts. |
|
190 | - * 2. An exact match. |
|
191 | - * 3. The area starts with "." and the area is the last part of the host. e.g. |
|
192 | - * '.mit.edu' will match any host that ends with '.mit.edu'. |
|
193 | - * |
|
194 | - * @param string $host Host to check against the patterns. |
|
195 | - * @param string[] $noProxyArray An array of host patterns. |
|
196 | - * |
|
197 | - * @throws InvalidArgumentException |
|
198 | - */ |
|
199 | - public static function isHostInNoProxy(string $host, array $noProxyArray) : bool |
|
200 | - { |
|
201 | - if (\strlen($host) === 0) { |
|
202 | - throw new InvalidArgumentException('Empty host provided'); |
|
203 | - } |
|
204 | - // Strip port if present. |
|
205 | - [$host] = \explode(':', $host, 2); |
|
206 | - foreach ($noProxyArray as $area) { |
|
207 | - // Always match on wildcards. |
|
208 | - if ($area === '*') { |
|
209 | - return \true; |
|
210 | - } |
|
211 | - if (empty($area)) { |
|
212 | - // Don't match on empty values. |
|
213 | - continue; |
|
214 | - } |
|
215 | - if ($area === $host) { |
|
216 | - // Exact matches. |
|
217 | - return \true; |
|
218 | - } |
|
219 | - // Special match if the area when prefixed with ".". Remove any |
|
220 | - // existing leading "." and add a new leading ".". |
|
221 | - $area = '.' . \ltrim($area, '.'); |
|
222 | - if (\substr($host, -\strlen($area)) === $area) { |
|
223 | - return \true; |
|
224 | - } |
|
225 | - } |
|
226 | - return \false; |
|
227 | - } |
|
228 | - /** |
|
229 | - * Wrapper for json_decode that throws when an error occurs. |
|
230 | - * |
|
231 | - * @param string $json JSON data to parse |
|
232 | - * @param bool $assoc When true, returned objects will be converted |
|
233 | - * into associative arrays. |
|
234 | - * @param int $depth User specified recursion depth. |
|
235 | - * @param int $options Bitmask of JSON decode options. |
|
236 | - * |
|
237 | - * @return object|array|string|int|float|bool|null |
|
238 | - * |
|
239 | - * @throws InvalidArgumentException if the JSON cannot be decoded. |
|
240 | - * |
|
241 | - * @see https://www.php.net/manual/en/function.json-decode.php |
|
242 | - */ |
|
243 | - public static function jsonDecode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0) |
|
244 | - { |
|
245 | - $data = \json_decode($json, $assoc, $depth, $options); |
|
246 | - if (\JSON_ERROR_NONE !== \json_last_error()) { |
|
247 | - throw new InvalidArgumentException('json_decode error: ' . \json_last_error_msg()); |
|
248 | - } |
|
249 | - return $data; |
|
250 | - } |
|
251 | - /** |
|
252 | - * Wrapper for JSON encoding that throws when an error occurs. |
|
253 | - * |
|
254 | - * @param mixed $value The value being encoded |
|
255 | - * @param int $options JSON encode option bitmask |
|
256 | - * @param int $depth Set the maximum depth. Must be greater than zero. |
|
257 | - * |
|
258 | - * @throws InvalidArgumentException if the JSON cannot be encoded. |
|
259 | - * |
|
260 | - * @see https://www.php.net/manual/en/function.json-encode.php |
|
261 | - */ |
|
262 | - public static function jsonEncode($value, int $options = 0, int $depth = 512) : string |
|
263 | - { |
|
264 | - $json = \json_encode($value, $options, $depth); |
|
265 | - if (\JSON_ERROR_NONE !== \json_last_error()) { |
|
266 | - throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg()); |
|
267 | - } |
|
268 | - /** @var string */ |
|
269 | - return $json; |
|
270 | - } |
|
271 | - /** |
|
272 | - * Wrapper for the hrtime() or microtime() functions |
|
273 | - * (depending on the PHP version, one of the two is used) |
|
274 | - * |
|
275 | - * @return float UNIX timestamp |
|
276 | - * |
|
277 | - * @internal |
|
278 | - */ |
|
279 | - public static function currentTime() : float |
|
280 | - { |
|
281 | - return (float) \function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true); |
|
282 | - } |
|
283 | - /** |
|
284 | - * @throws InvalidArgumentException |
|
285 | - * |
|
286 | - * @internal |
|
287 | - */ |
|
288 | - public static function idnUriConvert(UriInterface $uri, int $options = 0) : UriInterface |
|
289 | - { |
|
290 | - if ($uri->getHost()) { |
|
291 | - $asciiHost = self::idnToAsci($uri->getHost(), $options, $info); |
|
292 | - if ($asciiHost === \false) { |
|
293 | - $errorBitSet = $info['errors'] ?? 0; |
|
294 | - $errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function (string $name) : bool { |
|
295 | - return \substr($name, 0, 11) === 'IDNA_ERROR_'; |
|
296 | - }); |
|
297 | - $errors = []; |
|
298 | - foreach ($errorConstants as $errorConstant) { |
|
299 | - if ($errorBitSet & \constant($errorConstant)) { |
|
300 | - $errors[] = $errorConstant; |
|
301 | - } |
|
302 | - } |
|
303 | - $errorMessage = 'IDN conversion failed'; |
|
304 | - if ($errors) { |
|
305 | - $errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')'; |
|
306 | - } |
|
307 | - throw new InvalidArgumentException($errorMessage); |
|
308 | - } |
|
309 | - if ($uri->getHost() !== $asciiHost) { |
|
310 | - // Replace URI only if the ASCII version is different |
|
311 | - $uri = $uri->withHost($asciiHost); |
|
312 | - } |
|
313 | - } |
|
314 | - return $uri; |
|
315 | - } |
|
316 | - /** |
|
317 | - * @internal |
|
318 | - */ |
|
319 | - public static function getenv(string $name) : ?string |
|
320 | - { |
|
321 | - if (isset($_SERVER[$name])) { |
|
322 | - return (string) $_SERVER[$name]; |
|
323 | - } |
|
324 | - if (\PHP_SAPI === 'cli' && ($value = \getenv($name)) !== \false && $value !== null) { |
|
325 | - return (string) $value; |
|
326 | - } |
|
327 | - return null; |
|
328 | - } |
|
329 | - /** |
|
330 | - * @return string|false |
|
331 | - */ |
|
332 | - private static function idnToAsci(string $domain, int $options, ?array &$info = []) |
|
333 | - { |
|
334 | - if (\function_exists('idn_to_ascii') && \defined('INTL_IDNA_VARIANT_UTS46')) { |
|
335 | - return \idn_to_ascii($domain, $options, \INTL_IDNA_VARIANT_UTS46, $info); |
|
336 | - } |
|
337 | - throw new \Error('ext-idn or symfony/polyfill-intl-idn not loaded or too old'); |
|
338 | - } |
|
167 | + } |
|
168 | + /** |
|
169 | + * Creates an associative array of lowercase header names to the actual |
|
170 | + * header casing. |
|
171 | + */ |
|
172 | + public static function normalizeHeaderKeys(array $headers) : array |
|
173 | + { |
|
174 | + $result = []; |
|
175 | + foreach (\array_keys($headers) as $key) { |
|
176 | + $result[\strtolower($key)] = $key; |
|
177 | + } |
|
178 | + return $result; |
|
179 | + } |
|
180 | + /** |
|
181 | + * Returns true if the provided host matches any of the no proxy areas. |
|
182 | + * |
|
183 | + * This method will strip a port from the host if it is present. Each pattern |
|
184 | + * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a |
|
185 | + * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" == |
|
186 | + * "baz.foo.com", but ".foo.com" != "foo.com"). |
|
187 | + * |
|
188 | + * Areas are matched in the following cases: |
|
189 | + * 1. "*" (without quotes) always matches any hosts. |
|
190 | + * 2. An exact match. |
|
191 | + * 3. The area starts with "." and the area is the last part of the host. e.g. |
|
192 | + * '.mit.edu' will match any host that ends with '.mit.edu'. |
|
193 | + * |
|
194 | + * @param string $host Host to check against the patterns. |
|
195 | + * @param string[] $noProxyArray An array of host patterns. |
|
196 | + * |
|
197 | + * @throws InvalidArgumentException |
|
198 | + */ |
|
199 | + public static function isHostInNoProxy(string $host, array $noProxyArray) : bool |
|
200 | + { |
|
201 | + if (\strlen($host) === 0) { |
|
202 | + throw new InvalidArgumentException('Empty host provided'); |
|
203 | + } |
|
204 | + // Strip port if present. |
|
205 | + [$host] = \explode(':', $host, 2); |
|
206 | + foreach ($noProxyArray as $area) { |
|
207 | + // Always match on wildcards. |
|
208 | + if ($area === '*') { |
|
209 | + return \true; |
|
210 | + } |
|
211 | + if (empty($area)) { |
|
212 | + // Don't match on empty values. |
|
213 | + continue; |
|
214 | + } |
|
215 | + if ($area === $host) { |
|
216 | + // Exact matches. |
|
217 | + return \true; |
|
218 | + } |
|
219 | + // Special match if the area when prefixed with ".". Remove any |
|
220 | + // existing leading "." and add a new leading ".". |
|
221 | + $area = '.' . \ltrim($area, '.'); |
|
222 | + if (\substr($host, -\strlen($area)) === $area) { |
|
223 | + return \true; |
|
224 | + } |
|
225 | + } |
|
226 | + return \false; |
|
227 | + } |
|
228 | + /** |
|
229 | + * Wrapper for json_decode that throws when an error occurs. |
|
230 | + * |
|
231 | + * @param string $json JSON data to parse |
|
232 | + * @param bool $assoc When true, returned objects will be converted |
|
233 | + * into associative arrays. |
|
234 | + * @param int $depth User specified recursion depth. |
|
235 | + * @param int $options Bitmask of JSON decode options. |
|
236 | + * |
|
237 | + * @return object|array|string|int|float|bool|null |
|
238 | + * |
|
239 | + * @throws InvalidArgumentException if the JSON cannot be decoded. |
|
240 | + * |
|
241 | + * @see https://www.php.net/manual/en/function.json-decode.php |
|
242 | + */ |
|
243 | + public static function jsonDecode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0) |
|
244 | + { |
|
245 | + $data = \json_decode($json, $assoc, $depth, $options); |
|
246 | + if (\JSON_ERROR_NONE !== \json_last_error()) { |
|
247 | + throw new InvalidArgumentException('json_decode error: ' . \json_last_error_msg()); |
|
248 | + } |
|
249 | + return $data; |
|
250 | + } |
|
251 | + /** |
|
252 | + * Wrapper for JSON encoding that throws when an error occurs. |
|
253 | + * |
|
254 | + * @param mixed $value The value being encoded |
|
255 | + * @param int $options JSON encode option bitmask |
|
256 | + * @param int $depth Set the maximum depth. Must be greater than zero. |
|
257 | + * |
|
258 | + * @throws InvalidArgumentException if the JSON cannot be encoded. |
|
259 | + * |
|
260 | + * @see https://www.php.net/manual/en/function.json-encode.php |
|
261 | + */ |
|
262 | + public static function jsonEncode($value, int $options = 0, int $depth = 512) : string |
|
263 | + { |
|
264 | + $json = \json_encode($value, $options, $depth); |
|
265 | + if (\JSON_ERROR_NONE !== \json_last_error()) { |
|
266 | + throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg()); |
|
267 | + } |
|
268 | + /** @var string */ |
|
269 | + return $json; |
|
270 | + } |
|
271 | + /** |
|
272 | + * Wrapper for the hrtime() or microtime() functions |
|
273 | + * (depending on the PHP version, one of the two is used) |
|
274 | + * |
|
275 | + * @return float UNIX timestamp |
|
276 | + * |
|
277 | + * @internal |
|
278 | + */ |
|
279 | + public static function currentTime() : float |
|
280 | + { |
|
281 | + return (float) \function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true); |
|
282 | + } |
|
283 | + /** |
|
284 | + * @throws InvalidArgumentException |
|
285 | + * |
|
286 | + * @internal |
|
287 | + */ |
|
288 | + public static function idnUriConvert(UriInterface $uri, int $options = 0) : UriInterface |
|
289 | + { |
|
290 | + if ($uri->getHost()) { |
|
291 | + $asciiHost = self::idnToAsci($uri->getHost(), $options, $info); |
|
292 | + if ($asciiHost === \false) { |
|
293 | + $errorBitSet = $info['errors'] ?? 0; |
|
294 | + $errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function (string $name) : bool { |
|
295 | + return \substr($name, 0, 11) === 'IDNA_ERROR_'; |
|
296 | + }); |
|
297 | + $errors = []; |
|
298 | + foreach ($errorConstants as $errorConstant) { |
|
299 | + if ($errorBitSet & \constant($errorConstant)) { |
|
300 | + $errors[] = $errorConstant; |
|
301 | + } |
|
302 | + } |
|
303 | + $errorMessage = 'IDN conversion failed'; |
|
304 | + if ($errors) { |
|
305 | + $errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')'; |
|
306 | + } |
|
307 | + throw new InvalidArgumentException($errorMessage); |
|
308 | + } |
|
309 | + if ($uri->getHost() !== $asciiHost) { |
|
310 | + // Replace URI only if the ASCII version is different |
|
311 | + $uri = $uri->withHost($asciiHost); |
|
312 | + } |
|
313 | + } |
|
314 | + return $uri; |
|
315 | + } |
|
316 | + /** |
|
317 | + * @internal |
|
318 | + */ |
|
319 | + public static function getenv(string $name) : ?string |
|
320 | + { |
|
321 | + if (isset($_SERVER[$name])) { |
|
322 | + return (string) $_SERVER[$name]; |
|
323 | + } |
|
324 | + if (\PHP_SAPI === 'cli' && ($value = \getenv($name)) !== \false && $value !== null) { |
|
325 | + return (string) $value; |
|
326 | + } |
|
327 | + return null; |
|
328 | + } |
|
329 | + /** |
|
330 | + * @return string|false |
|
331 | + */ |
|
332 | + private static function idnToAsci(string $domain, int $options, ?array &$info = []) |
|
333 | + { |
|
334 | + if (\function_exists('idn_to_ascii') && \defined('INTL_IDNA_VARIANT_UTS46')) { |
|
335 | + return \idn_to_ascii($domain, $options, \INTL_IDNA_VARIANT_UTS46, $info); |
|
336 | + } |
|
337 | + throw new \Error('ext-idn or symfony/polyfill-intl-idn not loaded or too old'); |
|
338 | + } |
|
339 | 339 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | { |
23 | 23 | switch (\gettype($input)) { |
24 | 24 | case 'object': |
25 | - return 'object(' . \get_class($input) . ')'; |
|
25 | + return 'object('.\get_class($input).')'; |
|
26 | 26 | case 'array': |
27 | - return 'array(' . \count($input) . ')'; |
|
27 | + return 'array('.\count($input).')'; |
|
28 | 28 | default: |
29 | 29 | \ob_start(); |
30 | 30 | \var_dump($input); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | // Special match if the area when prefixed with ".". Remove any |
220 | 220 | // existing leading "." and add a new leading ".". |
221 | - $area = '.' . \ltrim($area, '.'); |
|
221 | + $area = '.'.\ltrim($area, '.'); |
|
222 | 222 | if (\substr($host, -\strlen($area)) === $area) { |
223 | 223 | return \true; |
224 | 224 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | { |
245 | 245 | $data = \json_decode($json, $assoc, $depth, $options); |
246 | 246 | if (\JSON_ERROR_NONE !== \json_last_error()) { |
247 | - throw new InvalidArgumentException('json_decode error: ' . \json_last_error_msg()); |
|
247 | + throw new InvalidArgumentException('json_decode error: '.\json_last_error_msg()); |
|
248 | 248 | } |
249 | 249 | return $data; |
250 | 250 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | { |
264 | 264 | $json = \json_encode($value, $options, $depth); |
265 | 265 | if (\JSON_ERROR_NONE !== \json_last_error()) { |
266 | - throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg()); |
|
266 | + throw new InvalidArgumentException('json_encode error: '.\json_last_error_msg()); |
|
267 | 267 | } |
268 | 268 | /** @var string */ |
269 | 269 | return $json; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public static function currentTime() : float |
280 | 280 | { |
281 | - return (float) \function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true); |
|
281 | + return (float)\function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true); |
|
282 | 282 | } |
283 | 283 | /** |
284 | 284 | * @throws InvalidArgumentException |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $asciiHost = self::idnToAsci($uri->getHost(), $options, $info); |
292 | 292 | if ($asciiHost === \false) { |
293 | 293 | $errorBitSet = $info['errors'] ?? 0; |
294 | - $errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function (string $name) : bool { |
|
294 | + $errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function(string $name) : bool { |
|
295 | 295 | return \substr($name, 0, 11) === 'IDNA_ERROR_'; |
296 | 296 | }); |
297 | 297 | $errors = []; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | $errorMessage = 'IDN conversion failed'; |
304 | 304 | if ($errors) { |
305 | - $errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')'; |
|
305 | + $errorMessage .= ' (errors: '.\implode(', ', $errors).')'; |
|
306 | 306 | } |
307 | 307 | throw new InvalidArgumentException($errorMessage); |
308 | 308 | } |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | public static function getenv(string $name) : ?string |
320 | 320 | { |
321 | 321 | if (isset($_SERVER[$name])) { |
322 | - return (string) $_SERVER[$name]; |
|
322 | + return (string)$_SERVER[$name]; |
|
323 | 323 | } |
324 | 324 | if (\PHP_SAPI === 'cli' && ($value = \getenv($name)) !== \false && $value !== null) { |
325 | - return (string) $value; |
|
325 | + return (string)$value; |
|
326 | 326 | } |
327 | 327 | return null; |
328 | 328 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | use OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Handler\Proxy; |
9 | 9 | use OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Handler\StreamHandler; |
10 | 10 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\UriInterface; |
11 | -final class Utils |
|
12 | -{ |
|
11 | +final class Utils { |
|
13 | 12 | /** |
14 | 13 | * Debug function used to describe the provided value type and class. |
15 | 14 | * |
@@ -40,202 +40,202 @@ |
||
40 | 40 | */ |
41 | 41 | class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface |
42 | 42 | { |
43 | - private $requestFactory; |
|
44 | - private $responseFactory; |
|
45 | - private $serverRequestFactory; |
|
46 | - private $streamFactory; |
|
47 | - private $uploadedFileFactory; |
|
48 | - private $uriFactory; |
|
49 | - public function __construct(?RequestFactoryInterface $requestFactory = null, ?ResponseFactoryInterface $responseFactory = null, ?ServerRequestFactoryInterface $serverRequestFactory = null, ?StreamFactoryInterface $streamFactory = null, ?UploadedFileFactoryInterface $uploadedFileFactory = null, ?UriFactoryInterface $uriFactory = null) |
|
50 | - { |
|
51 | - $this->requestFactory = $requestFactory; |
|
52 | - $this->responseFactory = $responseFactory; |
|
53 | - $this->serverRequestFactory = $serverRequestFactory; |
|
54 | - $this->streamFactory = $streamFactory; |
|
55 | - $this->uploadedFileFactory = $uploadedFileFactory; |
|
56 | - $this->uriFactory = $uriFactory; |
|
57 | - $this->setFactory($requestFactory); |
|
58 | - $this->setFactory($responseFactory); |
|
59 | - $this->setFactory($serverRequestFactory); |
|
60 | - $this->setFactory($streamFactory); |
|
61 | - $this->setFactory($uploadedFileFactory); |
|
62 | - $this->setFactory($uriFactory); |
|
63 | - } |
|
64 | - /** |
|
65 | - * @param UriInterface|string $uri |
|
66 | - */ |
|
67 | - public function createRequest(string $method, $uri) : RequestInterface |
|
68 | - { |
|
69 | - $factory = $this->requestFactory ?? $this->setFactory(Psr17FactoryDiscovery::findRequestFactory()); |
|
70 | - return $factory->createRequest(...\func_get_args()); |
|
71 | - } |
|
72 | - public function createResponse(int $code = 200, string $reasonPhrase = '') : ResponseInterface |
|
73 | - { |
|
74 | - $factory = $this->responseFactory ?? $this->setFactory(Psr17FactoryDiscovery::findResponseFactory()); |
|
75 | - return $factory->createResponse(...\func_get_args()); |
|
76 | - } |
|
77 | - /** |
|
78 | - * @param UriInterface|string $uri |
|
79 | - */ |
|
80 | - public function createServerRequest(string $method, $uri, array $serverParams = []) : ServerRequestInterface |
|
81 | - { |
|
82 | - $factory = $this->serverRequestFactory ?? $this->setFactory(Psr17FactoryDiscovery::findServerRequestFactory()); |
|
83 | - return $factory->createServerRequest(...\func_get_args()); |
|
84 | - } |
|
85 | - public function createServerRequestFromGlobals(?array $server = null, ?array $get = null, ?array $post = null, ?array $cookie = null, ?array $files = null, ?StreamInterface $body = null) : ServerRequestInterface |
|
86 | - { |
|
87 | - $server = $server ?? $_SERVER; |
|
88 | - $request = $this->createServerRequest($server['REQUEST_METHOD'] ?? 'GET', $this->createUriFromGlobals($server), $server); |
|
89 | - return $this->buildServerRequestFromGlobals($request, $server, $files ?? $_FILES)->withQueryParams($get ?? $_GET)->withParsedBody($post ?? $_POST)->withCookieParams($cookie ?? $_COOKIE)->withBody($body ?? $this->createStreamFromFile('php://input', 'r+')); |
|
90 | - } |
|
91 | - public function createStream(string $content = '') : StreamInterface |
|
92 | - { |
|
93 | - $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
94 | - return $factory->createStream($content); |
|
95 | - } |
|
96 | - public function createStreamFromFile(string $filename, string $mode = 'r') : StreamInterface |
|
97 | - { |
|
98 | - $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
99 | - return $factory->createStreamFromFile($filename, $mode); |
|
100 | - } |
|
101 | - /** |
|
102 | - * @param resource $resource |
|
103 | - */ |
|
104 | - public function createStreamFromResource($resource) : StreamInterface |
|
105 | - { |
|
106 | - $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
107 | - return $factory->createStreamFromResource($resource); |
|
108 | - } |
|
109 | - public function createUploadedFile(StreamInterface $stream, ?int $size = null, int $error = \UPLOAD_ERR_OK, ?string $clientFilename = null, ?string $clientMediaType = null) : UploadedFileInterface |
|
110 | - { |
|
111 | - $factory = $this->uploadedFileFactory ?? $this->setFactory(Psr17FactoryDiscovery::findUploadedFileFactory()); |
|
112 | - return $factory->createUploadedFile(...\func_get_args()); |
|
113 | - } |
|
114 | - public function createUri(string $uri = '') : UriInterface |
|
115 | - { |
|
116 | - $factory = $this->uriFactory ?? $this->setFactory(Psr17FactoryDiscovery::findUriFactory()); |
|
117 | - return $factory->createUri(...\func_get_args()); |
|
118 | - } |
|
119 | - public function createUriFromGlobals(?array $server = null) : UriInterface |
|
120 | - { |
|
121 | - return $this->buildUriFromGlobals($this->createUri(''), $server ?? $_SERVER); |
|
122 | - } |
|
123 | - private function setFactory($factory) |
|
124 | - { |
|
125 | - if (!$this->requestFactory && $factory instanceof RequestFactoryInterface) { |
|
126 | - $this->requestFactory = $factory; |
|
127 | - } |
|
128 | - if (!$this->responseFactory && $factory instanceof ResponseFactoryInterface) { |
|
129 | - $this->responseFactory = $factory; |
|
130 | - } |
|
131 | - if (!$this->serverRequestFactory && $factory instanceof ServerRequestFactoryInterface) { |
|
132 | - $this->serverRequestFactory = $factory; |
|
133 | - } |
|
134 | - if (!$this->streamFactory && $factory instanceof StreamFactoryInterface) { |
|
135 | - $this->streamFactory = $factory; |
|
136 | - } |
|
137 | - if (!$this->uploadedFileFactory && $factory instanceof UploadedFileFactoryInterface) { |
|
138 | - $this->uploadedFileFactory = $factory; |
|
139 | - } |
|
140 | - if (!$this->uriFactory && $factory instanceof UriFactoryInterface) { |
|
141 | - $this->uriFactory = $factory; |
|
142 | - } |
|
143 | - return $factory; |
|
144 | - } |
|
145 | - private function buildServerRequestFromGlobals(ServerRequestInterface $request, array $server, array $files) : ServerRequestInterface |
|
146 | - { |
|
147 | - $request = $request->withProtocolVersion(isset($server['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $server['SERVER_PROTOCOL']) : '1.1')->withUploadedFiles($this->normalizeFiles($files)); |
|
148 | - $headers = []; |
|
149 | - foreach ($server as $k => $v) { |
|
150 | - if (0 === \strpos($k, 'HTTP_')) { |
|
151 | - $k = \substr($k, 5); |
|
152 | - } elseif (!\in_array($k, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], \true)) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - $k = \str_replace(' ', '-', \ucwords(\strtolower(\str_replace('_', ' ', $k)))); |
|
156 | - $headers[$k] = $v; |
|
157 | - } |
|
158 | - if (!isset($headers['Authorization'])) { |
|
159 | - if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { |
|
160 | - $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; |
|
161 | - } elseif (isset($_SERVER['PHP_AUTH_USER'])) { |
|
162 | - $headers['Authorization'] = 'Basic ' . \base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . ($_SERVER['PHP_AUTH_PW'] ?? '')); |
|
163 | - } elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) { |
|
164 | - $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; |
|
165 | - } |
|
166 | - } |
|
167 | - foreach ($headers as $k => $v) { |
|
168 | - try { |
|
169 | - $request = $request->withHeader($k, $v); |
|
170 | - } catch (\InvalidArgumentException $e) { |
|
171 | - // ignore invalid headers |
|
172 | - } |
|
173 | - } |
|
174 | - return $request; |
|
175 | - } |
|
176 | - private function buildUriFromGlobals(UriInterface $uri, array $server) : UriInterface |
|
177 | - { |
|
178 | - $uri = $uri->withScheme(!empty($server['HTTPS']) && 'off' !== \strtolower($server['HTTPS']) ? 'https' : 'http'); |
|
179 | - $hasPort = \false; |
|
180 | - if (isset($server['HTTP_HOST'])) { |
|
181 | - $parts = \parse_url('http://' . $server['HTTP_HOST']); |
|
182 | - $uri = $uri->withHost($parts['host'] ?? 'localhost'); |
|
183 | - if ($parts['port'] ?? \false) { |
|
184 | - $hasPort = \true; |
|
185 | - $uri = $uri->withPort($parts['port']); |
|
186 | - } |
|
187 | - } else { |
|
188 | - $uri = $uri->withHost($server['SERVER_NAME'] ?? $server['SERVER_ADDR'] ?? 'localhost'); |
|
189 | - } |
|
190 | - if (!$hasPort && isset($server['SERVER_PORT'])) { |
|
191 | - $uri = $uri->withPort($server['SERVER_PORT']); |
|
192 | - } |
|
193 | - $hasQuery = \false; |
|
194 | - if (isset($server['REQUEST_URI'])) { |
|
195 | - $requestUriParts = \explode('?', $server['REQUEST_URI'], 2); |
|
196 | - $uri = $uri->withPath($requestUriParts[0]); |
|
197 | - if (isset($requestUriParts[1])) { |
|
198 | - $hasQuery = \true; |
|
199 | - $uri = $uri->withQuery($requestUriParts[1]); |
|
200 | - } |
|
201 | - } |
|
202 | - if (!$hasQuery && isset($server['QUERY_STRING'])) { |
|
203 | - $uri = $uri->withQuery($server['QUERY_STRING']); |
|
204 | - } |
|
205 | - return $uri; |
|
206 | - } |
|
207 | - private function normalizeFiles(array $files) : array |
|
208 | - { |
|
209 | - foreach ($files as $k => $v) { |
|
210 | - if ($v instanceof UploadedFileInterface) { |
|
211 | - continue; |
|
212 | - } |
|
213 | - if (!\is_array($v)) { |
|
214 | - unset($files[$k]); |
|
215 | - } elseif (!isset($v['tmp_name'])) { |
|
216 | - $files[$k] = $this->normalizeFiles($v); |
|
217 | - } else { |
|
218 | - $files[$k] = $this->createUploadedFileFromSpec($v); |
|
219 | - } |
|
220 | - } |
|
221 | - return $files; |
|
222 | - } |
|
223 | - /** |
|
224 | - * Create and return an UploadedFile instance from a $_FILES specification. |
|
225 | - * |
|
226 | - * @param array $value $_FILES struct |
|
227 | - * |
|
228 | - * @return UploadedFileInterface|UploadedFileInterface[] |
|
229 | - */ |
|
230 | - private function createUploadedFileFromSpec(array $value) |
|
231 | - { |
|
232 | - if (!\is_array($tmpName = $value['tmp_name'])) { |
|
233 | - $file = \is_file($tmpName) ? $this->createStreamFromFile($tmpName, 'r') : $this->createStream(); |
|
234 | - return $this->createUploadedFile($file, $value['size'], $value['error'], $value['name'], $value['type']); |
|
235 | - } |
|
236 | - foreach ($tmpName as $k => $v) { |
|
237 | - $tmpName[$k] = $this->createUploadedFileFromSpec(['tmp_name' => $v, 'size' => $value['size'][$k] ?? null, 'error' => $value['error'][$k] ?? null, 'name' => $value['name'][$k] ?? null, 'type' => $value['type'][$k] ?? null]); |
|
238 | - } |
|
239 | - return $tmpName; |
|
240 | - } |
|
43 | + private $requestFactory; |
|
44 | + private $responseFactory; |
|
45 | + private $serverRequestFactory; |
|
46 | + private $streamFactory; |
|
47 | + private $uploadedFileFactory; |
|
48 | + private $uriFactory; |
|
49 | + public function __construct(?RequestFactoryInterface $requestFactory = null, ?ResponseFactoryInterface $responseFactory = null, ?ServerRequestFactoryInterface $serverRequestFactory = null, ?StreamFactoryInterface $streamFactory = null, ?UploadedFileFactoryInterface $uploadedFileFactory = null, ?UriFactoryInterface $uriFactory = null) |
|
50 | + { |
|
51 | + $this->requestFactory = $requestFactory; |
|
52 | + $this->responseFactory = $responseFactory; |
|
53 | + $this->serverRequestFactory = $serverRequestFactory; |
|
54 | + $this->streamFactory = $streamFactory; |
|
55 | + $this->uploadedFileFactory = $uploadedFileFactory; |
|
56 | + $this->uriFactory = $uriFactory; |
|
57 | + $this->setFactory($requestFactory); |
|
58 | + $this->setFactory($responseFactory); |
|
59 | + $this->setFactory($serverRequestFactory); |
|
60 | + $this->setFactory($streamFactory); |
|
61 | + $this->setFactory($uploadedFileFactory); |
|
62 | + $this->setFactory($uriFactory); |
|
63 | + } |
|
64 | + /** |
|
65 | + * @param UriInterface|string $uri |
|
66 | + */ |
|
67 | + public function createRequest(string $method, $uri) : RequestInterface |
|
68 | + { |
|
69 | + $factory = $this->requestFactory ?? $this->setFactory(Psr17FactoryDiscovery::findRequestFactory()); |
|
70 | + return $factory->createRequest(...\func_get_args()); |
|
71 | + } |
|
72 | + public function createResponse(int $code = 200, string $reasonPhrase = '') : ResponseInterface |
|
73 | + { |
|
74 | + $factory = $this->responseFactory ?? $this->setFactory(Psr17FactoryDiscovery::findResponseFactory()); |
|
75 | + return $factory->createResponse(...\func_get_args()); |
|
76 | + } |
|
77 | + /** |
|
78 | + * @param UriInterface|string $uri |
|
79 | + */ |
|
80 | + public function createServerRequest(string $method, $uri, array $serverParams = []) : ServerRequestInterface |
|
81 | + { |
|
82 | + $factory = $this->serverRequestFactory ?? $this->setFactory(Psr17FactoryDiscovery::findServerRequestFactory()); |
|
83 | + return $factory->createServerRequest(...\func_get_args()); |
|
84 | + } |
|
85 | + public function createServerRequestFromGlobals(?array $server = null, ?array $get = null, ?array $post = null, ?array $cookie = null, ?array $files = null, ?StreamInterface $body = null) : ServerRequestInterface |
|
86 | + { |
|
87 | + $server = $server ?? $_SERVER; |
|
88 | + $request = $this->createServerRequest($server['REQUEST_METHOD'] ?? 'GET', $this->createUriFromGlobals($server), $server); |
|
89 | + return $this->buildServerRequestFromGlobals($request, $server, $files ?? $_FILES)->withQueryParams($get ?? $_GET)->withParsedBody($post ?? $_POST)->withCookieParams($cookie ?? $_COOKIE)->withBody($body ?? $this->createStreamFromFile('php://input', 'r+')); |
|
90 | + } |
|
91 | + public function createStream(string $content = '') : StreamInterface |
|
92 | + { |
|
93 | + $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
94 | + return $factory->createStream($content); |
|
95 | + } |
|
96 | + public function createStreamFromFile(string $filename, string $mode = 'r') : StreamInterface |
|
97 | + { |
|
98 | + $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
99 | + return $factory->createStreamFromFile($filename, $mode); |
|
100 | + } |
|
101 | + /** |
|
102 | + * @param resource $resource |
|
103 | + */ |
|
104 | + public function createStreamFromResource($resource) : StreamInterface |
|
105 | + { |
|
106 | + $factory = $this->streamFactory ?? $this->setFactory(Psr17FactoryDiscovery::findStreamFactory()); |
|
107 | + return $factory->createStreamFromResource($resource); |
|
108 | + } |
|
109 | + public function createUploadedFile(StreamInterface $stream, ?int $size = null, int $error = \UPLOAD_ERR_OK, ?string $clientFilename = null, ?string $clientMediaType = null) : UploadedFileInterface |
|
110 | + { |
|
111 | + $factory = $this->uploadedFileFactory ?? $this->setFactory(Psr17FactoryDiscovery::findUploadedFileFactory()); |
|
112 | + return $factory->createUploadedFile(...\func_get_args()); |
|
113 | + } |
|
114 | + public function createUri(string $uri = '') : UriInterface |
|
115 | + { |
|
116 | + $factory = $this->uriFactory ?? $this->setFactory(Psr17FactoryDiscovery::findUriFactory()); |
|
117 | + return $factory->createUri(...\func_get_args()); |
|
118 | + } |
|
119 | + public function createUriFromGlobals(?array $server = null) : UriInterface |
|
120 | + { |
|
121 | + return $this->buildUriFromGlobals($this->createUri(''), $server ?? $_SERVER); |
|
122 | + } |
|
123 | + private function setFactory($factory) |
|
124 | + { |
|
125 | + if (!$this->requestFactory && $factory instanceof RequestFactoryInterface) { |
|
126 | + $this->requestFactory = $factory; |
|
127 | + } |
|
128 | + if (!$this->responseFactory && $factory instanceof ResponseFactoryInterface) { |
|
129 | + $this->responseFactory = $factory; |
|
130 | + } |
|
131 | + if (!$this->serverRequestFactory && $factory instanceof ServerRequestFactoryInterface) { |
|
132 | + $this->serverRequestFactory = $factory; |
|
133 | + } |
|
134 | + if (!$this->streamFactory && $factory instanceof StreamFactoryInterface) { |
|
135 | + $this->streamFactory = $factory; |
|
136 | + } |
|
137 | + if (!$this->uploadedFileFactory && $factory instanceof UploadedFileFactoryInterface) { |
|
138 | + $this->uploadedFileFactory = $factory; |
|
139 | + } |
|
140 | + if (!$this->uriFactory && $factory instanceof UriFactoryInterface) { |
|
141 | + $this->uriFactory = $factory; |
|
142 | + } |
|
143 | + return $factory; |
|
144 | + } |
|
145 | + private function buildServerRequestFromGlobals(ServerRequestInterface $request, array $server, array $files) : ServerRequestInterface |
|
146 | + { |
|
147 | + $request = $request->withProtocolVersion(isset($server['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $server['SERVER_PROTOCOL']) : '1.1')->withUploadedFiles($this->normalizeFiles($files)); |
|
148 | + $headers = []; |
|
149 | + foreach ($server as $k => $v) { |
|
150 | + if (0 === \strpos($k, 'HTTP_')) { |
|
151 | + $k = \substr($k, 5); |
|
152 | + } elseif (!\in_array($k, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], \true)) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + $k = \str_replace(' ', '-', \ucwords(\strtolower(\str_replace('_', ' ', $k)))); |
|
156 | + $headers[$k] = $v; |
|
157 | + } |
|
158 | + if (!isset($headers['Authorization'])) { |
|
159 | + if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { |
|
160 | + $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; |
|
161 | + } elseif (isset($_SERVER['PHP_AUTH_USER'])) { |
|
162 | + $headers['Authorization'] = 'Basic ' . \base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . ($_SERVER['PHP_AUTH_PW'] ?? '')); |
|
163 | + } elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) { |
|
164 | + $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; |
|
165 | + } |
|
166 | + } |
|
167 | + foreach ($headers as $k => $v) { |
|
168 | + try { |
|
169 | + $request = $request->withHeader($k, $v); |
|
170 | + } catch (\InvalidArgumentException $e) { |
|
171 | + // ignore invalid headers |
|
172 | + } |
|
173 | + } |
|
174 | + return $request; |
|
175 | + } |
|
176 | + private function buildUriFromGlobals(UriInterface $uri, array $server) : UriInterface |
|
177 | + { |
|
178 | + $uri = $uri->withScheme(!empty($server['HTTPS']) && 'off' !== \strtolower($server['HTTPS']) ? 'https' : 'http'); |
|
179 | + $hasPort = \false; |
|
180 | + if (isset($server['HTTP_HOST'])) { |
|
181 | + $parts = \parse_url('http://' . $server['HTTP_HOST']); |
|
182 | + $uri = $uri->withHost($parts['host'] ?? 'localhost'); |
|
183 | + if ($parts['port'] ?? \false) { |
|
184 | + $hasPort = \true; |
|
185 | + $uri = $uri->withPort($parts['port']); |
|
186 | + } |
|
187 | + } else { |
|
188 | + $uri = $uri->withHost($server['SERVER_NAME'] ?? $server['SERVER_ADDR'] ?? 'localhost'); |
|
189 | + } |
|
190 | + if (!$hasPort && isset($server['SERVER_PORT'])) { |
|
191 | + $uri = $uri->withPort($server['SERVER_PORT']); |
|
192 | + } |
|
193 | + $hasQuery = \false; |
|
194 | + if (isset($server['REQUEST_URI'])) { |
|
195 | + $requestUriParts = \explode('?', $server['REQUEST_URI'], 2); |
|
196 | + $uri = $uri->withPath($requestUriParts[0]); |
|
197 | + if (isset($requestUriParts[1])) { |
|
198 | + $hasQuery = \true; |
|
199 | + $uri = $uri->withQuery($requestUriParts[1]); |
|
200 | + } |
|
201 | + } |
|
202 | + if (!$hasQuery && isset($server['QUERY_STRING'])) { |
|
203 | + $uri = $uri->withQuery($server['QUERY_STRING']); |
|
204 | + } |
|
205 | + return $uri; |
|
206 | + } |
|
207 | + private function normalizeFiles(array $files) : array |
|
208 | + { |
|
209 | + foreach ($files as $k => $v) { |
|
210 | + if ($v instanceof UploadedFileInterface) { |
|
211 | + continue; |
|
212 | + } |
|
213 | + if (!\is_array($v)) { |
|
214 | + unset($files[$k]); |
|
215 | + } elseif (!isset($v['tmp_name'])) { |
|
216 | + $files[$k] = $this->normalizeFiles($v); |
|
217 | + } else { |
|
218 | + $files[$k] = $this->createUploadedFileFromSpec($v); |
|
219 | + } |
|
220 | + } |
|
221 | + return $files; |
|
222 | + } |
|
223 | + /** |
|
224 | + * Create and return an UploadedFile instance from a $_FILES specification. |
|
225 | + * |
|
226 | + * @param array $value $_FILES struct |
|
227 | + * |
|
228 | + * @return UploadedFileInterface|UploadedFileInterface[] |
|
229 | + */ |
|
230 | + private function createUploadedFileFromSpec(array $value) |
|
231 | + { |
|
232 | + if (!\is_array($tmpName = $value['tmp_name'])) { |
|
233 | + $file = \is_file($tmpName) ? $this->createStreamFromFile($tmpName, 'r') : $this->createStream(); |
|
234 | + return $this->createUploadedFile($file, $value['size'], $value['error'], $value['name'], $value['type']); |
|
235 | + } |
|
236 | + foreach ($tmpName as $k => $v) { |
|
237 | + $tmpName[$k] = $this->createUploadedFileFromSpec(['tmp_name' => $v, 'size' => $value['size'][$k] ?? null, 'error' => $value['error'][$k] ?? null, 'name' => $value['name'][$k] ?? null, 'type' => $value['type'][$k] ?? null]); |
|
238 | + } |
|
239 | + return $tmpName; |
|
240 | + } |
|
241 | 241 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { |
160 | 160 | $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; |
161 | 161 | } elseif (isset($_SERVER['PHP_AUTH_USER'])) { |
162 | - $headers['Authorization'] = 'Basic ' . \base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . ($_SERVER['PHP_AUTH_PW'] ?? '')); |
|
162 | + $headers['Authorization'] = 'Basic '.\base64_encode($_SERVER['PHP_AUTH_USER'].':'.($_SERVER['PHP_AUTH_PW'] ?? '')); |
|
163 | 163 | } elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) { |
164 | 164 | $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; |
165 | 165 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $uri = $uri->withScheme(!empty($server['HTTPS']) && 'off' !== \strtolower($server['HTTPS']) ? 'https' : 'http'); |
179 | 179 | $hasPort = \false; |
180 | 180 | if (isset($server['HTTP_HOST'])) { |
181 | - $parts = \parse_url('http://' . $server['HTTP_HOST']); |
|
181 | + $parts = \parse_url('http://'.$server['HTTP_HOST']); |
|
182 | 182 | $uri = $uri->withHost($parts['host'] ?? 'localhost'); |
183 | 183 | if ($parts['port'] ?? \false) { |
184 | 184 | $hasPort = \true; |
@@ -10,36 +10,36 @@ |
||
10 | 10 | */ |
11 | 11 | final class DiscoveryFailedException extends \Exception implements Exception |
12 | 12 | { |
13 | - /** |
|
14 | - * @var \Exception[] |
|
15 | - */ |
|
16 | - private $exceptions; |
|
17 | - /** |
|
18 | - * @param string $message |
|
19 | - * @param \Exception[] $exceptions |
|
20 | - */ |
|
21 | - public function __construct($message, array $exceptions = []) |
|
22 | - { |
|
23 | - $this->exceptions = $exceptions; |
|
24 | - parent::__construct($message); |
|
25 | - } |
|
26 | - /** |
|
27 | - * @param \Exception[] $exceptions |
|
28 | - */ |
|
29 | - public static function create($exceptions) |
|
30 | - { |
|
31 | - $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; |
|
32 | - foreach ($exceptions as $e) { |
|
33 | - $message .= "\n - " . $e->getMessage(); |
|
34 | - } |
|
35 | - $message .= "\n\n"; |
|
36 | - return new self($message, $exceptions); |
|
37 | - } |
|
38 | - /** |
|
39 | - * @return \Exception[] |
|
40 | - */ |
|
41 | - public function getExceptions() |
|
42 | - { |
|
43 | - return $this->exceptions; |
|
44 | - } |
|
13 | + /** |
|
14 | + * @var \Exception[] |
|
15 | + */ |
|
16 | + private $exceptions; |
|
17 | + /** |
|
18 | + * @param string $message |
|
19 | + * @param \Exception[] $exceptions |
|
20 | + */ |
|
21 | + public function __construct($message, array $exceptions = []) |
|
22 | + { |
|
23 | + $this->exceptions = $exceptions; |
|
24 | + parent::__construct($message); |
|
25 | + } |
|
26 | + /** |
|
27 | + * @param \Exception[] $exceptions |
|
28 | + */ |
|
29 | + public static function create($exceptions) |
|
30 | + { |
|
31 | + $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; |
|
32 | + foreach ($exceptions as $e) { |
|
33 | + $message .= "\n - " . $e->getMessage(); |
|
34 | + } |
|
35 | + $message .= "\n\n"; |
|
36 | + return new self($message, $exceptions); |
|
37 | + } |
|
38 | + /** |
|
39 | + * @return \Exception[] |
|
40 | + */ |
|
41 | + public function getExceptions() |
|
42 | + { |
|
43 | + return $this->exceptions; |
|
44 | + } |
|
45 | 45 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | { |
31 | 31 | $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; |
32 | 32 | foreach ($exceptions as $e) { |
33 | - $message .= "\n - " . $e->getMessage(); |
|
33 | + $message .= "\n - ".$e->getMessage(); |
|
34 | 34 | } |
35 | 35 | $message .= "\n\n"; |
36 | 36 | return new self($message, $exceptions); |
@@ -10,25 +10,25 @@ |
||
10 | 10 | */ |
11 | 11 | final class NoCandidateFoundException extends \Exception implements Exception |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $strategy |
|
15 | - */ |
|
16 | - public function __construct($strategy, array $candidates) |
|
17 | - { |
|
18 | - $classes = \array_map(function ($a) { |
|
19 | - return $a['class']; |
|
20 | - }, $candidates); |
|
21 | - $message = \sprintf('No valid candidate found using strategy "%s". We tested the following candidates: %s.', $strategy, \implode(', ', \array_map([$this, 'stringify'], $classes))); |
|
22 | - parent::__construct($message); |
|
23 | - } |
|
24 | - private function stringify($mixed) |
|
25 | - { |
|
26 | - if (\is_string($mixed)) { |
|
27 | - return $mixed; |
|
28 | - } |
|
29 | - if (\is_array($mixed) && 2 === \count($mixed)) { |
|
30 | - return \sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]); |
|
31 | - } |
|
32 | - return \is_object($mixed) ? \get_class($mixed) : \gettype($mixed); |
|
33 | - } |
|
13 | + /** |
|
14 | + * @param string $strategy |
|
15 | + */ |
|
16 | + public function __construct($strategy, array $candidates) |
|
17 | + { |
|
18 | + $classes = \array_map(function ($a) { |
|
19 | + return $a['class']; |
|
20 | + }, $candidates); |
|
21 | + $message = \sprintf('No valid candidate found using strategy "%s". We tested the following candidates: %s.', $strategy, \implode(', ', \array_map([$this, 'stringify'], $classes))); |
|
22 | + parent::__construct($message); |
|
23 | + } |
|
24 | + private function stringify($mixed) |
|
25 | + { |
|
26 | + if (\is_string($mixed)) { |
|
27 | + return $mixed; |
|
28 | + } |
|
29 | + if (\is_array($mixed) && 2 === \count($mixed)) { |
|
30 | + return \sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]); |
|
31 | + } |
|
32 | + return \is_object($mixed) ? \get_class($mixed) : \gettype($mixed); |
|
33 | + } |
|
34 | 34 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public function __construct($strategy, array $candidates) |
17 | 17 | { |
18 | - $classes = \array_map(function ($a) { |
|
18 | + $classes = \array_map(function($a) { |
|
19 | 19 | return $a['class']; |
20 | 20 | }, $candidates); |
21 | 21 | $message = \sprintf('No valid candidate found using strategy "%s". We tested the following candidates: %s.', $strategy, \implode(', ', \array_map([$this, 'stringify'], $classes))); |