Merge pull request #3708 from appwrite/feat-update-naming-conventions
feat: update naming convention and folder structure
This commit is contained in:
commit
9881c4cc73
11 changed files with 206 additions and 180 deletions
16
composer.lock
generated
16
composer.lock
generated
|
@ -3526,23 +3526,23 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
"version": "9.2.15",
|
"version": "9.2.16",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
||||||
"reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f"
|
"reference": "2593003befdcc10db5e213f9f28814f5aa8ac073"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
|
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2593003befdcc10db5e213f9f28814f5aa8ac073",
|
||||||
"reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
|
"reference": "2593003befdcc10db5e213f9f28814f5aa8ac073",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*",
|
||||||
"ext-xmlwriter": "*",
|
"ext-xmlwriter": "*",
|
||||||
"nikic/php-parser": "^4.13.0",
|
"nikic/php-parser": "^4.14",
|
||||||
"php": ">=7.3",
|
"php": ">=7.3",
|
||||||
"phpunit/php-file-iterator": "^3.0.3",
|
"phpunit/php-file-iterator": "^3.0.3",
|
||||||
"phpunit/php-text-template": "^2.0.2",
|
"phpunit/php-text-template": "^2.0.2",
|
||||||
|
@ -3591,7 +3591,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
|
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
|
||||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15"
|
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.16"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -3599,7 +3599,7 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2022-03-07T09:28:20+00:00"
|
"time": "2022-08-20T05:26:47+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-file-iterator",
|
"name": "phpunit/php-file-iterator",
|
||||||
|
@ -5383,5 +5383,5 @@
|
||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "8.0"
|
"php": "8.0"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.2.0"
|
"plugin-api-version": "2.3.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,15 @@ class Queries extends Validator
|
||||||
/**
|
/**
|
||||||
* Queries constructor
|
* Queries constructor
|
||||||
*
|
*
|
||||||
* @param Validator $validator used to validate each query
|
* @param $validators - a list of validators
|
||||||
* @param Document[] $attributes allowed attributes to be queried
|
|
||||||
* @param Document[] $indexes available for strict query matching
|
|
||||||
* @param bool $strict
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Validator $validator)
|
public function __construct(Limit $limit = null, Offset $offset = null, Order $order = null, Cursor $cursor = null, Filter $filter = null)
|
||||||
{
|
{
|
||||||
$this->validator = $validator;
|
$this->limit = $limit;
|
||||||
|
$this->offset = $offset;
|
||||||
|
$this->order = $order;
|
||||||
|
$this->filter = $filter;
|
||||||
|
$this->cursor = $cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +69,19 @@ class Queries extends Validator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->validator->isValid($query)) {
|
$method = $query->getMethod();
|
||||||
|
switch ($method) {
|
||||||
|
case Query::TYPE_LIMIT:
|
||||||
|
$validator = $this->limit;
|
||||||
|
case Query::TYPE_OFFSET:
|
||||||
|
$validator = $this->offset;
|
||||||
|
case Query::TYPE_ORDER:
|
||||||
|
$validator = $this->order;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($validator && !$validator->isValid($query)) {
|
||||||
$this->message = 'Query not valid: ' . $this->validator->getDescription();
|
$this->message = 'Query not valid: ' . $this->validator->getDescription();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
|
||||||
|
|
||||||
use Utopia\Database\Query;
|
|
||||||
use Utopia\Database\Validator\UID;
|
|
||||||
|
|
||||||
class LimitOffsetCursorQuery extends LimitOffsetQuery
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $message = 'Invalid query';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query constructor
|
|
||||||
*
|
|
||||||
* @param int $maxLimit
|
|
||||||
* @param int $maxOffset
|
|
||||||
* @param int $maxValuesCount
|
|
||||||
*/
|
|
||||||
public function __construct(int $maxLimit = 100, int $maxOffset = 5000)
|
|
||||||
{
|
|
||||||
parent::__construct($maxLimit, $maxOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isValidCursor($cursor): bool
|
|
||||||
{
|
|
||||||
$validator = new UID();
|
|
||||||
|
|
||||||
if ($validator->isValid($cursor)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->message = 'Invalid cursor: ' . $validator->getDescription();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is valid.
|
|
||||||
*
|
|
||||||
* Returns true if:
|
|
||||||
* 1. method is limit or offset and values are within range
|
|
||||||
* 2. method is cursorBefore or cursorAfter and value is not null
|
|
||||||
*
|
|
||||||
* Otherwise, returns false
|
|
||||||
*
|
|
||||||
* @param Query $value
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid($query): bool
|
|
||||||
{
|
|
||||||
// Validate method
|
|
||||||
$method = $query->getMethod();
|
|
||||||
|
|
||||||
if ($method === Query::TYPE_CURSORAFTER || $method === Query::TYPE_CURSORBEFORE) {
|
|
||||||
$cursor = $query->getValue();
|
|
||||||
return $this->isValidCursor($cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::isValid($query);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Database\Validator;
|
|
||||||
|
|
||||||
use Utopia\Database\Validator\UID;
|
|
||||||
use Utopia\Database\Validator\Query as QueryValidator;
|
|
||||||
|
|
||||||
class Query extends QueryValidator
|
|
||||||
{
|
|
||||||
protected function isValidCursor($cursor): bool
|
|
||||||
{
|
|
||||||
$validator = new UID();
|
|
||||||
|
|
||||||
if ($validator->isValid($cursor)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->message = 'Invalid cursor: ' . $validator->getDescription();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
44
src/Appwrite/Utopia/Database/Validator/Query/Cursor.php
Normal file
44
src/Appwrite/Utopia/Database/Validator/Query/Cursor.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||||
|
|
||||||
|
use Utopia\Validator;
|
||||||
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\Database\Validator\UID;
|
||||||
|
|
||||||
|
class Cursor extends Validator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $message = 'Invalid query';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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($query): bool
|
||||||
|
{
|
||||||
|
// Validate method
|
||||||
|
$method = $query->getMethod();
|
||||||
|
|
||||||
|
if ($method === Query::TYPE_CURSORAFTER || $method === Query::TYPE_CURSORBEFORE) {
|
||||||
|
$cursor = $query->getValue();
|
||||||
|
$validator = new UID();
|
||||||
|
if ($validator->isValid($cursor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$this->message = 'Invalid cursor: ' . $validator->getDescription();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||||
|
|
||||||
use Appwrite\Utopia\Database\Validator\Queries\LimitOffsetCursorQuery;
|
use Utopia\Validator;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
|
|
||||||
class LimitOffsetCursorFilterQuery extends LimitOffsetCursorQuery
|
class Filter extends Validator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -21,19 +21,15 @@ class LimitOffsetCursorFilterQuery extends LimitOffsetCursorQuery
|
||||||
/**
|
/**
|
||||||
* Query constructor
|
* Query constructor
|
||||||
*
|
*
|
||||||
* @param int $maxLimit
|
|
||||||
* @param int $maxOffset
|
|
||||||
* @param int $maxValuesCount
|
* @param int $maxValuesCount
|
||||||
*/
|
*/
|
||||||
public function __construct(int $maxLimit = 100, int $maxOffset = 5000, array $attributes = [], int $maxValuesCount = 100)
|
public function __construct(array $attributes = [], int $maxValuesCount = 100)
|
||||||
{
|
{
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
$this->schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy();
|
$this->schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maxValuesCount = $maxValuesCount;
|
$this->maxValuesCount = $maxValuesCount;
|
||||||
|
|
||||||
parent::__construct($maxLimit, $maxOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isValidAttribute($attribute): bool
|
protected function isValidAttribute($attribute): bool
|
||||||
|
@ -78,30 +74,10 @@ class LimitOffsetCursorFilterQuery extends LimitOffsetCursorQuery
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isValidContains(string $attribute, array $values): bool
|
|
||||||
{
|
|
||||||
if (!$this->isValidAttributeAndValues($attribute, $values)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributeSchema = $this->schema[$attribute];
|
|
||||||
|
|
||||||
// Contains method only supports array attributes
|
|
||||||
if (!$attributeSchema['array']) {
|
|
||||||
$this->message = 'Query method only supported on array attributes: ' . Query::TYPE_CONTAINS;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is valid.
|
* Is valid.
|
||||||
*
|
*
|
||||||
* Returns true if:
|
* Returns true if method is a filter method, attribute exists, and value matches attribute type
|
||||||
* 1. method is limit or offset and values are within range
|
|
||||||
* 2. method is cursorBefore or cursorAfter and value is not null
|
|
||||||
* 3. method is a filter method, attribute exists, and value matches attribute type
|
|
||||||
*
|
*
|
||||||
* Otherwise, returns false
|
* Otherwise, returns false
|
||||||
*
|
*
|
||||||
|
@ -116,9 +92,10 @@ class LimitOffsetCursorFilterQuery extends LimitOffsetCursorQuery
|
||||||
$attribute = $query->getAttribute();
|
$attribute = $query->getAttribute();
|
||||||
|
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case Query::TYPE_CONTAINS:
|
// Do we support contains ?
|
||||||
$values = $query->getValues();
|
// case Query::TYPE_CONTAINS:
|
||||||
return $this->isValidContains($attribute, $values);
|
// $values = $query->getValues();
|
||||||
|
// return $this->isValidContains($attribute, $values);
|
||||||
|
|
||||||
case Query::TYPE_EQUAL:
|
case Query::TYPE_EQUAL:
|
||||||
case Query::TYPE_NOTEQUAL:
|
case Query::TYPE_NOTEQUAL:
|
||||||
|
@ -131,7 +108,7 @@ class LimitOffsetCursorFilterQuery extends LimitOffsetCursorQuery
|
||||||
return $this->isValidAttributeAndValues($attribute, $values);
|
return $this->isValidAttributeAndValues($attribute, $values);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return parent::isValid($query);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
97
src/Appwrite/Utopia/Database/Validator/Query/Limit.php
Normal file
97
src/Appwrite/Utopia/Database/Validator/Query/Limit.php
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||||
|
|
||||||
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\Validator\Range;
|
||||||
|
use Utopia\Validator;
|
||||||
|
|
||||||
|
class Limit extends Validator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $message = 'Invalid query';
|
||||||
|
|
||||||
|
protected int $maxLimit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query constructor
|
||||||
|
*
|
||||||
|
* @param int $maxLimit
|
||||||
|
*/
|
||||||
|
public function __construct(int $maxLimit = 100)
|
||||||
|
{
|
||||||
|
$this->maxLimit = $maxLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Description.
|
||||||
|
*
|
||||||
|
* Returns validator description
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isValidLimit($limit): bool
|
||||||
|
{
|
||||||
|
$validator = new Range(0, $this->maxLimit);
|
||||||
|
if ($validator->isValid($limit)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->message = 'Invalid limit: ' . $validator->getDescription();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is valid.
|
||||||
|
*
|
||||||
|
* Returns true if method is limit values are within range.
|
||||||
|
*
|
||||||
|
* @param Query $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValid($query): bool
|
||||||
|
{
|
||||||
|
// Validate method
|
||||||
|
$method = $query->getMethod();
|
||||||
|
|
||||||
|
if ($method !== Query::LIMIT) {
|
||||||
|
$this->message = 'Query method invalid: ' . $method;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = $query->getValue();
|
||||||
|
return $this->isValidLimit($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is array
|
||||||
|
*
|
||||||
|
* Function will return true if object is array.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isArray(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Type
|
||||||
|
*
|
||||||
|
* Returns validator type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType(): string
|
||||||
|
{
|
||||||
|
return self::TYPE_OBJECT;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,31 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||||
|
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Validator\Range;
|
use Utopia\Validator\Range;
|
||||||
use Utopia\Validator;
|
use Utopia\Validator;
|
||||||
|
|
||||||
class LimitOffsetQuery extends Validator
|
class Offset extends Validator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $message = 'Invalid query';
|
protected $message = 'Invalid query';
|
||||||
|
|
||||||
protected int $maxLimit;
|
|
||||||
protected int $maxOffset;
|
protected int $maxOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query constructor
|
* Query constructor
|
||||||
*
|
*
|
||||||
* @param int $maxLimit
|
|
||||||
* @param int $maxOffset
|
* @param int $maxOffset
|
||||||
* @param int $maxValuesCount
|
|
||||||
*/
|
*/
|
||||||
public function __construct(int $maxLimit = 100, int $maxOffset = 5000)
|
public function __construct(int $maxOffset = 5000)
|
||||||
{
|
{
|
||||||
$this->maxLimit = $maxLimit;
|
|
||||||
$this->maxOffset = $maxOffset;
|
$this->maxOffset = $maxOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,17 +37,6 @@ class LimitOffsetQuery extends Validator
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isValidLimit($limit): bool
|
|
||||||
{
|
|
||||||
$validator = new Range(0, $this->maxLimit);
|
|
||||||
if ($validator->isValid($limit)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->message = 'Invalid limit: ' . $validator->getDescription();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isValidOffset($offset): bool
|
protected function isValidOffset($offset): bool
|
||||||
{
|
{
|
||||||
$validator = new Range(0, $this->maxOffset);
|
$validator = new Range(0, $this->maxOffset);
|
||||||
|
@ -66,7 +51,7 @@ class LimitOffsetQuery extends Validator
|
||||||
/**
|
/**
|
||||||
* Is valid.
|
* Is valid.
|
||||||
*
|
*
|
||||||
* Returns true if method is limit or offset and values are within range.
|
* Returns true if method is offset and values are within range.
|
||||||
*
|
*
|
||||||
* @param Query $value
|
* @param Query $value
|
||||||
*
|
*
|
||||||
|
@ -76,19 +61,14 @@ class LimitOffsetQuery extends Validator
|
||||||
{
|
{
|
||||||
// Validate method
|
// Validate method
|
||||||
$method = $query->getMethod();
|
$method = $query->getMethod();
|
||||||
switch ($method) {
|
|
||||||
case Query::TYPE_LIMIT:
|
|
||||||
$limit = $query->getValue();
|
|
||||||
return $this->isValidLimit($limit);
|
|
||||||
|
|
||||||
case Query::TYPE_OFFSET:
|
if ($method !== Query::TYPE_OFFSET) {
|
||||||
$offset = $query->getValue();
|
|
||||||
return $this->isValidOffset($offset);
|
|
||||||
|
|
||||||
default:
|
|
||||||
$this->message = 'Query method invalid: ' . $method;
|
$this->message = 'Query method invalid: ' . $method;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$offset = $query->getValue();
|
||||||
|
return $this->isValidOffset($offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||||
|
|
||||||
use Appwrite\Utopia\Database\Validator\Queries\LimitOffsetCursorFilterQuery;
|
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\Validator;
|
||||||
|
|
||||||
class LimitOffsetCursorFilterOrderQuery extends LimitOffsetCursorFilterQuery
|
class Order extends Validator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -20,29 +20,29 @@ class LimitOffsetCursorFilterOrderQuery extends LimitOffsetCursorFilterQuery
|
||||||
/**
|
/**
|
||||||
* Query constructor
|
* Query constructor
|
||||||
*
|
*
|
||||||
* @param int $maxLimit
|
|
||||||
* @param int $maxOffset
|
|
||||||
* @param int $maxValuesCount
|
|
||||||
*/
|
*/
|
||||||
public function __construct(int $maxLimit = 100, int $maxOffset = 5000, array $attributes = [], int $maxValuesCount = 100)
|
public function __construct(array $attributes = [])
|
||||||
{
|
{
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
$this->schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy();
|
$this->schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->maxValuesCount = $maxValuesCount;
|
protected function isValidAttribute($attribute): bool
|
||||||
|
{
|
||||||
|
// Search for attribute in schema
|
||||||
|
if (!isset($this->schema[$attribute])) {
|
||||||
|
$this->message = 'Attribute not found in schema: ' . $attribute;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($maxLimit, $maxOffset);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is valid.
|
* Is valid.
|
||||||
*
|
*
|
||||||
* Returns true if:
|
* Returns true if method is ORDER_ASC or ORDER_DESC and attributes are valid
|
||||||
* 1. method is limit or offset and values are within range
|
|
||||||
* 2. method is cursorBefore or cursorAfter and value is not null
|
|
||||||
* 3. method is a filter method, attribute exists, and value matches attribute type
|
|
||||||
* 4. method is orderAsc or orderDesc and attribute exists or is empty string
|
|
||||||
*
|
*
|
||||||
* Otherwise, returns false
|
* Otherwise, returns false
|
||||||
*
|
*
|
Loading…
Reference in a new issue