Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ public function createCollection(string $id, array $attributes = [], array $inde
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
);
foreach ($indexes as $index) {
if (!$validator->isValid($index)) {
Expand Down Expand Up @@ -2420,6 +2421,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
);

foreach ($indexes as $index) {
Expand Down Expand Up @@ -3363,6 +3365,7 @@ public function createIndex(string $collection, string $id, string $type, array
$this->adapter->getSupportForSpatialAttributes(),
$this->adapter->getSupportForSpatialIndexNull(),
$this->adapter->getSupportForSpatialIndexOrder(),
$this->adapter->getSupportForAttributes()
);
if (!$validator->isValid($index)) {
throw new IndexException($validator->getDescription());
Expand Down Expand Up @@ -3906,6 +3909,7 @@ public function createDocument(string $collection, Document $document): Document
$this->adapter->getIdAttributeType(),
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);
if (!$structure->isValid($document)) {
throw new StructureException($structure->getDescription());
Expand Down Expand Up @@ -4006,6 +4010,7 @@ public function createDocuments(
$this->adapter->getIdAttributeType(),
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);
if (!$validator->isValid($document)) {
throw new StructureException($validator->getDescription());
Expand Down Expand Up @@ -4559,6 +4564,7 @@ public function updateDocument(string $collection, string $id, Document $documen
$this->adapter->getIdAttributeType(),
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);
if (!$structureValidator->isValid($document)) { // Make sure updated structure still apply collection rules (if any)
throw new StructureException($structureValidator->getDescription());
Expand Down Expand Up @@ -4693,6 +4699,7 @@ public function updateDocuments(
$this->adapter->getIdAttributeType(),
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);

if (!$validator->isValid($updates)) {
Expand Down Expand Up @@ -5404,6 +5411,7 @@ public function upsertDocumentsWithIncrease(
$this->adapter->getIdAttributeType(),
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);

if (!$validator->isValid($document)) {
Expand Down Expand Up @@ -6397,6 +6405,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
$this->maxQueryValues,
$this->adapter->getMinDateTime(),
$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
);
if (!$validator->isValid($queries)) {
throw new QueryException($validator->getDescription());
Expand Down
12 changes: 10 additions & 2 deletions src/Database/Validator/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Index extends Validator

protected bool $spatialIndexOrderSupport;

protected bool $supportForAttributes;
/**
* @param array<Document> $attributes
* @param int $maxLength
Expand All @@ -40,14 +41,15 @@ class Index extends Validator
* @param bool $spatialIndexOrderSupport
* @throws DatabaseException
*/
public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], bool $arrayIndexSupport = false, bool $spatialIndexSupport = false, bool $spatialIndexNullSupport = false, bool $spatialIndexOrderSupport = false)
public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], bool $arrayIndexSupport = false, bool $spatialIndexSupport = false, bool $spatialIndexNullSupport = false, bool $spatialIndexOrderSupport = false, bool $supportForAttributes = true)
{
$this->maxLength = $maxLength;
$this->reservedKeys = $reservedKeys;
$this->arrayIndexSupport = $arrayIndexSupport;
$this->spatialIndexSupport = $spatialIndexSupport;
$this->spatialIndexNullSupport = $spatialIndexNullSupport;
$this->spatialIndexOrderSupport = $spatialIndexOrderSupport;
$this->supportForAttributes = $supportForAttributes;

foreach ($attributes as $attribute) {
$key = \strtolower($attribute->getAttribute('key', $attribute->getAttribute('$id')));
Expand Down Expand Up @@ -75,7 +77,7 @@ public function getDescription(): string
public function checkAttributesNotFound(Document $index): bool
{
foreach ($index->getAttribute('attributes', []) as $attribute) {
if (!isset($this->attributes[\strtolower($attribute)])) {
if ($this->supportForAttributes && !isset($this->attributes[\strtolower($attribute)])) {
$this->message = 'Invalid index attribute "' . $attribute . '" not found';
return false;
}
Expand Down Expand Up @@ -123,6 +125,9 @@ public function checkDuplicatedAttributes(Document $index): bool
*/
public function checkFulltextIndexNonString(Document $index): bool
{
if (!$this->supportForAttributes) {
return true;
}
if ($index->getAttribute('type') === Database::INDEX_FULLTEXT) {
foreach ($index->getAttribute('attributes', []) as $attribute) {
$attribute = $this->attributes[\strtolower($attribute)] ?? new Document();
Expand All @@ -141,6 +146,9 @@ public function checkFulltextIndexNonString(Document $index): bool
*/
public function checkArrayIndex(Document $index): bool
{
if (!$this->supportForAttributes) {
return true;
}
$attributes = $index->getAttribute('attributes', []);
$orders = $index->getAttribute('orders', []);
$lengths = $index->getAttribute('lengths', []);
Expand Down
6 changes: 4 additions & 2 deletions src/Database/Validator/Queries/Documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(
int $maxValuesCount = 100,
\DateTime $minAllowedDate = new \DateTime('0000-01-01'),
\DateTime $maxAllowedDate = new \DateTime('9999-12-31'),
bool $supportForAttributes = true
) {
$attributes[] = new Document([
'$id' => '$id',
Expand Down Expand Up @@ -66,9 +67,10 @@ public function __construct(
$maxValuesCount,
$minAllowedDate,
$maxAllowedDate,
$supportForAttributes
),
new Order($attributes),
new Select($attributes),
new Order($attributes, $supportForAttributes),
new Select($attributes, $supportForAttributes),
];

parent::__construct($attributes, $indexes, $validators);
Expand Down
6 changes: 5 additions & 1 deletion src/Database/Validator/Query/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
private readonly int $maxValuesCount = 100,
private readonly \DateTime $minAllowedDate = new \DateTime('0000-01-01'),
private readonly \DateTime $maxAllowedDate = new \DateTime('9999-12-31'),
private bool $supportForAttributes = true
) {
foreach ($attributes as $attribute) {
$this->schema[$attribute->getAttribute('key', $attribute->getAttribute('$id'))] = $attribute->getArrayCopy();
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function isValidAttribute(string $attribute): bool
}

// Search for attribute in schema
if (!isset($this->schema[$attribute])) {
if ($this->supportForAttributes && !isset($this->schema[$attribute])) {
$this->message = 'Attribute not found in schema: ' . $attribute;
return false;
}
Expand All @@ -94,6 +95,9 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
$attribute = \explode('.', $attribute)[0];
}

if (!$this->supportForAttributes && !isset($this->schema[$attribute])) {
return true;
}
$attributeSchema = $this->schema[$attribute];

if (count($values) > $this->maxValuesCount) {
Expand Down
5 changes: 3 additions & 2 deletions src/Database/Validator/Query/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class Order extends Base

/**
* @param array<Document> $attributes
* @param bool $supportForAttributes
*/
public function __construct(array $attributes = [])
public function __construct(array $attributes = [], protected bool $supportForAttributes = true)
{
foreach ($attributes as $attribute) {
$this->schema[$attribute->getAttribute('key', $attribute->getAttribute('$id'))] = $attribute->getArrayCopy();
Expand All @@ -29,7 +30,7 @@ public function __construct(array $attributes = [])
protected function isValidAttribute(string $attribute): bool
{
// Search for attribute in schema
if (!isset($this->schema[$attribute])) {
if ($this->supportForAttributes && !isset($this->schema[$attribute])) {
$this->message = 'Attribute not found in schema: ' . $attribute;
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Database/Validator/Query/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class Select extends Base

/**
* @param array<Document> $attributes
* @param bool $supportForAttributes
*/
public function __construct(array $attributes = [])
public function __construct(array $attributes = [], protected bool $supportForAttributes = true)
{
foreach ($attributes as $attribute) {
$this->schema[$attribute->getAttribute('key', $attribute->getAttribute('$id'))] = $attribute->getArrayCopy();
Expand Down Expand Up @@ -89,7 +90,7 @@ public function isValid($value): bool
continue;
}

if (!isset($this->schema[$attribute]) && $attribute !== '*') {
if ($this->supportForAttributes && !isset($this->schema[$attribute]) && $attribute !== '*') {
$this->message = 'Attribute not found in schema: ' . $attribute;
return false;
}
Expand Down
16 changes: 13 additions & 3 deletions src/Database/Validator/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function __construct(
private readonly string $idAttributeType,
private readonly \DateTime $minAllowedDate = new \DateTime('0000-01-01'),
private readonly \DateTime $maxAllowedDate = new \DateTime('9999-12-31'),
private bool $supportForAttributes = true
) {
}

Expand Down Expand Up @@ -251,7 +252,11 @@ public function isValid($document): bool
*/
protected function checkForAllRequiredValues(array $structure, array $attributes, array &$keys): bool
{
foreach ($attributes as $key => $attribute) { // Check all required attributes are set
if (!$this->supportForAttributes) {
return true;
}

foreach ($attributes as $attribute) { // Check all required attributes are set
$name = $attribute['$id'] ?? '';
$required = $attribute['required'] ?? false;

Expand All @@ -276,6 +281,9 @@ protected function checkForAllRequiredValues(array $structure, array $attributes
*/
protected function checkForUnknownAttributes(array $structure, array $keys): bool
{
if (!$this->supportForAttributes) {
return true;
}
foreach ($structure as $key => $value) {
if (!array_key_exists($key, $keys)) { // Check no unknown attributes are set
$this->message = 'Unknown attribute: "'.$key.'"';
Expand Down Expand Up @@ -357,8 +365,10 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
break;

default:
$this->message = 'Unknown attribute type "'.$type.'"';
return false;
if ($this->supportForAttributes) {
$this->message = 'Unknown attribute type "'.$type.'"';
return false;
}
}

/** Error message label, either 'format' or 'type' */
Expand Down
Loading