1 | <?php |
||
11 | class ArrayConnection |
||
12 | { |
||
13 | |||
14 | const PREFIX = 'arrayconnection:'; |
||
15 | |||
16 | 1 | public static function cursorForObjectInConnection($data, $object) |
|
23 | |||
24 | /** |
||
25 | * @param $offset int |
||
26 | * @return string |
||
27 | * @deprecated |
||
28 | * Use keyToCursor instead. |
||
29 | */ |
||
30 | public static function offsetToCursor($offset) |
||
34 | |||
35 | 2 | public static function keyToCursor($key) |
|
39 | |||
40 | /** |
||
41 | * @param $cursor string |
||
42 | * |
||
43 | * @return int|null |
||
44 | * @deprecated Use cursorToKey instead. |
||
45 | */ |
||
46 | public static function cursorToOffset($cursor) |
||
50 | |||
51 | /** |
||
52 | * Converts a cursor to its array key. |
||
53 | * |
||
54 | * @param $cursor |
||
55 | * @return null|string |
||
56 | */ |
||
57 | 1 | public static function cursorToKey($cursor) { |
|
63 | |||
64 | /** |
||
65 | * Converts a cursor to an array offset. |
||
66 | * |
||
67 | * @param $cursor |
||
68 | * The cursor string. |
||
69 | * @param $default |
||
70 | * The default value, in case the cursor is not given. |
||
71 | * @param array $array |
||
72 | * The array to use in counting the offset. If empty, assumed to be an indexed array. |
||
73 | * @return int|null |
||
74 | */ |
||
75 | 2 | public static function cursorToOffsetWithDefault($cursor, $default, $array = []) |
|
76 | { |
||
77 | 2 | if (!is_string($cursor)) { |
|
78 | 2 | return $default; |
|
79 | } |
||
80 | |||
81 | 1 | $key = self::cursorToKey($cursor); |
|
82 | 1 | if (empty($array)) { |
|
83 | 1 | $offset = $key; |
|
84 | 1 | } |
|
85 | else { |
||
86 | $offset = array_search($key, array_keys($array)); |
||
87 | } |
||
88 | |||
89 | 1 | return is_null($offset) ? $default : (int) $offset; |
|
90 | } |
||
91 | |||
92 | 1 | public static function connectionFromArray(array $data, array $args = []) |
|
96 | |||
97 | 1 | public static function connectionFromArraySlice(array $data, array $args, $sliceStart, $arrayLength) |
|
142 | |||
143 | 1 | public static function edgeForObjectWithIndex($object, $index) |
|
150 | |||
151 | } |
||
152 |