-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathCursor.php
More file actions
56 lines (46 loc) · 1.29 KB
/
Copy pathCursor.php
File metadata and controls
56 lines (46 loc) · 1.29 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
52
53
54
55
56
<?php
namespace Utopia\Database\Validator\Query;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\UID;
class Cursor extends Base
{
public function __construct(private readonly int $maxLength = Database::MAX_UID_DEFAULT_LENGTH)
{
}
/**
* 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($this->maxLength);
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;
}
}