-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathCursor.php
More file actions
51 lines (42 loc) · 1.18 KB
/
Cursor.php
File metadata and controls
51 lines (42 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Utopia\Database\Validator\Query;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\UID;
class Cursor extends Base
{
/**
* Is valid.
*
* Returns true if method is cursorBefore or cursorAfter and value is not null
*
* Otherwise, returns false
*
* @param Query $value
* @return bool
*/
public function isValid($value): bool
{
if (!$value instanceof Query) {
return false;
}
$method = $value->getMethod();
if ($method === Query::TYPE_CURSOR_AFTER || $method === Query::TYPE_CURSOR_BEFORE) {
$cursor = $value->getValue();
// if ($cursor instanceof Document) {
// $cursor = $cursor->getId();
// }
$validator = new UID();
if ($validator->isValid($cursor)) {
return true;
}
$this->message = 'Invalid cursor: ' . $validator->getDescription();
return false;
}
return false;
}
public function getMethodType(): string
{
return self::METHOD_TYPE_CURSOR;
}
}