File tree Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of phayne-io/php-dynamodb and is proprietary and confidential.
5+ * Unauthorized copying of this file, via any medium is strictly prohibited.
6+ *
7+ * @see https://github.com/phayne-io/php-dynamodb for the canonical source repository
8+ * @copyright Copyright (c) 2024-2025 Phayne Limited. (https://phayne.io)
9+ */
10+
11+ declare (strict_types=1 );
12+
13+ namespace Phayne \DynamoDB \Operation \Query ;
14+
15+ /**
16+ * Class Criteria
17+ *
18+ * @package Phayne\DynamoDB\Operation\Query
19+ */
20+ final readonly class Criteria
21+ {
22+ private array $ criteria ;
23+
24+ public function __construct (Criterion ...$ criteria )
25+ {
26+ $ this ->criteria = $ criteria ;
27+ }
28+
29+ public static function from (Criterion ...$ criteria ): Criteria
30+ {
31+ return new self (...$ criteria );
32+ }
33+
34+ public function toArray (): array
35+ {
36+ $ criteria = [];
37+ foreach ($ this ->criteria as $ criterion ) {
38+ $ criteria [$ criterion ->field ] = [
39+ 'operator ' => $ criterion ->operator ->value ,
40+ 'value ' => $ criterion ->value ,
41+ ];
42+ }
43+
44+ return $ criteria ;
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of phayne-io/php-dynamodb and is proprietary and confidential.
5+ * Unauthorized copying of this file, via any medium is strictly prohibited.
6+ *
7+ * @see https://github.com/phayne-io/php-dynamodb for the canonical source repository
8+ * @copyright Copyright (c) 2024-2025 Phayne Limited. (https://phayne.io)
9+ */
10+
11+ declare (strict_types=1 );
12+
13+ namespace Phayne \DynamoDB \Operation \Query ;
14+
15+ use Phayne \DynamoDB \Enum \Operator ;
16+
17+ /**
18+ * Class Criterion
19+ *
20+ * @package Phayne\DynamoDB\Operation\Query
21+ */
22+ final readonly class Criterion
23+ {
24+ private function __construct (
25+ public Operator $ operator ,
26+ public string $ field ,
27+ public mixed $ value ,
28+ ) {
29+ }
30+
31+ public static function from (Operator $ operator , string $ field , mixed $ value ): Criterion
32+ {
33+ return new self ($ operator , $ field , $ value );
34+ }
35+
36+ public function toArray (bool $ fieldAsKey = false ): array
37+ {
38+ return $ fieldAsKey
39+ ? [$ this ->field => ['operator ' => $ this ->operator ->value , 'value ' => $ this ->value ]]
40+ : ['operator ' => $ this ->operator ->value , 'name ' => $ this ->field , 'value ' => $ this ->value ];
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments