We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
17 | class ConnectionBuilder |
||
18 | { |
||
19 | public const PREFIX = 'arrayconnection:'; |
||
20 | |||
21 | /** |
||
22 | * If set, used to generate the connection object. |
||
23 | * |
||
24 | * @var callable |
||
25 | */ |
||
26 | protected $connectionCallback; |
||
27 | |||
28 | /** |
||
29 | * If set, used to generate the edge object. |
||
30 | * |
||
31 | * @var callable |
||
32 | */ |
||
33 | protected $edgeCallback; |
||
34 | |||
35 | 77 | public function __construct(callable $connectionCallback = null, callable $edgeCallback = null) |
|
40 | |||
41 | /** |
||
42 | * A simple function that accepts an array and connection arguments, and returns |
||
43 | * a connection object for use in GraphQL. It uses array offsets as pagination, |
||
44 | * so pagination will only work if the array is static. |
||
45 | * |
||
46 | * @param array $data |
||
47 | * @param array|Argument $args |
||
48 | * |
||
49 | * @return ConnectionInterface |
||
50 | */ |
||
51 | 66 | public function connectionFromArray(array $data, $args = []): ConnectionInterface |
|
62 | |||
63 | /** |
||
64 | * A version of `connectionFromArray` that takes a promised array, and returns a |
||
65 | * promised connection. |
||
66 | * |
||
67 | * @param mixed $dataPromise a promise |
||
68 | * @param array|Argument $args |
||
69 | * |
||
70 | * @return mixed a promise |
||
71 | */ |
||
72 | 14 | public function connectionFromPromisedArray($dataPromise, $args = []) |
|
80 | |||
81 | /** |
||
82 | * Given a slice (subset) of an array, returns a connection object for use in |
||
83 | * GraphQL. |
||
84 | * |
||
85 | * This function is similar to `connectionFromArray`, but is intended for use |
||
86 | * cases where you know the cardinality of the connection, consider it too large |
||
87 | * to materialize the entire array, and instead wish pass in a slice of the |
||
88 | * total result large enough to cover the range specified in `args`. |
||
89 | * |
||
90 | * @param array $arraySlice |
||
91 | * @param array|Argument $args |
||
92 | * @param array $meta |
||
93 | * |
||
94 | * @return ConnectionInterface |
||
95 | */ |
||
96 | 90 | public function connectionFromArraySlice(array $arraySlice, $args, array $meta): ConnectionInterface |
|
170 | |||
171 | /** |
||
172 | * A version of `connectionFromArraySlice` that takes a promised array slice, |
||
173 | * and returns a promised connection. |
||
174 | * |
||
175 | * @param mixed $dataPromise a promise |
||
176 | * @param array|Argument $args |
||
177 | * @param array $meta |
||
178 | * |
||
179 | * @return mixed a promise |
||
180 | */ |
||
181 | 12 | public function connectionFromPromisedArraySlice($dataPromise, $args, array $meta) |
|
189 | |||
190 | /** |
||
191 | * Return the cursor associated with an object in an array. |
||
192 | * |
||
193 | * @param array $data |
||
194 | * @param mixed $object |
||
195 | * |
||
196 | * @return null|string |
||
197 | */ |
||
198 | 4 | public function cursorForObjectInConnection(array $data, $object): ? string |
|
218 | |||
219 | /** |
||
220 | * Given an optional cursor and a default offset, returns the offset |
||
221 | * to use; if the cursor contains a valid offset, that will be used, |
||
222 | * otherwise it will be the default. |
||
223 | * |
||
224 | * @param string|null $cursor |
||
225 | * @param int $defaultOffset |
||
226 | * |
||
227 | * @return int |
||
228 | */ |
||
229 | 92 | public function getOffsetWithDefault(?string $cursor, int $defaultOffset): int |
|
238 | |||
239 | /** |
||
240 | * Creates the cursor string from an offset. |
||
241 | * |
||
242 | * @param $offset |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | 84 | public function offsetToCursor($offset): string |
|
250 | |||
251 | /** |
||
252 | * Redefines the offset from the cursor string. |
||
253 | * |
||
254 | * @param $cursor |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | 48 | public function cursorToOffset($cursor): string |
|
266 | |||
267 | 86 | private function createEdges(iterable $slice, int $startOffset): array |
|
286 | |||
287 | 86 | private function createConnection($edges, PageInfoInterface $pageInfo): ConnectionInterface |
|
300 | |||
301 | 90 | private function getOptionsWithDefaults(array $options, array $defaults) |
|
305 | |||
306 | 26 | private function checkPromise($value): void |
|
312 | } |
||
313 |