Skip to content

Commit e487b55

Browse files
committed
Const default
1 parent 9be8e29 commit e487b55

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/Database/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Database
8080
public const MAX_DOUBLE = PHP_FLOAT_MAX;
8181
public const MAX_VECTOR_DIMENSIONS = 16000;
8282
public const MAX_ARRAY_INDEX_LENGTH = 255;
83+
public const MAX_UID_DEFAULT_LENGTH = 36;
8384

8485
// Global SRID for geographic coordinates (WGS84)
8586
public const DEFAULT_SRID = 4326;

src/Database/Validator/Key.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Utopia\Database\Validator;
44

5+
use Utopia\Database\Database;
56
use Utopia\Validator;
67

78
class Key extends Validator
@@ -24,8 +25,8 @@ public function getDescription(): string
2425
* Expression constructor
2526
*/
2627
public function __construct(
27-
private readonly bool $allowInternal = false,
28-
private readonly int $maxLength = 36,
28+
protected readonly bool $allowInternal = false,
29+
protected readonly int $maxLength = Database::MAX_UID_DEFAULT_LENGTH,
2930
) {
3031
$this->message = 'Parameter must contain at most ' . $this->maxLength . ' chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char';
3132
}

src/Database/Validator/Label.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace Utopia\Database\Validator;
44

5+
use Utopia\Database\Database;
6+
57
class Label extends Key
68
{
7-
public function __construct(bool $allowInternal = false, int $maxLength = 255)
8-
{
9+
public function __construct(
10+
bool $allowInternal = false,
11+
int $maxLength = Database::MAX_UID_DEFAULT_LENGTH
12+
) {
913
parent::__construct($allowInternal, $maxLength);
1014
$this->message = 'Value must be a valid string between 1 and ' . $this->maxLength . ' chars containing only alphanumeric chars';
1115
}

src/Database/Validator/Query/Cursor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace Utopia\Database\Validator\Query;
44

5+
use Utopia\Database\Database;
56
use Utopia\Database\Document;
67
use Utopia\Database\Query;
78
use Utopia\Database\Validator\UID;
89

910
class Cursor extends Base
1011
{
11-
public function __construct(private readonly int $maxLength = 36)
12+
public function __construct(private readonly int $maxLength = Database::MAX_UID_DEFAULT_LENGTH)
1213
{
1314
}
1415

src/Database/Validator/UID.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Utopia\Database\Validator;
44

5+
use Utopia\Database\Database;
6+
57
class UID extends Key
68
{
79
/**
810
* Expression constructor
911
*/
10-
public function __construct(int $maxLength = 36)
12+
public function __construct(int $maxLength = Database::MAX_UID_DEFAULT_LENGTH)
1113
{
1214
parent::__construct(false, $maxLength);
1315
}

0 commit comments

Comments
 (0)