Completed
Pull Request — master (#407)
by
unknown
02:40
created
lib/Vendor/GuzzleHttp/Promise/AggregateException.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,7 @@
 block discarded – undo
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)));
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
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
 /**
Please login to merge, or discard this patch.
lib/Vendor/GuzzleHttp/Promise/Utils.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,7 @@
 block discarded – undo
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
      *
Please login to merge, or discard this patch.
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -5,215 +5,215 @@
 block discarded – undo
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
-            if (Is::pending($aggregate)) {
131
-                $aggregate->reject($reason);
132
-            }
133
-        })->then(function () use(&$results) {
134
-            \ksort($results);
135
-            return $results;
136
-        });
137
-        if (\true === $recursive) {
138
-            $promise = $promise->then(function ($results) use($recursive, &$promises) {
139
-                foreach ($promises as $promise) {
140
-                    if (Is::pending($promise)) {
141
-                        return self::all($promises, $recursive);
142
-                    }
143
-                }
144
-                return $results;
145
-            });
146
-        }
147
-        return $promise;
148
-    }
149
-    /**
150
-     * Initiate a competitive race between multiple promises or values (values
151
-     * will become immediately fulfilled promises).
152
-     *
153
-     * When count amount of promises have been fulfilled, the returned promise
154
-     * is fulfilled with an array that contains the fulfillment values of the
155
-     * winners in order of resolution.
156
-     *
157
-     * This promise is rejected with a {@see AggregateException} if the number
158
-     * of fulfilled promises is less than the desired $count.
159
-     *
160
-     * @param int   $count    Total number of promises.
161
-     * @param mixed $promises Promises or values.
162
-     */
163
-    public static function some(int $count, $promises) : PromiseInterface
164
-    {
165
-        $results = [];
166
-        $rejections = [];
167
-        return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void {
168
-            if (Is::settled($p)) {
169
-                return;
170
-            }
171
-            $results[$idx] = $value;
172
-            if (\count($results) >= $count) {
173
-                $p->resolve(null);
174
-            }
175
-        }, function ($reason) use(&$rejections) : void {
176
-            $rejections[] = $reason;
177
-        })->then(function () use(&$results, &$rejections, $count) {
178
-            if (\count($results) !== $count) {
179
-                throw new AggregateException('Not enough promises to fulfill count', $rejections);
180
-            }
181
-            \ksort($results);
182
-            return \array_values($results);
183
-        });
184
-    }
185
-    /**
186
-     * Like some(), with 1 as count. However, if the promise fulfills, the
187
-     * fulfillment value is not an array of 1 but the value directly.
188
-     *
189
-     * @param mixed $promises Promises or values.
190
-     */
191
-    public static function any($promises) : PromiseInterface
192
-    {
193
-        return self::some(1, $promises)->then(function ($values) {
194
-            return $values[0];
195
-        });
196
-    }
197
-    /**
198
-     * Returns a promise that is fulfilled when all of the provided promises have
199
-     * been fulfilled or rejected.
200
-     *
201
-     * The returned promise is fulfilled with an array of inspection state arrays.
202
-     *
203
-     * @see inspect for the inspection state array format.
204
-     *
205
-     * @param mixed $promises Promises or values.
206
-     */
207
-    public static function settle($promises) : PromiseInterface
208
-    {
209
-        $results = [];
210
-        return Each::of($promises, function ($value, $idx) use(&$results) : void {
211
-            $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value];
212
-        }, function ($reason, $idx) use(&$results) : void {
213
-            $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason];
214
-        })->then(function () use(&$results) {
215
-            \ksort($results);
216
-            return $results;
217
-        });
218
-    }
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
+			if (Is::pending($aggregate)) {
131
+				$aggregate->reject($reason);
132
+			}
133
+		})->then(function () use(&$results) {
134
+			\ksort($results);
135
+			return $results;
136
+		});
137
+		if (\true === $recursive) {
138
+			$promise = $promise->then(function ($results) use($recursive, &$promises) {
139
+				foreach ($promises as $promise) {
140
+					if (Is::pending($promise)) {
141
+						return self::all($promises, $recursive);
142
+					}
143
+				}
144
+				return $results;
145
+			});
146
+		}
147
+		return $promise;
148
+	}
149
+	/**
150
+	 * Initiate a competitive race between multiple promises or values (values
151
+	 * will become immediately fulfilled promises).
152
+	 *
153
+	 * When count amount of promises have been fulfilled, the returned promise
154
+	 * is fulfilled with an array that contains the fulfillment values of the
155
+	 * winners in order of resolution.
156
+	 *
157
+	 * This promise is rejected with a {@see AggregateException} if the number
158
+	 * of fulfilled promises is less than the desired $count.
159
+	 *
160
+	 * @param int   $count    Total number of promises.
161
+	 * @param mixed $promises Promises or values.
162
+	 */
163
+	public static function some(int $count, $promises) : PromiseInterface
164
+	{
165
+		$results = [];
166
+		$rejections = [];
167
+		return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void {
168
+			if (Is::settled($p)) {
169
+				return;
170
+			}
171
+			$results[$idx] = $value;
172
+			if (\count($results) >= $count) {
173
+				$p->resolve(null);
174
+			}
175
+		}, function ($reason) use(&$rejections) : void {
176
+			$rejections[] = $reason;
177
+		})->then(function () use(&$results, &$rejections, $count) {
178
+			if (\count($results) !== $count) {
179
+				throw new AggregateException('Not enough promises to fulfill count', $rejections);
180
+			}
181
+			\ksort($results);
182
+			return \array_values($results);
183
+		});
184
+	}
185
+	/**
186
+	 * Like some(), with 1 as count. However, if the promise fulfills, the
187
+	 * fulfillment value is not an array of 1 but the value directly.
188
+	 *
189
+	 * @param mixed $promises Promises or values.
190
+	 */
191
+	public static function any($promises) : PromiseInterface
192
+	{
193
+		return self::some(1, $promises)->then(function ($values) {
194
+			return $values[0];
195
+		});
196
+	}
197
+	/**
198
+	 * Returns a promise that is fulfilled when all of the provided promises have
199
+	 * been fulfilled or rejected.
200
+	 *
201
+	 * The returned promise is fulfilled with an array of inspection state arrays.
202
+	 *
203
+	 * @see inspect for the inspection state array format.
204
+	 *
205
+	 * @param mixed $promises Promises or values.
206
+	 */
207
+	public static function settle($promises) : PromiseInterface
208
+	{
209
+		$results = [];
210
+		return Each::of($promises, function ($value, $idx) use(&$results) : void {
211
+			$results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value];
212
+		}, function ($reason, $idx) use(&$results) : void {
213
+			$results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason];
214
+		})->then(function () use(&$results) {
215
+			\ksort($results);
216
+			return $results;
217
+		});
218
+	}
219 219
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,18 +124,18 @@  discard block
 block discarded – undo
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
             if (Is::pending($aggregate)) {
131 131
                 $aggregate->reject($reason);
132 132
             }
