Skip to content

Commit b3941f4

Browse files
committed
Update main
1 parent 32b2bd9 commit b3941f4

3 files changed

Lines changed: 51 additions & 34 deletions

File tree

src/Database/Query.php

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Query
157157
self::TYPE_GREATER_EQUAL,
158158
self::TYPE_CONTAINS,
159159
self::TYPE_NOT_CONTAINS,
160+
self::TYPE_CONTAINS_ANY,
161+
self::TYPE_CONTAINS_ALL,
160162
self::TYPE_SEARCH,
161163
self::TYPE_NOT_SEARCH,
162164
self::TYPE_IS_NULL,
@@ -747,9 +749,9 @@ public static function greaterThanEqual(string $attribute, string|int|float|bool
747749
* @param array<mixed> $values
748750
* @return Query
749751
*/
750-
public static function contains(string $attribute, array $values): self
752+
public static function contains(string $attribute, array $values, string $alias = ''): self
751753
{
752-
return new self(self::TYPE_CONTAINS, $attribute, $values);
754+
return new self(self::TYPE_CONTAINS, $attribute, $values, alias: $alias);
753755
}
754756

755757
/**
@@ -760,9 +762,9 @@ public static function contains(string $attribute, array $values): self
760762
* @param array<mixed> $values
761763
* @return Query
762764
*/
763-
public static function containsAny(string $attribute, array $values): self
765+
public static function containsAny(string $attribute, array $values, string $alias = ''): self
764766
{
765-
return new self(self::TYPE_CONTAINS_ANY, $attribute, $values);
767+
return new self(self::TYPE_CONTAINS_ANY, $attribute, $values, alias: $alias);
766768
}
767769

768770
/**
@@ -772,9 +774,9 @@ public static function containsAny(string $attribute, array $values): self
772774
* @param array<mixed> $values
773775
* @return Query
774776
*/
775-
public static function notContains(string $attribute, array $values): self
777+
public static function notContains(string $attribute, array $values, string $alias = ''): self
776778
{
777-
return new self(self::TYPE_NOT_CONTAINS, $attribute, $values);
779+
return new self(self::TYPE_NOT_CONTAINS, $attribute, $values, alias: $alias);
778780
}
779781

780782
/**
@@ -783,6 +785,7 @@ public static function notContains(string $attribute, array $values): self
783785
* @param string $attribute
784786
* @param string|int|float|bool $start
785787
* @param string|int|float|bool $end
788+
* @param string $alias
786789
* @return Query
787790
*/
788791
public static function between(string $attribute, string|int|float|bool $start, string|int|float|bool $end, string $alias = ''): self
@@ -796,35 +799,38 @@ public static function between(string $attribute, string|int|float|bool $start,
796799
* @param string $attribute
797800
* @param string|int|float|bool $start
798801
* @param string|int|float|bool $end
802+
* @param string $alias
799803
* @return Query
800804
*/
801-
public static function notBetween(string $attribute, string|int|float|bool $start, string|int|float|bool $end): self
805+
public static function notBetween(string $attribute, string|int|float|bool $start, string|int|float|bool $end, string $alias = ''): self
802806
{
803-
return new self(self::TYPE_NOT_BETWEEN, $attribute, [$start, $end]);
807+
return new self(self::TYPE_NOT_BETWEEN, $attribute, [$start, $end], alias: $alias);
804808
}
805809

806810
/**
807811
* Helper method to create Query with search method
808812
*
809813
* @param string $attribute
810814
* @param string $value
815+
* @param string $alias
811816
* @return Query
812817
*/
813-
public static function search(string $attribute, string $value): self
818+
public static function search(string $attribute, string $value, string $alias = ''): self
814819
{
815-
return new self(self::TYPE_SEARCH, $attribute, [$value]);
820+
return new self(self::TYPE_SEARCH, $attribute, [$value], alias: $alias);
816821
}
817822

818823
/**
819824
* Helper method to create Query with notSearch method
820825
*
821826
* @param string $attribute
822827
* @param string $value
828+
* @param string $alias
823829
* @return Query
824830
*/
825-
public static function notSearch(string $attribute, string $value): self
831+
public static function notSearch(string $attribute, string $value, string $alias = ''): self
826832
{
827-
return new self(self::TYPE_NOT_SEARCH, $attribute, [$value]);
833+
return new self(self::TYPE_NOT_SEARCH, $attribute, [$value], alias: $alias);
828834
}
829835

830836
public static function select(string $attribute, string $alias = '', string $as = '', bool $system = false): self
@@ -836,6 +842,7 @@ public static function select(string $attribute, string $alias = '', string $as
836842
* Helper method to create Query with orderDesc method
837843
*
838844
* @param string $attribute
845+
* @param string $alias
839846
* @return Query
840847
*/
841848
public static function orderDesc(string $attribute = '', string $alias = ''): self
@@ -847,6 +854,7 @@ public static function orderDesc(string $attribute = '', string $alias = ''): se
847854
* Helper method to create Query with orderAsc method
848855
*
849856
* @param string $attribute
857+
* @param string $alias
850858
* @return Query
851859
*/
852860
public static function orderAsc(string $attribute = '', string $alias = ''): self
@@ -932,24 +940,24 @@ public static function isNotNull(string $attribute, string $alias = ''): self
932940
return new self(self::TYPE_IS_NOT_NULL, $attribute, alias: $alias);
933941
}
934942

935-
public static function startsWith(string $attribute, string $value): self
943+
public static function startsWith(string $attribute, string $value, string $alias = ''): self
936944
{
937-
return new self(self::TYPE_STARTS_WITH, $attribute, [$value]);
945+
return new self(self::TYPE_STARTS_WITH, $attribute, [$value], alias: $alias);
938946
}
939947

940-
public static function notStartsWith(string $attribute, string $value): self
948+
public static function notStartsWith(string $attribute, string $value, string $alias = ''): self
941949
{
942-
return new self(self::TYPE_NOT_STARTS_WITH, $attribute, [$value]);
950+
return new self(self::TYPE_NOT_STARTS_WITH, $attribute, [$value], alias: $alias);
943951
}
944952

945-
public static function endsWith(string $attribute, string $value): self
953+
public static function endsWith(string $attribute, string $value, string $alias = ''): self
946954
{
947-
return new self(self::TYPE_ENDS_WITH, $attribute, [$value]);
955+
return new self(self::TYPE_ENDS_WITH, $attribute, [$value], alias: $alias);
948956
}
949957

950-
public static function notEndsWith(string $attribute, string $value): self
958+
public static function notEndsWith(string $attribute, string $value, string $alias = ''): self
951959
{
952-
return new self(self::TYPE_NOT_ENDS_WITH, $attribute, [$value]);
960+
return new self(self::TYPE_NOT_ENDS_WITH, $attribute, [$value], alias: $alias);
953961
}
954962

955963
/**
@@ -958,9 +966,9 @@ public static function notEndsWith(string $attribute, string $value): self
958966
* @param string $value
959967
* @return Query
960968
*/
961-
public static function createdBefore(string $value): self
969+
public static function createdBefore(string $value, string $alias = ''): self
962970
{
963-
return self::lessThan('$createdAt', $value);
971+
return self::lessThan('$createdAt', $value, alias: $alias);
964972
}
965973

966974
/**
@@ -969,9 +977,9 @@ public static function createdBefore(string $value): self
969977
* @param string $value
970978
* @return Query
971979
*/
972-
public static function createdAfter(string $value): self
980+
public static function createdAfter(string $value, string $alias = ''): self
973981
{
974-
return self::greaterThan('$createdAt', $value);
982+
return self::greaterThan('$createdAt', $value, alias: $alias);
975983
}
976984

977985
/**
@@ -980,9 +988,9 @@ public static function createdAfter(string $value): self
980988
* @param string $value
981989
* @return Query
982990
*/
983-
public static function updatedBefore(string $value): self
991+
public static function updatedBefore(string $value, string $alias = ''): self
984992
{
985-
return self::lessThan('$updatedAt', $value);
993+
return self::lessThan('$updatedAt', $value, alias: $alias);
986994
}
987995

988996
/**
@@ -991,9 +999,9 @@ public static function updatedBefore(string $value): self
991999
* @param string $value
9921000
* @return Query
9931001
*/
994-
public static function updatedAfter(string $value): self
1002+
public static function updatedAfter(string $value, string $alias = ''): self
9951003
{
996-
return self::greaterThan('$updatedAt', $value);
1004+
return self::greaterThan('$updatedAt', $value, alias: $alias);
9971005
}
9981006

9991007
/**
@@ -1003,9 +1011,9 @@ public static function updatedAfter(string $value): self
10031011
* @param string $end
10041012
* @return Query
10051013
*/
1006-
public static function createdBetween(string $start, string $end): self
1014+
public static function createdBetween(string $start, string $end, string $alias = ''): self
10071015
{
1008-
return self::between('$createdAt', $start, $end);
1016+
return self::between('$createdAt', $start, $end, alias: $alias);
10091017
}
10101018

10111019
/**
@@ -1015,9 +1023,9 @@ public static function createdBetween(string $start, string $end): self
10151023
* @param string $end
10161024
* @return Query
10171025
*/
1018-
public static function updatedBetween(string $start, string $end): self
1026+
public static function updatedBetween(string $start, string $end, string $alias = ''): self
10191027
{
1020-
return self::between('$updatedAt', $start, $end);
1028+
return self::between('$updatedAt', $start, $end, alias: $alias);
10211029
}
10221030

10231031
/**

src/Database/Validator/Queries/V2.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public function isValid($value, string $scope = ''): bool
208208
case Query::TYPE_EQUAL:
209209
case Query::TYPE_CONTAINS:
210210
case Query::TYPE_NOT_CONTAINS:
211+
case Query::TYPE_CONTAINS_ANY:
212+
case Query::TYPE_CONTAINS_ALL:
211213
case Query::TYPE_EXISTS:
212214
case Query::TYPE_NOT_EXISTS:
213215
if ($this->isEmpty($query->getValues())) {
@@ -637,7 +639,7 @@ protected function validateValues(string $attributeId, string $alias, array $val
637639
}
638640

639641
if (
640-
\in_array($method, [Query::TYPE_EQUAL, Query::TYPE_NOT_EQUAL, Query::TYPE_CONTAINS, Query::TYPE_NOT_CONTAINS], true) &&
642+
\in_array($method, [Query::TYPE_EQUAL, Query::TYPE_NOT_EQUAL, Query::TYPE_CONTAINS, Query::TYPE_NOT_CONTAINS, Query::TYPE_CONTAINS_ANY, Query::TYPE_CONTAINS_ALL], true) &&
641643
!$this->isValidObjectQueryValues($value)
642644
) {
643645
throw new \Exception('Invalid object query structure for attribute "'.$attributeId.'"');
@@ -712,7 +714,7 @@ protected function validateValues(string $attributeId, string $alias, array $val
712714

713715
if (
714716
! $array &&
715-
in_array($method, [Query::TYPE_CONTAINS, Query::TYPE_NOT_CONTAINS]) &&
717+
in_array($method, [Query::TYPE_CONTAINS, Query::TYPE_NOT_CONTAINS, Query::TYPE_CONTAINS_ANY, Query::TYPE_CONTAINS_ALL]) &&
716718
$attribute['type'] !== Database::VAR_STRING &&
717719
$attribute['type'] !== Database::VAR_OBJECT &&
718720
!in_array($attribute['type'], Database::SPATIAL_TYPES)
@@ -725,6 +727,8 @@ protected function validateValues(string $attributeId, string $alias, array $val
725727
!in_array($method, [
726728
Query::TYPE_CONTAINS,
727729
Query::TYPE_NOT_CONTAINS,
730+
Query::TYPE_CONTAINS_ANY,
731+
Query::TYPE_CONTAINS_ALL,
728732
Query::TYPE_IS_NULL,
729733
Query::TYPE_IS_NOT_NULL,
730734
Query::TYPE_EXISTS,

tests/unit/QueryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,9 @@ public function testJoinsParse(): void
596596
$this->assertEquals('id1', $query->getAttribute());
597597
$this->assertEquals('id2', $query->getAttributeRight());
598598
}
599+
600+
public function testFilter()
601+
{
602+
$filters = Query::getFilterQueries($queries);
603+
}
599604
}

0 commit comments

Comments
 (0)