133
-        })->then(function () use(&$results) {
133
+        })->then(function() use(&$results) {
134 134
             \ksort($results);
135 135
             return $results;
136 136
         });
137 137
         if (\true === $recursive) {
138
-            $promise = $promise->then(function ($results) use($recursive, &$promises) {
138
+            $promise = $promise->then(function($results) use($recursive, &$promises) {
139 139
                 foreach ($promises as $promise) {
140 140
                     if (Is::pending($promise)) {
141 141
                         return self::all($promises, $recursive);
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $results = [];
166 166
         $rejections = [];
167
-        return Each::of($promises, function ($value, $idx, PromiseInterface $p) use(&$results, $count) : void {
167
+        return Each::of($promises, function($value, $idx, PromiseInterface $p) use(&$results, $count) : void {
168 168
             if (Is::settled($p)) {
169 169
                 return;
170 170
             }
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
             if (\count($results) >= $count) {
173 173
                 $p->resolve(null);
174 174
             }
175
-        }, function ($reason) use(&$rejections) : void {
175
+        }, function($reason) use(&$rejections) : void {
176 176
             $rejections[] = $reason;
177
-        })->then(function () use(&$results, &$rejections, $count) {
177
+        })->then(function() use(&$results, &$rejections, $count) {
178 178
             if (\count($results) !== $count) {
179 179
                 throw new AggregateException('Not enough promises to fulfill count', $rejections);
180 180
             }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public static function any($promises) : PromiseInterface
192 192
     {
193
-        return self::some(1, $promises)->then(function ($values) {
193
+        return self::some(1, $promises)->then(function($values) {
194 194
             return $values[0];
195 195
         });
196 196
     }
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
     public static function settle($promises) : PromiseInterface
208 208
     {
209 209
         $results = [];
210
-        return Each::of($promises, function ($value, $idx) use(&$results) : void {
210
+        return Each::of($promises, function($value, $idx) use(&$results) : void {
211 211
             $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value];
212
-        }, function ($reason, $idx) use(&$results) : void {
212
+        }, function($reason, $idx) use(&$results) : void {
213 213
             $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason];
214
-        })->then(function () use(&$results) {
214
+        })->then(function() use(&$results) {
215 215
             \ksort($results);
216 216
             return $results;
217 217
         });
Please login to merge, or discard this patch.
lib/Vendor/GuzzleHttp/BodySummarizer.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,7 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,19 +5,19 @@
 block discarded – undo
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 ? Psr7\Message::bodySummary($message) : 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 ? Psr7\Message::bodySummary($message) : Psr7\Message::bodySummary($message, $this->truncateAt);
22
+	}
23 23
 }
Please login to merge, or discard this patch.
lib/Vendor/GuzzleHttp/Utils.php 3 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,8 +8,7 @@
 block discarded – undo
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
      *
Please login to merge, or discard this patch.
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -10,147 +10,147 @@  discard block
 block discarded – undo
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 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') && \function_exists('curl_version') && \version_compare(\curl_version()['version'], '7.21.2') >= 0) {
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 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') && \function_exists('curl_version') && \version_compare(\curl_version()['version'], '7.21.2') >= 0) {
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Vendor/Http/Discovery/Psr17Factory.php 2 patches
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -40,202 +40,202 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
lib/Vendor/Http/Discovery/Exception/DiscoveryFailedException.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,36 +10,36 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
lib/Vendor/Http/Discovery/Exception/NoCandidateFoundException.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,25 +10,25 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
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)));
Please login to merge, or discard this patch.
lib/Vendor/Http/Discovery/Psr17FactoryDiscovery.php 3 patches
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -17,103 +17,103 @@
 block discarded – undo
17 17
  */
18 18
 final class Psr17FactoryDiscovery extends ClassDiscovery
19 19
 {
20
-    private static function createException($type, Exception $e)
21
-    {
22
-        return new RealNotFoundException('No PSR-17 ' . $type . ' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', 0, $e);
23
-    }
24
-    /**
25
-     * @return RequestFactoryInterface
26
-     *
27
-     * @throws RealNotFoundException
28
-     */
29
-    public static function findRequestFactory()
30
-    {
31
-        try {
32
-            $messageFactory = static::findOneByType(RequestFactoryInterface::class);
33
-        } catch (DiscoveryFailedException $e) {
34
-            throw self::createException('request factory', $e);
35
-        }
36
-        return static::instantiateClass($messageFactory);
37
-    }
38
-    /**
39
-     * @return ResponseFactoryInterface
40
-     *
41
-     * @throws RealNotFoundException
42
-     */
43
-    public static function findResponseFactory()
44
-    {
45
-        try {
46
-            $messageFactory = static::findOneByType(ResponseFactoryInterface::class);
47
-        } catch (DiscoveryFailedException $e) {
48
-            throw self::createException('response factory', $e);
49
-        }
50
-        return static::instantiateClass($messageFactory);
51
-    }
52
-    /**
53
-     * @return ServerRequestFactoryInterface
54
-     *
55
-     * @throws RealNotFoundException
56
-     */
57
-    public static function findServerRequestFactory()
58
-    {
59
-        try {
60
-            $messageFactory = static::findOneByType(ServerRequestFactoryInterface::class);
61
-        } catch (DiscoveryFailedException $e) {
62
-            throw self::createException('server request factory', $e);
63
-        }
64
-        return static::instantiateClass($messageFactory);
65
-    }
66
-    /**
67
-     * @return StreamFactoryInterface
68
-     *
69
-     * @throws RealNotFoundException
70
-     */
71
-    public static function findStreamFactory()
72
-    {
73
-        try {
74
-            $messageFactory = static::findOneByType(StreamFactoryInterface::class);
75
-        } catch (DiscoveryFailedException $e) {
76
-            throw self::createException('stream factory', $e);
77
-        }
78
-        return static::instantiateClass($messageFactory);
79
-    }
80
-    /**
81
-     * @return UploadedFileFactoryInterface
82
-     *
83
-     * @throws RealNotFoundException
84
-     */
85
-    public static function findUploadedFileFactory()
86
-    {
87
-        try {
88
-            $messageFactory = static::findOneByType(UploadedFileFactoryInterface::class);
89
-        } catch (DiscoveryFailedException $e) {
90
-            throw self::createException('uploaded file factory', $e);
91
-        }
92
-        return static::instantiateClass($messageFactory);
93
-    }
94
-    /**
95
-     * @return UriFactoryInterface
96
-     *
97
-     * @throws RealNotFoundException
98
-     */
99
-    public static function findUriFactory()
100
-    {
101
-        try {
102
-            $messageFactory = static::findOneByType(UriFactoryInterface::class);
103
-        } catch (DiscoveryFailedException $e) {
104
-            throw self::createException('url factory', $e);
105
-        }
106
-        return static::instantiateClass($messageFactory);
107
-    }
108
-    /**
109
-     * @return UriFactoryInterface
110
-     *
111
-     * @throws RealNotFoundException
112
-     *
113
-     * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method.
114
-     */
115
-    public static function findUrlFactory()
116
-    {
117
-        return static::findUriFactory();
118
-    }
20
+	private static function createException($type, Exception $e)
21
+	{
22
+		return new RealNotFoundException('No PSR-17 ' . $type . ' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', 0, $e);
23
+	}
24
+	/**
25
+	 * @return RequestFactoryInterface
26
+	 *
27
+	 * @throws RealNotFoundException
28
+	 */
29
+	public static function findRequestFactory()
30
+	{
31
+		try {
32
+			$messageFactory = static::findOneByType(RequestFactoryInterface::class);
33
+		} catch (DiscoveryFailedException $e) {
34
+			throw self::createException('request factory', $e);
35
+		}
36
+		return static::instantiateClass($messageFactory);
37
+	}
38
+	/**
39
+	 * @return ResponseFactoryInterface
40
+	 *
41
+	 * @throws RealNotFoundException
42
+	 */
43
+	public static function findResponseFactory()
44
+	{
45
+		try {
46
+			$messageFactory = static::findOneByType(ResponseFactoryInterface::class);
47
+		} catch (DiscoveryFailedException $e) {
48
+			throw self::createException('response factory', $e);
49
+		}
50
+		return static::instantiateClass($messageFactory);
51
+	}
52
+	/**
53
+	 * @return ServerRequestFactoryInterface
54
+	 *
55
+	 * @throws RealNotFoundException
56
+	 */
57
+	public static function findServerRequestFactory()
58
+	{
59
+		try {
60
+			$messageFactory = static::findOneByType(ServerRequestFactoryInterface::class);
61
+		} catch (DiscoveryFailedException $e) {
62
+			throw self::createException('server request factory', $e);
63
+		}
64
+		return static::instantiateClass($messageFactory);
65
+	}
66
+	/**
67
+	 * @return StreamFactoryInterface
68
+	 *
69
+	 * @throws RealNotFoundException
70
+	 */
71
+	public static function findStreamFactory()
72
+	{
73
+		try {
74
+			$messageFactory = static::findOneByType(StreamFactoryInterface::class);
75
+		} catch (DiscoveryFailedException $e) {
76
+			throw self::createException('stream factory', $e);
77
+		}
78
+		return static::instantiateClass($messageFactory);
79
+	}
80
+	/**
81
+	 * @return UploadedFileFactoryInterface
82
+	 *
83
+	 * @throws RealNotFoundException
84
+	 */
85
+	public static function findUploadedFileFactory()
86
+	{
87
+		try {
88
+			$messageFactory = static::findOneByType(UploadedFileFactoryInterface::class);
89
+		} catch (DiscoveryFailedException $e) {
90
+			throw self::createException('uploaded file factory', $e);
91
+		}
92
+		return static::instantiateClass($messageFactory);
93
+	}
94
+	/**
95
+	 * @return UriFactoryInterface
96
+	 *
97
+	 * @throws RealNotFoundException
98
+	 */
99
+	public static function findUriFactory()
100
+	{
101
+		try {
102
+			$messageFactory = static::findOneByType(UriFactoryInterface::class);
103
+		} catch (DiscoveryFailedException $e) {
104
+			throw self::createException('url factory', $e);
105
+		}
106
+		return static::instantiateClass($messageFactory);
107
+	}
108
+	/**
109
+	 * @return UriFactoryInterface
110
+	 *
111
+	 * @throws RealNotFoundException
112
+	 *
113
+	 * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method.
114
+	 */
115
+	public static function findUrlFactory()
116
+	{
117
+		return static::findUriFactory();
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 {
20 20
     private static function createException($type, Exception $e)
21 21
     {
22
-        return new RealNotFoundException('No PSR-17 ' . $type . ' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', 0, $e);
22
+        return new RealNotFoundException('No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', 0, $e);
23 23
     }
24 24
     /**
25 25
      * @return RequestFactoryInterface
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@
 block discarded – undo
15 15
  *
16 16
  * @author Tobias Nyholm <[email protected]>
17 17
  */
18
-final class Psr17FactoryDiscovery extends ClassDiscovery
19
-{
18
+final class Psr17FactoryDiscovery extends ClassDiscovery {
20 19
     private static function createException($type, Exception $e)
21 20
     {
22 21
         return new RealNotFoundException('No PSR-17 ' . $type . ' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', 0, $e);
Please login to merge, or discard this patch.
lib/Vendor/Http/Discovery/NotFoundException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,6 +10,5 @@
 block discarded – undo
10 10
  *
11 11
  * @deprecated since since version 1.0, and will be removed in 2.0. Use {@link \Http\Discovery\Exception\NotFoundException} instead.
12 12
  */
13
-final class NotFoundException extends RealNotFoundException
14
-{
13
+final class NotFoundException extends RealNotFoundException {
15 14
 }
Please login to merge, or discard this patch.