From 85447eb583d5245e43ac01c8a5332c687ad3ee9e Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 25 Feb 2025 15:50:51 -0500 Subject: [PATCH 1/5] PHPLIB-1492: Support sort option for updateOne and replaceOne (#1605) Addresses both single-statement updates and bulk writes. * Require PHPC 1.21-dev for CI builds --- .../generated/build/build-extension.yml | 44 +++++++++++++++---- .../templates/build/build-extension.yml | 11 ++++- .github/workflows/coding-standards.yml | 4 +- .github/workflows/generator.yml | 4 +- .github/workflows/static-analysis.yml | 4 +- .github/workflows/tests.yml | 4 +- composer.json | 2 +- src/Operation/BulkWrite.php | 20 +++++++++ src/Operation/ReplaceOne.php | 6 +++ src/Operation/Update.php | 14 +++++- src/Operation/UpdateOne.php | 6 +++ tests/Operation/BulkWriteTest.php | 29 ++++++++++++ tests/Operation/UpdateTest.php | 8 ++++ tests/UnifiedSpecTests/UnifiedSpecTest.php | 5 --- tests/UnifiedSpecTests/Util.php | 4 +- 15 files changed, 140 insertions(+), 25 deletions(-) diff --git a/.evergreen/config/generated/build/build-extension.yml b/.evergreen/config/generated/build/build-extension.yml index 1ccde5f97..a74e18776 100644 --- a/.evergreen/config/generated/build/build-extension.yml +++ b/.evergreen/config/generated/build/build-extension.yml @@ -7,6 +7,9 @@ tasks: vars: PHP_VERSION: "8.4" - func: "compile extension" + # TODO: remove once 1.21.0 is released + vars: + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.4-lowest" tags: ["build", "php8.4", "lowest", "pr", "tag"] @@ -16,7 +19,9 @@ tasks: PHP_VERSION: "8.4" - func: "compile extension" vars: - EXTENSION_VERSION: "1.20.0" + # TODO: change to "EXTENSION_VERSION: 1.21.0" once 1.21.0 is released + # EXTENSION_VERSION: "1.21.0" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.4-next-stable" tags: ["build", "php8.4", "next-stable", "pr", "tag"] @@ -26,7 +31,9 @@ tasks: PHP_VERSION: "8.4" - func: "compile extension" vars: - EXTENSION_BRANCH: "v1.20" + # TODO: change to "v1.21" once 1.21.0 is released + # EXTENSION_BRANCH: "v1.21" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.4-next-minor" tags: ["build", "php8.4", "next-minor"] @@ -45,6 +52,9 @@ tasks: vars: PHP_VERSION: "8.3" - func: "compile extension" + # TODO: remove once 1.21.0 is released + vars: + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.3-lowest" tags: ["build", "php8.3", "lowest", "pr", "tag"] @@ -54,7 +64,9 @@ tasks: PHP_VERSION: "8.3" - func: "compile extension" vars: - EXTENSION_VERSION: "1.20.0" + # TODO: change to "EXTENSION_VERSION: 1.21.0" once 1.21.0 is released + # EXTENSION_VERSION: "1.21.0" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.3-next-stable" tags: ["build", "php8.3", "next-stable", "pr", "tag"] @@ -64,7 +76,9 @@ tasks: PHP_VERSION: "8.3" - func: "compile extension" vars: - EXTENSION_BRANCH: "v1.20" + # TODO: change to "v1.21" once 1.21.0 is released + # EXTENSION_BRANCH: "v1.21" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.3-next-minor" tags: ["build", "php8.3", "next-minor"] @@ -83,6 +97,9 @@ tasks: vars: PHP_VERSION: "8.2" - func: "compile extension" + # TODO: remove once 1.21.0 is released + vars: + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.2-lowest" tags: ["build", "php8.2", "lowest", "pr", "tag"] @@ -92,7 +109,9 @@ tasks: PHP_VERSION: "8.2" - func: "compile extension" vars: - EXTENSION_VERSION: "1.20.0" + # TODO: change to "EXTENSION_VERSION: 1.21.0" once 1.21.0 is released + # EXTENSION_VERSION: "1.21.0" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.2-next-stable" tags: ["build", "php8.2", "next-stable", "pr", "tag"] @@ -102,7 +121,9 @@ tasks: PHP_VERSION: "8.2" - func: "compile extension" vars: - EXTENSION_BRANCH: "v1.20" + # TODO: change to "v1.21" once 1.21.0 is released + # EXTENSION_BRANCH: "v1.21" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.2-next-minor" tags: ["build", "php8.2", "next-minor"] @@ -121,6 +142,9 @@ tasks: vars: PHP_VERSION: "8.1" - func: "compile extension" + # TODO: remove once 1.21.0 is released + vars: + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.1-lowest" tags: ["build", "php8.1", "lowest", "pr", "tag"] @@ -130,7 +154,9 @@ tasks: PHP_VERSION: "8.1" - func: "compile extension" vars: - EXTENSION_VERSION: "1.20.0" + # TODO: change to "EXTENSION_VERSION: 1.21.0" once 1.21.0 is released + # EXTENSION_VERSION: "1.21.0" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.1-next-stable" tags: ["build", "php8.1", "next-stable", "pr", "tag"] @@ -140,7 +166,9 @@ tasks: PHP_VERSION: "8.1" - func: "compile extension" vars: - EXTENSION_BRANCH: "v1.20" + # TODO: change to "v1.21" once 1.21.0 is released + # EXTENSION_BRANCH: "v1.21" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-8.1-next-minor" tags: ["build", "php8.1", "next-minor"] diff --git a/.evergreen/config/templates/build/build-extension.yml b/.evergreen/config/templates/build/build-extension.yml index 869c0a9e4..98da2976d 100644 --- a/.evergreen/config/templates/build/build-extension.yml +++ b/.evergreen/config/templates/build/build-extension.yml @@ -5,6 +5,9 @@ vars: PHP_VERSION: "%phpVersion%" - func: "compile extension" + # TODO: remove once 1.21.0 is released + vars: + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-%phpVersion%-lowest" tags: ["build", "php%phpVersion%", "lowest", "pr", "tag"] @@ -14,7 +17,9 @@ PHP_VERSION: "%phpVersion%" - func: "compile extension" vars: - EXTENSION_VERSION: "1.20.0" + # TODO: change to "EXTENSION_VERSION: 1.21.0" once 1.21.0 is released + # EXTENSION_VERSION: "1.21.0" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-%phpVersion%-next-stable" tags: ["build", "php%phpVersion%", "next-stable", "pr", "tag"] @@ -24,7 +29,9 @@ PHP_VERSION: "%phpVersion%" - func: "compile extension" vars: - EXTENSION_BRANCH: "v1.20" + # TODO: change to "v1.21" once 1.21.0 is released + # EXTENSION_BRANCH: "v1.21" + EXTENSION_BRANCH: "v1.x" - func: "upload extension" - name: "build-php-%phpVersion%-next-minor" tags: ["build", "php%phpVersion%", "next-minor"] diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 462e4d67e..10bcc251d 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -13,7 +13,9 @@ on: env: PHP_VERSION: "8.2" - DRIVER_VERSION: "stable" + # TODO: change to "stable" once 1.21.0 is released + # DRIVER_VERSION: "stable" + DRIVER_VERSION: "mongodb/mongo-php-driver@v1.x" jobs: phpcs: diff --git a/.github/workflows/generator.yml b/.github/workflows/generator.yml index 2427a41eb..fd755509c 100644 --- a/.github/workflows/generator.yml +++ b/.github/workflows/generator.yml @@ -13,9 +13,9 @@ on: env: PHP_VERSION: "8.2" - # TODO: change to "stable" once 1.20.0 is released + # TODO: change to "stable" once 1.21.0 is released # DRIVER_VERSION: "stable" - DRIVER_VERSION: "mongodb/mongo-php-driver@v1.20" + DRIVER_VERSION: "mongodb/mongo-php-driver@v1.x" jobs: psalm: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 0103bdcd1..5a7d6fbf3 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -19,7 +19,9 @@ on: env: PHP_VERSION: "8.2" - DRIVER_VERSION: "stable" + # TODO: change to "stable" once 1.21.0 is released + # DRIVER_VERSION: "stable" + DRIVER_VERSION: "mongodb/mongo-php-driver@v1.x" jobs: psalm: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36640a724..194414fb4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,9 @@ on: - "feature/*" env: - DRIVER_VERSION: "stable" + # TODO: change to "stable" once 1.21.0 is released + # DRIVER_VERSION: "stable" + DRIVER_VERSION: "mongodb/mongo-php-driver@v1.x" jobs: phpunit: diff --git a/composer.json b/composer.json index 3b5738ae1..118943bb3 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.1", "ext-hash": "*", "ext-json": "*", - "ext-mongodb": "^1.20.0", + "ext-mongodb": "^1.21.0", "composer-runtime-api": "^2.0", "psr/log": "^1.1.4|^2|^3", "symfony/polyfill-php80": "^1.27", diff --git a/src/Operation/BulkWrite.php b/src/Operation/BulkWrite.php index 5c0b67ea5..c8f695675 100644 --- a/src/Operation/BulkWrite.php +++ b/src/Operation/BulkWrite.php @@ -91,6 +91,14 @@ class BulkWrite implements Executable * * upsert (boolean): When true, a new document is created if no document * matches the query. The default is false. * + * Supported options for replaceOne and updateOne operations: + * + * * sort (document): Determines which document the operation modifies if + * the query selects multiple documents. + * + * This is not supported for server versions < 8.0 and will result in an + * exception at execution time if used. + * * Supported options for updateMany and updateOne operations: * * * arrayFilters (document array): A set of filters specifying to which @@ -372,6 +380,10 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En throw InvalidArgumentException::expectedDocumentType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation']); } + if (isset($args[2]['sort']) && ! is_document($args[2]['sort'])) { + throw InvalidArgumentException::expectedDocumentType(sprintf('$operations[%d]["%s"][2]["sort"]', $i, $type), $args[2]['sort']); + } + if (! is_bool($args[2]['upsert'])) { throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean'); } @@ -413,6 +425,14 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En throw InvalidArgumentException::expectedDocumentType(sprintf('$operations[%d]["%s"][2]["collation"]', $i, $type), $args[2]['collation']); } + if (isset($args[2]['sort']) && ! is_document($args[2]['sort'])) { + throw InvalidArgumentException::expectedDocumentType(sprintf('$operations[%d]["%s"][2]["sort"]', $i, $type), $args[2]['sort']); + } + + if (isset($args[2]['sort']) && $args[2]['multi']) { + throw new InvalidArgumentException(sprintf('"sort" option cannot be used with $operations[%d]["%s"]', $i, $type)); + } + if (! is_bool($args[2]['upsert'])) { throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean'); } diff --git a/src/Operation/ReplaceOne.php b/src/Operation/ReplaceOne.php index 3cec99ff0..843640923 100644 --- a/src/Operation/ReplaceOne.php +++ b/src/Operation/ReplaceOne.php @@ -74,6 +74,12 @@ class ReplaceOne implements Executable * Parameters can then be accessed as variables in an aggregate * expression context (e.g. "$$var"). * + * * sort (document): Determines which document the operation modifies if + * the query selects multiple documents. + * + * This is not supported for server versions < 8.0 and will result in an + * exception at execution time if used. + * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * @param string $databaseName Database name diff --git a/src/Operation/Update.php b/src/Operation/Update.php index 5d011da28..2016d89a8 100644 --- a/src/Operation/Update.php +++ b/src/Operation/Update.php @@ -149,6 +149,14 @@ public function __construct(private string $databaseName, private string $collec throw InvalidArgumentException::expectedDocumentType('"let" option', $options['let']); } + if (isset($options['sort']) && ! is_document($options['sort'])) { + throw InvalidArgumentException::expectedDocumentType('"sort" option', $options['sort']); + } + + if (isset($options['sort']) && $options['multi']) { + throw new InvalidArgumentException('"sort" option cannot be used with multi-document updates'); + } + if (isset($options['bypassDocumentValidation']) && ! $options['bypassDocumentValidation']) { unset($options['bypassDocumentValidation']); } @@ -270,8 +278,10 @@ private function createUpdateOptions(): array } } - if (isset($this->options['collation'])) { - $updateOptions['collation'] = (object) $this->options['collation']; + foreach (['collation', 'sort'] as $option) { + if (isset($this->options[$option])) { + $updateOptions[$option] = (object) $this->options[$option]; + } } return $updateOptions; diff --git a/src/Operation/UpdateOne.php b/src/Operation/UpdateOne.php index 17bc4a554..d7bbe57cb 100644 --- a/src/Operation/UpdateOne.php +++ b/src/Operation/UpdateOne.php @@ -72,6 +72,12 @@ class UpdateOne implements Executable, Explainable * Parameters can then be accessed as variables in an aggregate * expression context (e.g. "$$var"). * + * * sort (document): Determines which document the operation modifies if + * the query selects multiple documents. + * + * This is not supported for server versions < 8.0 and will result in an + * exception at execution time if used. + * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * @param string $databaseName Database name diff --git a/tests/Operation/BulkWriteTest.php b/tests/Operation/BulkWriteTest.php index d64fc351f..30d5c6374 100644 --- a/tests/Operation/BulkWriteTest.php +++ b/tests/Operation/BulkWriteTest.php @@ -217,6 +217,16 @@ public function testReplaceOneCollationOptionTypeCheck($collation): void ]); } + #[DataProvider('provideInvalidDocumentValues')] + public function testReplaceOneSortOptionTypeCheck($sort): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/Expected \$operations\[0\]\["replaceOne"\]\[2\]\["sort"\] to have type "document" \(array or object\) but found ".+"/'); + new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ + [BulkWrite::REPLACE_ONE => [['x' => 1], ['y' => 1], ['sort' => $sort]]], + ]); + } + #[DataProvider('provideInvalidBooleanValues')] public function testReplaceOneUpsertOptionTypeCheck($upsert): void { @@ -322,6 +332,15 @@ public function testUpdateManyCollationOptionTypeCheck($collation): void ]); } + public function testUpdateManyProhibitsSortOption(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('"sort" option cannot be used with $operations[0]["updateMany"]'); + new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ + [BulkWrite::UPDATE_MANY => [['x' => 1], ['$set' => ['y' => 1]], ['sort' => ['z' => 1]]]], + ]); + } + #[DataProvider('provideInvalidBooleanValues')] public function testUpdateManyUpsertOptionTypeCheck($upsert): void { @@ -410,6 +429,16 @@ public function testUpdateOneCollationOptionTypeCheck($collation): void ]); } + #[DataProvider('provideInvalidDocumentValues')] + public function testUpdateOneSortOptionTypeCheck($sort): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/Expected \$operations\[0\]\["updateOne"\]\[2\]\["sort"\] to have type "document" \(array or object\) but found ".+"/'); + new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ + [BulkWrite::UPDATE_ONE => [['x' => 1], ['$set' => ['y' => 1]], ['sort' => $sort]]], + ]); + } + #[DataProvider('provideInvalidBooleanValues')] public function testUpdateOneUpsertOptionTypeCheck($upsert): void { diff --git a/tests/Operation/UpdateTest.php b/tests/Operation/UpdateTest.php index 6c6f590d5..9617c77e8 100644 --- a/tests/Operation/UpdateTest.php +++ b/tests/Operation/UpdateTest.php @@ -40,6 +40,7 @@ public static function provideInvalidConstructorOptions() 'collation' => self::getInvalidDocumentValues(), 'hint' => self::getInvalidHintValues(), 'multi' => self::getInvalidBooleanValues(), + 'sort' => self::getInvalidDocumentValues(), 'session' => self::getInvalidSessionValues(), 'upsert' => self::getInvalidBooleanValues(), 'writeConcern' => self::getInvalidWriteConcernValues(), @@ -55,6 +56,13 @@ public function testConstructorMultiOptionProhibitsReplacementDocumentOrEmptyPip new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update, ['multi' => true]); } + public function testConstructorMultiOptionProhibitsSortOption(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('"sort" option cannot be used with multi-document updates'); + new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['$set' => ['x' => 2]], ['multi' => true, 'sort' => ['x' => 1]]); + } + public function testExplainableCommandDocument(): void { $options = [ diff --git a/tests/UnifiedSpecTests/UnifiedSpecTest.php b/tests/UnifiedSpecTests/UnifiedSpecTest.php index 5dad387fb..b41a67f38 100644 --- a/tests/UnifiedSpecTests/UnifiedSpecTest.php +++ b/tests/UnifiedSpecTests/UnifiedSpecTest.php @@ -37,11 +37,6 @@ class UnifiedSpecTest extends FunctionalTestCase // mongoc_cluster_stream_for_server does not retry handshakes (CDRIVER-4532, PHPLIB-1033, PHPLIB-1042) 'retryable-reads/retryable reads handshake failures' => 'Handshakes are not retried (CDRIVER-4532)', 'retryable-writes/retryable writes handshake failures' => 'Handshakes are not retried (CDRIVER-4532)', - // sort option for update operations is not supported (PHPLIB-1492) - 'crud/BulkWrite replaceOne-sort' => 'Sort for replace operations is not supported (PHPLIB-1492)', - 'crud/BulkWrite updateOne-sort' => 'Sort for update operations is not supported (PHPLIB-1492)', - 'crud/replaceOne-sort' => 'Sort for replace operations is not supported (PHPLIB-1492)', - 'crud/updateOne-sort' => 'Sort for update operations is not supported (PHPLIB-1492)', 'crud/bypassDocumentValidation' => 'bypassDocumentValidation is handled by libmongoc (PHPLIB-1576)', ]; diff --git a/tests/UnifiedSpecTests/Util.php b/tests/UnifiedSpecTests/Util.php index 8adb2923a..d508d7d65 100644 --- a/tests/UnifiedSpecTests/Util.php +++ b/tests/UnifiedSpecTests/Util.php @@ -105,10 +105,10 @@ final class Util 'findOne' => ['let', 'filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'max', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'min', 'modifiers', 'noCursorTimeout', 'oplogReplay', 'projection', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'], 'findOneAndReplace' => ['let', 'returnDocument', 'filter', 'replacement', 'session', 'projection', 'returnDocument', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'maxTimeMS', 'new', 'remove', 'sort', 'comment'], 'rename' => ['to', 'comment', 'dropTarget'], - 'replaceOne' => ['let', 'filter', 'replacement', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment'], + 'replaceOne' => ['let', 'filter', 'replacement', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment', 'sort'], 'findOneAndUpdate' => ['let', 'returnDocument', 'filter', 'update', 'session', 'upsert', 'projection', 'remove', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'maxTimeMS', 'sort', 'comment'], 'updateMany' => ['let', 'filter', 'update', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment'], - 'updateOne' => ['let', 'filter', 'update', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment'], + 'updateOne' => ['let', 'filter', 'update', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment', 'sort'], 'updateSearchIndex' => ['name', 'definition'], 'insertMany' => ['documents', 'session', 'ordered', 'bypassDocumentValidation', 'comment'], 'insertOne' => ['document', 'session', 'bypassDocumentValidation', 'comment'], From dd77c8ddc34dc26a6caf0bb156c6e6e1c62fe10a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 26 Feb 2025 10:38:09 +0100 Subject: [PATCH 2/5] PHPLIB-1634: Support encoding DateTimeInterface instances in aggregation builder (#1610) * PHPLIB-1634: Support encoding DateTimeInterface instances in aggregation builder * Sort types correctly * Accept DateTimeInterface for query objects * Add missing psalm annotation * Use BSON Type class instead of UTCDateTime * Update psalm baseline --- generator/config/expressions.php | 5 +- psalm-baseline.xml | 2 + .../Accumulator/AddToSetAccumulator.php | 12 +- src/Builder/Accumulator/BottomAccumulator.php | 9 +- .../Accumulator/BottomNAccumulator.php | 9 +- .../Accumulator/DerivativeAccumulator.php | 9 +- src/Builder/Accumulator/FactoryTrait.php | 65 ++-- src/Builder/Accumulator/FirstAccumulator.php | 12 +- src/Builder/Accumulator/FirstNAccumulator.php | 9 +- .../Accumulator/IntegralAccumulator.php | 9 +- src/Builder/Accumulator/LastAccumulator.php | 12 +- src/Builder/Accumulator/LocfAccumulator.php | 12 +- src/Builder/Accumulator/MaxAccumulator.php | 12 +- src/Builder/Accumulator/MinAccumulator.php | 12 +- src/Builder/Accumulator/PushAccumulator.php | 12 +- src/Builder/Accumulator/ShiftAccumulator.php | 17 +- src/Builder/Accumulator/TopAccumulator.php | 9 +- src/Builder/Accumulator/TopNAccumulator.php | 9 +- src/Builder/BuilderEncoder.php | 10 +- .../Encoder/AbstractExpressionEncoder.php | 4 +- src/Builder/Encoder/DateTimeEncoder.php | 35 ++ src/Builder/Encoder/ExpressionEncoder.php | 3 +- src/Builder/Expression/AddOperator.php | 7 +- src/Builder/Expression/AndOperator.php | 7 +- src/Builder/Expression/CaseOperator.php | 9 +- src/Builder/Expression/CmpOperator.php | 17 +- src/Builder/Expression/CondOperator.php | 17 +- src/Builder/Expression/ConvertOperator.php | 25 +- src/Builder/Expression/DateAddOperator.php | 9 +- src/Builder/Expression/DateDiffOperator.php | 17 +- .../Expression/DateFromStringOperator.php | 17 +- .../Expression/DateSubtractOperator.php | 9 +- .../Expression/DateToPartsOperator.php | 9 +- .../Expression/DateToStringOperator.php | 17 +- src/Builder/Expression/DateTruncOperator.php | 9 +- src/Builder/Expression/DayOfMonthOperator.php | 9 +- src/Builder/Expression/DayOfWeekOperator.php | 9 +- src/Builder/Expression/DayOfYearOperator.php | 9 +- src/Builder/Expression/EqOperator.php | 17 +- src/Builder/Expression/FactoryTrait.php | 300 +++++++++--------- src/Builder/Expression/GetFieldOperator.php | 9 +- src/Builder/Expression/GtOperator.php | 17 +- src/Builder/Expression/GteOperator.php | 17 +- src/Builder/Expression/HourOperator.php | 9 +- src/Builder/Expression/IfNullOperator.php | 10 +- src/Builder/Expression/InOperator.php | 9 +- .../Expression/IndexOfArrayOperator.php | 9 +- src/Builder/Expression/IsArrayOperator.php | 12 +- src/Builder/Expression/IsNumberOperator.php | 12 +- .../Expression/IsoDayOfWeekOperator.php | 9 +- src/Builder/Expression/IsoWeekOperator.php | 9 +- .../Expression/IsoWeekYearOperator.php | 9 +- src/Builder/Expression/LetOperator.php | 9 +- src/Builder/Expression/LiteralOperator.php | 9 +- src/Builder/Expression/LtOperator.php | 17 +- src/Builder/Expression/LteOperator.php | 17 +- src/Builder/Expression/MapOperator.php | 9 +- src/Builder/Expression/MaxOperator.php | 10 +- .../Expression/MillisecondOperator.php | 9 +- src/Builder/Expression/MinOperator.php | 10 +- src/Builder/Expression/MinuteOperator.php | 9 +- src/Builder/Expression/MonthOperator.php | 9 +- src/Builder/Expression/NeOperator.php | 17 +- src/Builder/Expression/NotOperator.php | 9 +- src/Builder/Expression/OrOperator.php | 7 +- src/Builder/Expression/ReduceOperator.php | 17 +- src/Builder/Expression/SecondOperator.php | 9 +- src/Builder/Expression/SetFieldOperator.php | 9 +- src/Builder/Expression/SubtractOperator.php | 17 +- src/Builder/Expression/SwitchOperator.php | 9 +- src/Builder/Expression/ToBoolOperator.php | 12 +- src/Builder/Expression/ToDateOperator.php | 12 +- src/Builder/Expression/ToDecimalOperator.php | 12 +- src/Builder/Expression/ToDoubleOperator.php | 12 +- .../Expression/ToHashedIndexKeyOperator.php | 12 +- src/Builder/Expression/ToIntOperator.php | 12 +- src/Builder/Expression/ToLongOperator.php | 12 +- src/Builder/Expression/ToObjectIdOperator.php | 12 +- src/Builder/Expression/ToStringOperator.php | 12 +- src/Builder/Expression/TypeOperator.php | 12 +- src/Builder/Expression/WeekOperator.php | 9 +- src/Builder/Expression/YearOperator.php | 9 +- src/Builder/Query/AllOperator.php | 10 +- src/Builder/Query/ElemMatchOperator.php | 9 +- src/Builder/Query/EqOperator.php | 9 +- src/Builder/Query/ExprOperator.php | 12 +- src/Builder/Query/FactoryTrait.php | 41 +-- src/Builder/Query/GtOperator.php | 9 +- src/Builder/Query/GteOperator.php | 9 +- src/Builder/Query/LtOperator.php | 9 +- src/Builder/Query/LteOperator.php | 9 +- src/Builder/Query/NeOperator.php | 9 +- src/Builder/Query/NotOperator.php | 12 +- src/Builder/Search/EqualsOperator.php | 9 +- src/Builder/Search/FactoryTrait.php | 29 +- src/Builder/Search/InOperator.php | 9 +- src/Builder/Search/NearOperator.php | 9 +- src/Builder/Search/RangeOperator.php | 33 +- src/Builder/Stage.php | 5 +- src/Builder/Stage/AddFieldsStage.php | 10 +- src/Builder/Stage/BucketAutoStage.php | 9 +- src/Builder/Stage/BucketStage.php | 17 +- src/Builder/Stage/FactoryTrait.php | 52 +-- src/Builder/Stage/FluentFactoryTrait.php | 62 ++-- src/Builder/Stage/GraphLookupStage.php | 9 +- src/Builder/Stage/GroupStage.php | 9 +- src/Builder/Stage/ProjectStage.php | 10 +- src/Builder/Stage/RedactStage.php | 12 +- src/Builder/Stage/SetStage.php | 10 +- src/Builder/Stage/SetWindowFieldsStage.php | 9 +- src/Builder/Stage/SortByCountStage.php | 12 +- src/Builder/Stage/SortStage.php | 10 +- src/Builder/Type/QueryObject.php | 5 +- tests/Builder/BuilderEncoderTest.php | 42 +++ 114 files changed, 1006 insertions(+), 776 deletions(-) create mode 100644 src/Builder/Encoder/DateTimeEncoder.php diff --git a/generator/config/expressions.php b/generator/config/expressions.php index f77b45e79..9d8df47a6 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -6,6 +6,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON; use MongoDB\Builder\Pipeline; use MongoDB\Builder\Type; @@ -26,7 +27,7 @@ 'binData' => ['string', BSON\Binary::class], 'objectId' => [BSON\ObjectId::class], 'bool' => ['bool'], - 'date' => [BSON\UTCDateTime::class], + 'date' => [BSON\UTCDateTime::class, DateTimeInterface::class], 'null' => ['null'], 'regex' => [BSON\Regex::class], 'javascript' => ['string', BSON\Javascript::class], @@ -37,7 +38,7 @@ ]; // "any" accepts all the BSON types. No generic "object" or "mixed" -$bsonTypes['any'] = ['bool', 'int', 'float', 'string', 'array', 'null', stdClass::class, BSON\Type::class]; +$bsonTypes['any'] = ['bool', 'int', 'float', 'string', 'array', 'null', stdClass::class, BSON\Type::class, DateTimeInterface::class]; // "number" accepts all the numeric types $bsonTypes['number'] = ['int', 'float', BSON\Int64::class, BSON\Decimal128::class]; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index eb68663a1..fb84ad5ca 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -248,6 +248,8 @@ + + diff --git a/src/Builder/Accumulator/AddToSetAccumulator.php b/src/Builder/Accumulator/AddToSetAccumulator.php index 2c77a7458..7e29eed62 100644 --- a/src/Builder/Accumulator/AddToSetAccumulator.php +++ b/src/Builder/Accumulator/AddToSetAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class AddToSetAccumulator implements AccumulatorInterface, WindowInterface public const NAME = '$addToSet'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/BottomAccumulator.php b/src/Builder/Accumulator/BottomAccumulator.php index eecf0a013..8d4dd417a 100644 --- a/src/Builder/Accumulator/BottomAccumulator.php +++ b/src/Builder/Accumulator/BottomAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -34,16 +35,16 @@ final class BottomAccumulator implements AccumulatorInterface, WindowInterface, /** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ public readonly Document|Serializable|stdClass|array $sortBy; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public function __construct( Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Accumulator/BottomNAccumulator.php b/src/Builder/Accumulator/BottomNAccumulator.php index 3733889de..95f0d7555 100644 --- a/src/Builder/Accumulator/BottomNAccumulator.php +++ b/src/Builder/Accumulator/BottomNAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -43,18 +44,18 @@ final class BottomNAccumulator implements AccumulatorInterface, WindowInterface, /** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ public readonly Document|Serializable|stdClass|array $sortBy; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** * @param ResolvesToInt|int|string $n Limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public function __construct( ResolvesToInt|int|string $n, Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { if (is_string($n) && ! str_starts_with($n, '$')) { throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Accumulator/DerivativeAccumulator.php b/src/Builder/Accumulator/DerivativeAccumulator.php index 7db64533f..872ddde4d 100644 --- a/src/Builder/Accumulator/DerivativeAccumulator.php +++ b/src/Builder/Accumulator/DerivativeAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -37,8 +38,8 @@ final class DerivativeAccumulator implements WindowInterface, OperatorInterface public const NAME = '$derivative'; public const PROPERTIES = ['input' => 'input', 'unit' => 'unit']; - /** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input */ - public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input; + /** @var DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input */ + public readonly DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input; /** * @var Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -47,12 +48,12 @@ final class DerivativeAccumulator implements WindowInterface, OperatorInterface public readonly Optional|ResolvesToString|TimeUnit|string $unit; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input * @param Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". * If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ) { if (is_string($input) && ! str_starts_with($input, '$')) { diff --git a/src/Builder/Accumulator/FactoryTrait.php b/src/Builder/Accumulator/FactoryTrait.php index 512ff17bf..9e9257549 100644 --- a/src/Builder/Accumulator/FactoryTrait.php +++ b/src/Builder/Accumulator/FactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; @@ -63,10 +64,10 @@ public static function accumulator( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function addToSet( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): AddToSetAccumulator { return new AddToSetAccumulator($expression); } @@ -89,11 +90,11 @@ public static function avg(Decimal128|Int64|ResolvesToNumber|float|int|string $e * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public static function bottom( Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ): BottomAccumulator { return new BottomAccumulator($sortBy, $output); } @@ -106,12 +107,12 @@ public static function bottom( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ * @param ResolvesToInt|int|string $n Limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public static function bottomN( ResolvesToInt|int|string $n, Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ): BottomNAccumulator { return new BottomNAccumulator($n, $sortBy, $output); } @@ -174,12 +175,12 @@ public static function denseRank(): DenseRankAccumulator * New in MongoDB 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input * @param Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". * If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. */ public static function derivative( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ): DerivativeAccumulator { return new DerivativeAccumulator($input, $unit); @@ -221,10 +222,10 @@ public static function expMovingAvg( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function first( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): FirstAccumulator { return new FirstAccumulator($expression); } @@ -235,11 +236,11 @@ public static function first( * If the group contains fewer than n elements, $firstN returns all elements in the group. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. * @param ResolvesToInt|int|string $n A positive integral expression that is either a constant or depends on the _id value for $group. */ public static function firstN( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, ResolvesToInt|int|string $n, ): FirstNAccumulator { return new FirstNAccumulator($input, $n); @@ -250,12 +251,12 @@ public static function firstN( * New in MongoDB 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input * @param Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". * If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. */ public static function integral( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ): IntegralAccumulator { return new IntegralAccumulator($input, $unit); @@ -266,10 +267,10 @@ public static function integral( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function last( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): LastAccumulator { return new LastAccumulator($expression); } @@ -310,10 +311,10 @@ public static function linearFill( * New in MongoDB 5.2. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function locf( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): LocfAccumulator { return new LocfAccumulator($expression); } @@ -323,10 +324,10 @@ public static function locf( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function max( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): MaxAccumulator { return new MaxAccumulator($expression); } @@ -381,10 +382,10 @@ public static function mergeObjects( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function min( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): MinAccumulator { return new MinAccumulator($expression); } @@ -433,10 +434,10 @@ public static function percentile( * Changed in MongoDB 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function push( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): PushAccumulator { return new PushAccumulator($expression); } @@ -457,20 +458,20 @@ public static function rank(): RankAccumulator * New in MongoDB 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. * @param int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: * 1 specifies the document position after the current document. * -1 specifies the document position before the current document. * -2 specifies the document position that is two positions before the current document. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. * The default expression must evaluate to a constant value. * If you do not specify a default expression, $shift returns null for documents whose positions are outside of the implicit $setWindowFields stage window. */ public static function shift( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, int $by, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, ): ShiftAccumulator { return new ShiftAccumulator($output, $by, $default); } @@ -523,11 +524,11 @@ public static function sum(Decimal128|Int64|ResolvesToNumber|float|int|string $e * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public static function top( Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ): TopAccumulator { return new TopAccumulator($sortBy, $output); } @@ -541,12 +542,12 @@ public static function top( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ * @param ResolvesToInt|int|string $n limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public static function topN( ResolvesToInt|int|string $n, Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ): TopNAccumulator { return new TopNAccumulator($n, $sortBy, $output); } diff --git a/src/Builder/Accumulator/FirstAccumulator.php b/src/Builder/Accumulator/FirstAccumulator.php index 20e3b4ee2..580588b6b 100644 --- a/src/Builder/Accumulator/FirstAccumulator.php +++ b/src/Builder/Accumulator/FirstAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class FirstAccumulator implements AccumulatorInterface, WindowInterface, O public const NAME = '$first'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/FirstNAccumulator.php b/src/Builder/Accumulator/FirstNAccumulator.php index 55c2809d7..03d412fd7 100644 --- a/src/Builder/Accumulator/FirstNAccumulator.php +++ b/src/Builder/Accumulator/FirstNAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; @@ -35,18 +36,18 @@ final class FirstNAccumulator implements AccumulatorInterface, WindowInterface, public const NAME = '$firstN'; public const PROPERTIES = ['input' => 'input', 'n' => 'n']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; /** @var ResolvesToInt|int|string $n A positive integral expression that is either a constant or depends on the _id value for $group. */ public readonly ResolvesToInt|int|string $n; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. * @param ResolvesToInt|int|string $n A positive integral expression that is either a constant or depends on the _id value for $group. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, ResolvesToInt|int|string $n, ) { $this->input = $input; diff --git a/src/Builder/Accumulator/IntegralAccumulator.php b/src/Builder/Accumulator/IntegralAccumulator.php index a55a91062..3abe3ff9e 100644 --- a/src/Builder/Accumulator/IntegralAccumulator.php +++ b/src/Builder/Accumulator/IntegralAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -37,8 +38,8 @@ final class IntegralAccumulator implements WindowInterface, OperatorInterface public const NAME = '$integral'; public const PROPERTIES = ['input' => 'input', 'unit' => 'unit']; - /** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input */ - public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input; + /** @var DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input */ + public readonly DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input; /** * @var Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -47,12 +48,12 @@ final class IntegralAccumulator implements WindowInterface, OperatorInterface public readonly Optional|ResolvesToString|TimeUnit|string $unit; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $input * @param Optional|ResolvesToString|TimeUnit|string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". * If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ) { if (is_string($input) && ! str_starts_with($input, '$')) { diff --git a/src/Builder/Accumulator/LastAccumulator.php b/src/Builder/Accumulator/LastAccumulator.php index dd495538a..5d7635d6e 100644 --- a/src/Builder/Accumulator/LastAccumulator.php +++ b/src/Builder/Accumulator/LastAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class LastAccumulator implements AccumulatorInterface, WindowInterface, Op public const NAME = '$last'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/LocfAccumulator.php b/src/Builder/Accumulator/LocfAccumulator.php index 15ee21740..effb6e463 100644 --- a/src/Builder/Accumulator/LocfAccumulator.php +++ b/src/Builder/Accumulator/LocfAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -29,14 +30,15 @@ final class LocfAccumulator implements WindowInterface, OperatorInterface public const NAME = '$locf'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/MaxAccumulator.php b/src/Builder/Accumulator/MaxAccumulator.php index cf53cb8cd..7870591d2 100644 --- a/src/Builder/Accumulator/MaxAccumulator.php +++ b/src/Builder/Accumulator/MaxAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class MaxAccumulator implements AccumulatorInterface, WindowInterface, Ope public const NAME = '$max'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/MinAccumulator.php b/src/Builder/Accumulator/MinAccumulator.php index b90ef761b..3b8f5a05b 100644 --- a/src/Builder/Accumulator/MinAccumulator.php +++ b/src/Builder/Accumulator/MinAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class MinAccumulator implements AccumulatorInterface, WindowInterface, Ope public const NAME = '$min'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/PushAccumulator.php b/src/Builder/Accumulator/PushAccumulator.php index 8f04023a9..85576e0ce 100644 --- a/src/Builder/Accumulator/PushAccumulator.php +++ b/src/Builder/Accumulator/PushAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; @@ -29,14 +30,15 @@ final class PushAccumulator implements AccumulatorInterface, WindowInterface, Op public const NAME = '$push'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/ShiftAccumulator.php b/src/Builder/Accumulator/ShiftAccumulator.php index 5f4200307..e4674e9a3 100644 --- a/src/Builder/Accumulator/ShiftAccumulator.php +++ b/src/Builder/Accumulator/ShiftAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -28,8 +29,8 @@ final class ShiftAccumulator implements WindowInterface, OperatorInterface public const NAME = '$shift'; public const PROPERTIES = ['output' => 'output', 'by' => 'by', 'default' => 'default']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** * @var int $by Specifies an integer with a numeric document position relative to the current document in the output. @@ -41,27 +42,27 @@ final class ShiftAccumulator implements WindowInterface, OperatorInterface public readonly int $by; /** - * @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. + * @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. * The default expression must evaluate to a constant value. * If you do not specify a default expression, $shift returns null for documents whose positions are outside of the implicit $setWindowFields stage window. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. * @param int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: * 1 specifies the document position after the current document. * -1 specifies the document position before the current document. * -2 specifies the document position that is two positions before the current document. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. * The default expression must evaluate to a constant value. * If you do not specify a default expression, $shift returns null for documents whose positions are outside of the implicit $setWindowFields stage window. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, int $by, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, ) { $this->output = $output; $this->by = $by; diff --git a/src/Builder/Accumulator/TopAccumulator.php b/src/Builder/Accumulator/TopAccumulator.php index 7fac97efc..d7fb258f1 100644 --- a/src/Builder/Accumulator/TopAccumulator.php +++ b/src/Builder/Accumulator/TopAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -35,16 +36,16 @@ final class TopAccumulator implements AccumulatorInterface, OperatorInterface /** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ public readonly Document|Serializable|stdClass|array $sortBy; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public function __construct( Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Accumulator/TopNAccumulator.php b/src/Builder/Accumulator/TopNAccumulator.php index 58e29fcaf..45087d5e0 100644 --- a/src/Builder/Accumulator/TopNAccumulator.php +++ b/src/Builder/Accumulator/TopNAccumulator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Accumulator; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -43,18 +44,18 @@ final class TopNAccumulator implements AccumulatorInterface, OperatorInterface /** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ public readonly Document|Serializable|stdClass|array $sortBy; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** * @param ResolvesToInt|int|string $n limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Represents the output for each element in the group and can be any expression. */ public function __construct( ResolvesToInt|int|string $n, Document|Serializable|stdClass|array $sortBy, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { if (is_string($n) && ! str_starts_with($n, '$')) { throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 0d7a5a90c..a630d4f0d 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -4,7 +4,10 @@ namespace MongoDB\Builder; +use DateTimeInterface; +use MongoDB\BSON\Type; use MongoDB\Builder\Encoder\CombinedFieldQueryEncoder; +use MongoDB\Builder\Encoder\DateTimeEncoder; use MongoDB\Builder\Encoder\DictionaryEncoder; use MongoDB\Builder\Encoder\ExpressionEncoder; use MongoDB\Builder\Encoder\FieldPathEncoder; @@ -31,10 +34,10 @@ use function array_key_exists; use function is_object; -/** @template-implements Encoder */ +/** @template-implements Encoder */ final class BuilderEncoder implements Encoder { - /** @template-use EncodeIfSupported */ + /** @template-use EncodeIfSupported */ use EncodeIfSupported; /** @var array> */ @@ -47,6 +50,7 @@ final class BuilderEncoder implements Encoder QueryObject::class => QueryEncoder::class, OutputWindow::class => OutputWindowEncoder::class, OperatorInterface::class => OperatorEncoder::class, + DateTimeInterface::class => DateTimeEncoder::class, ]; /** @var array */ @@ -67,7 +71,7 @@ public function canEncode(mixed $value): bool return (bool) $this->getEncoderFor($value)?->canEncode($value); } - public function encode(mixed $value): stdClass|array|string|int + public function encode(mixed $value): Type|stdClass|array|string|int { $encoder = $this->getEncoderFor($value); diff --git a/src/Builder/Encoder/AbstractExpressionEncoder.php b/src/Builder/Encoder/AbstractExpressionEncoder.php index d593f4e3b..7a0f437b2 100644 --- a/src/Builder/Encoder/AbstractExpressionEncoder.php +++ b/src/Builder/Encoder/AbstractExpressionEncoder.php @@ -4,6 +4,7 @@ namespace MongoDB\Builder\Encoder; +use MongoDB\BSON\Type; use MongoDB\Builder\BuilderEncoder; use stdClass; @@ -11,7 +12,7 @@ use function is_array; /** - * @template BSONType of stdClass|array|string|int + * @template BSONType of Type|stdClass|array|string|int * @template NativeType * @template-implements ExpressionEncoder * @internal @@ -25,6 +26,7 @@ final public function __construct(protected readonly BuilderEncoder $encoder) /** * Nested arrays and objects must be encoded recursively. * + * @psalm-template T * @psalm-param T $value * * @psalm-return (T is stdClass ? stdClass : (T is array ? array : mixed)) diff --git a/src/Builder/Encoder/DateTimeEncoder.php b/src/Builder/Encoder/DateTimeEncoder.php new file mode 100644 index 000000000..c4b98f2c4 --- /dev/null +++ b/src/Builder/Encoder/DateTimeEncoder.php @@ -0,0 +1,35 @@ + + * @internal + */ +final class DateTimeEncoder extends AbstractExpressionEncoder +{ + /** @template-use EncodeIfSupported */ + use EncodeIfSupported; + + /** @psalm-assert-if-true DateTimeInterface $value */ + public function canEncode(mixed $value): bool + { + return $value instanceof DateTimeInterface; + } + + public function encode(mixed $value): UTCDateTime + { + if (! $this->canEncode($value)) { + throw UnsupportedValueException::invalidEncodableValue($value); + } + + return new UTCDateTime($value); + } +} diff --git a/src/Builder/Encoder/ExpressionEncoder.php b/src/Builder/Encoder/ExpressionEncoder.php index b1acab2ee..f50da33d3 100644 --- a/src/Builder/Encoder/ExpressionEncoder.php +++ b/src/Builder/Encoder/ExpressionEncoder.php @@ -4,12 +4,13 @@ namespace MongoDB\Builder\Encoder; +use MongoDB\BSON\Type; use MongoDB\Builder\BuilderEncoder; use MongoDB\Codec\Encoder; use stdClass; /** - * @template BSONType of stdClass|array|string|int + * @template BSONType of Type|stdClass|array|string|int * @template NativeType * @template-extends Encoder * @internal diff --git a/src/Builder/Expression/AddOperator.php b/src/Builder/Expression/AddOperator.php index c7fe70d36..9eb139f36 100644 --- a/src/Builder/Expression/AddOperator.php +++ b/src/Builder/Expression/AddOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -29,15 +30,15 @@ final class AddOperator implements ResolvesToInt, ResolvesToLong, ResolvesToDoub public const NAME = '$add'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ + /** @var list $expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public readonly array $expression; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. * @no-named-arguments */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string ...$expression, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string ...$expression, ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); diff --git a/src/Builder/Expression/AndOperator.php b/src/Builder/Expression/AndOperator.php index 8e3364ab3..5e9121677 100644 --- a/src/Builder/Expression/AndOperator.php +++ b/src/Builder/Expression/AndOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\Type; @@ -31,15 +32,15 @@ final class AndOperator implements ResolvesToBool, OperatorInterface public const NAME = '$and'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression */ + /** @var list $expression */ public readonly array $expression; /** - * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|Type|array|bool|float|int|null|stdClass|string ...$expression * @no-named-arguments */ public function __construct( - Decimal128|Int64|Type|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Decimal128|Int64|Type|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); diff --git a/src/Builder/Expression/CaseOperator.php b/src/Builder/Expression/CaseOperator.php index 8680befdf..686d27ec9 100644 --- a/src/Builder/Expression/CaseOperator.php +++ b/src/Builder/Expression/CaseOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -34,16 +35,16 @@ final class CaseOperator implements SwitchBranchInterface, OperatorInterface /** @var ResolvesToBool|bool|string $case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. */ public readonly ResolvesToBool|bool|string $case; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then; /** * @param ResolvesToBool|bool|string $case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. */ public function __construct( ResolvesToBool|bool|string $case, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, ) { if (is_string($case) && ! str_starts_with($case, '$')) { throw new InvalidArgumentException('Argument $case can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Expression/CmpOperator.php b/src/Builder/Expression/CmpOperator.php index 72f27face..7e090f242 100644 --- a/src/Builder/Expression/CmpOperator.php +++ b/src/Builder/Expression/CmpOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class CmpOperator implements ResolvesToInt, OperatorInterface public const NAME = '$cmp'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/CondOperator.php b/src/Builder/Expression/CondOperator.php index 7c71f3396..ba34c910a 100644 --- a/src/Builder/Expression/CondOperator.php +++ b/src/Builder/Expression/CondOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -33,21 +34,21 @@ final class CondOperator implements ResolvesToAny, OperatorInterface /** @var ResolvesToBool|bool|string $if */ public readonly ResolvesToBool|bool|string $if; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else; /** * @param ResolvesToBool|bool|string $if - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else */ public function __construct( ResolvesToBool|bool|string $if, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else, ) { if (is_string($if) && ! str_starts_with($if, '$')) { throw new InvalidArgumentException('Argument $if can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Expression/ConvertOperator.php b/src/Builder/Expression/ConvertOperator.php index 92bfecb02..3a8d3764c 100644 --- a/src/Builder/Expression/ConvertOperator.php +++ b/src/Builder/Expression/ConvertOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -28,37 +29,37 @@ final class ConvertOperator implements ResolvesToAny, OperatorInterface public const NAME = '$convert'; public const PROPERTIES = ['input' => 'input', 'to' => 'to', 'onError' => 'onError', 'onNull' => 'onNull']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; /** @var ResolvesToInt|ResolvesToString|int|string $to */ public readonly ResolvesToInt|ResolvesToString|int|string $to; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. * If unspecified, the operation throws an error upon encountering an error and stops. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. * If unspecified, $convert returns null if the input is null or missing. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input * @param ResolvesToInt|ResolvesToString|int|string $to - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. * If unspecified, the operation throws an error upon encountering an error and stops. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. * If unspecified, $convert returns null if the input is null or missing. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, ResolvesToInt|ResolvesToString|int|string $to, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->input = $input; $this->to = $to; diff --git a/src/Builder/Expression/DateAddOperator.php b/src/Builder/Expression/DateAddOperator.php index 1c23c4a26..333cfca11 100644 --- a/src/Builder/Expression/DateAddOperator.php +++ b/src/Builder/Expression/DateAddOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; @@ -33,8 +34,8 @@ final class DateAddOperator implements ResolvesToDate, OperatorInterface public const NAME = '$dateAdd'; public const PROPERTIES = ['startDate' => 'startDate', 'unit' => 'unit', 'amount' => 'amount', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; /** @var ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. */ public readonly ResolvesToString|TimeUnit|string $unit; @@ -46,13 +47,13 @@ final class DateAddOperator implements ResolvesToDate, OperatorInterface public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int|string $amount * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, ResolvesToString|TimeUnit|string $unit, Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, diff --git a/src/Builder/Expression/DateDiffOperator.php b/src/Builder/Expression/DateDiffOperator.php index 24b8fb50f..8c4f5e5b4 100644 --- a/src/Builder/Expression/DateDiffOperator.php +++ b/src/Builder/Expression/DateDiffOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -39,11 +40,11 @@ final class DateDiffOperator implements ResolvesToInt, OperatorInterface 'startOfWeek' => 'startOfWeek', ]; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate; /** @var ResolvesToString|TimeUnit|string $unit The time measurement unit between the startDate and endDate */ public readonly ResolvesToString|TimeUnit|string $unit; @@ -55,15 +56,15 @@ final class DateDiffOperator implements ResolvesToInt, OperatorInterface public readonly Optional|ResolvesToString|string $startOfWeek; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The time measurement unit between the startDate and endDate * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. * @param Optional|ResolvesToString|string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate, ResolvesToString|TimeUnit|string $unit, Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|ResolvesToString|string $startOfWeek = Optional::Undefined, diff --git a/src/Builder/Expression/DateFromStringOperator.php b/src/Builder/Expression/DateFromStringOperator.php index 60c20fed1..ad796df98 100644 --- a/src/Builder/Expression/DateFromStringOperator.php +++ b/src/Builder/Expression/DateFromStringOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -47,33 +48,33 @@ final class DateFromStringOperator implements ResolvesToDate, OperatorInterface public readonly Optional|ResolvesToString|string $timezone; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. * If you do not specify onError, $dateFromString throws an error if it cannot parse dateString. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. * If you do not specify onNull and dateString is null or missing, then $dateFromString outputs null. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; /** * @param ResolvesToString|string $dateString The date/time string to convert to a date object. * @param Optional|ResolvesToString|string $format The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. * If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. * @param Optional|ResolvesToString|string $timezone The time zone to use to format the date. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. * If you do not specify onError, $dateFromString throws an error if it cannot parse dateString. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. * If you do not specify onNull and dateString is null or missing, then $dateFromString outputs null. */ public function __construct( ResolvesToString|string $dateString, Optional|ResolvesToString|string $format = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->dateString = $dateString; $this->format = $format; diff --git a/src/Builder/Expression/DateSubtractOperator.php b/src/Builder/Expression/DateSubtractOperator.php index 3deda4b37..91c790872 100644 --- a/src/Builder/Expression/DateSubtractOperator.php +++ b/src/Builder/Expression/DateSubtractOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; @@ -33,8 +34,8 @@ final class DateSubtractOperator implements ResolvesToDate, OperatorInterface public const NAME = '$dateSubtract'; public const PROPERTIES = ['startDate' => 'startDate', 'unit' => 'unit', 'amount' => 'amount', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate; /** @var ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. */ public readonly ResolvesToString|TimeUnit|string $unit; @@ -46,13 +47,13 @@ final class DateSubtractOperator implements ResolvesToDate, OperatorInterface public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int|string $amount * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, ResolvesToString|TimeUnit|string $unit, Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, diff --git a/src/Builder/Expression/DateToPartsOperator.php b/src/Builder/Expression/DateToPartsOperator.php index 14771858f..8e23c751c 100644 --- a/src/Builder/Expression/DateToPartsOperator.php +++ b/src/Builder/Expression/DateToPartsOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,8 +32,8 @@ final class DateToPartsOperator implements ResolvesToObject, OperatorInterface public const NAME = '$dateToParts'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone', 'iso8601' => 'iso8601']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; @@ -41,12 +42,12 @@ final class DateToPartsOperator implements ResolvesToObject, OperatorInterface public readonly Optional|bool $iso8601; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ) { diff --git a/src/Builder/Expression/DateToStringOperator.php b/src/Builder/Expression/DateToStringOperator.php index 7861f6990..703ac643e 100644 --- a/src/Builder/Expression/DateToStringOperator.php +++ b/src/Builder/Expression/DateToStringOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\Type; @@ -34,8 +35,8 @@ final class DateToStringOperator implements ResolvesToString, OperatorInterface public const NAME = '$dateToString'; public const PROPERTIES = ['date' => 'date', 'format' => 'format', 'timezone' => 'timezone', 'onNull' => 'onNull']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** * @var Optional|ResolvesToString|string $format The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. @@ -47,24 +48,24 @@ final class DateToStringOperator implements ResolvesToString, OperatorInterface public readonly Optional|ResolvesToString|string $timezone; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $format The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. * If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. * @param Optional|ResolvesToString|string $timezone The time zone to use to format the date. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $format = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Expression/DateTruncOperator.php b/src/Builder/Expression/DateTruncOperator.php index 9e84976dd..af550491f 100644 --- a/src/Builder/Expression/DateTruncOperator.php +++ b/src/Builder/Expression/DateTruncOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; @@ -41,8 +42,8 @@ final class DateTruncOperator implements ResolvesToDate, OperatorInterface 'startOfWeek' => 'startOfWeek', ]; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** * @var ResolvesToString|TimeUnit|string $unit The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. @@ -66,7 +67,7 @@ final class DateTruncOperator implements ResolvesToDate, OperatorInterface public readonly Optional|string $startOfWeek; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. * Together, binSize and unit specify the time period used in the $dateTrunc calculation. * @param Optional|Decimal128|Int64|ResolvesToNumber|float|int|string $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. @@ -76,7 +77,7 @@ final class DateTruncOperator implements ResolvesToDate, OperatorInterface * unit is week. Defaults to Sunday. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, ResolvesToString|TimeUnit|string $unit, Optional|Decimal128|Int64|ResolvesToNumber|float|int|string $binSize = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, diff --git a/src/Builder/Expression/DayOfMonthOperator.php b/src/Builder/Expression/DayOfMonthOperator.php index 041680cae..ce3df4a86 100644 --- a/src/Builder/Expression/DayOfMonthOperator.php +++ b/src/Builder/Expression/DayOfMonthOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class DayOfMonthOperator implements ResolvesToInt, OperatorInterface public const NAME = '$dayOfMonth'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/DayOfWeekOperator.php b/src/Builder/Expression/DayOfWeekOperator.php index ac3a2ec6d..db07c7a2a 100644 --- a/src/Builder/Expression/DayOfWeekOperator.php +++ b/src/Builder/Expression/DayOfWeekOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class DayOfWeekOperator implements ResolvesToInt, OperatorInterface public const NAME = '$dayOfWeek'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/DayOfYearOperator.php b/src/Builder/Expression/DayOfYearOperator.php index dff335adb..530fc619c 100644 --- a/src/Builder/Expression/DayOfYearOperator.php +++ b/src/Builder/Expression/DayOfYearOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class DayOfYearOperator implements ResolvesToInt, OperatorInterface public const NAME = '$dayOfYear'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/EqOperator.php b/src/Builder/Expression/EqOperator.php index f78d0ff3b..5db6ed26a 100644 --- a/src/Builder/Expression/EqOperator.php +++ b/src/Builder/Expression/EqOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class EqOperator implements ResolvesToBool, OperatorInterface public const NAME = '$eq'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/FactoryTrait.php b/src/Builder/Expression/FactoryTrait.php index cb6ed577d..c7bd1d801 100644 --- a/src/Builder/Expression/FactoryTrait.php +++ b/src/Builder/Expression/FactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; @@ -74,10 +75,10 @@ public static function acosh(Decimal128|Int64|ResolvesToNumber|float|int|string * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ * @no-named-arguments - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public static function add( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string ...$expression, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string ...$expression, ): AddOperator { return new AddOperator(...$expression); } @@ -99,10 +100,10 @@ public static function allElementsTrue( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/ * @no-named-arguments - * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|Type|array|bool|float|int|null|stdClass|string ...$expression */ public static function and( - Decimal128|Int64|Type|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Decimal128|Int64|Type|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): AndOperator { return new AndOperator(...$expression); } @@ -306,11 +307,11 @@ public static function bsonSize( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ * @param ResolvesToBool|bool|string $case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then Can be any valid expression. */ public static function case( ResolvesToBool|bool|string $case, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, ): CaseOperator { return new CaseOperator($case, $then); } @@ -330,12 +331,12 @@ public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int|string $ * Returns 0 if the two values are equivalent, 1 if the first value is greater than the second, and -1 if the first value is less than the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function cmp( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): CmpOperator { return new CmpOperator($expression1, $expression2); } @@ -370,13 +371,13 @@ public static function concatArrays( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ * @param ResolvesToBool|bool|string $if - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $then + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $else */ public static function cond( ResolvesToBool|bool|string $if, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else, ): CondOperator { return new CondOperator($if, $then, $else); } @@ -386,18 +387,18 @@ public static function cond( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input * @param ResolvesToInt|ResolvesToString|int|string $to - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. * If unspecified, the operation throws an error upon encountering an error and stops. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the input is null or missing. The arguments can be any valid expression. * If unspecified, $convert returns null if the input is null or missing. */ public static function convert( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input, ResolvesToInt|ResolvesToString|int|string $to, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): ConvertOperator { return new ConvertOperator($input, $to, $onError, $onNull); } @@ -430,13 +431,13 @@ public static function cosh(Decimal128|Int64|ResolvesToNumber|float|int|string $ * Adds a number of time units to a date object. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int|string $amount * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function dateAdd( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, ResolvesToString|TimeUnit|string $unit, Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, @@ -448,15 +449,15 @@ public static function dateAdd( * Returns the difference between two dates. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The time measurement unit between the startDate and endDate * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. * @param Optional|ResolvesToString|string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public static function dateDiff( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $endDate, ResolvesToString|TimeUnit|string $unit, Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|ResolvesToString|string $startOfWeek = Optional::Undefined, @@ -504,17 +505,17 @@ public static function dateFromParts( * @param Optional|ResolvesToString|string $format The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. * If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. * @param Optional|ResolvesToString|string $timezone The time zone to use to format the date. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onError If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. * If you do not specify onError, $dateFromString throws an error if it cannot parse dateString. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. * If you do not specify onNull and dateString is null or missing, then $dateFromString outputs null. */ public static function dateFromString( ResolvesToString|string $dateString, Optional|ResolvesToString|string $format = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): DateFromStringOperator { return new DateFromStringOperator($dateString, $format, $timezone, $onError, $onNull); } @@ -523,13 +524,13 @@ public static function dateFromString( * Subtracts a number of time units from a date object. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $startDate The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int|string $amount * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function dateSubtract( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $startDate, ResolvesToString|TimeUnit|string $unit, Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, @@ -541,12 +542,12 @@ public static function dateSubtract( * Returns a document containing the constituent parts of a date. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public static function dateToParts( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ): DateToPartsOperator { @@ -557,18 +558,18 @@ public static function dateToParts( * Returns the date as a formatted string. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $format The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. * If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. * @param Optional|ResolvesToString|string $timezone The time zone to use to format the date. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public static function dateToString( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $format = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): DateToStringOperator { return new DateToStringOperator($date, $format, $timezone, $onNull); } @@ -577,7 +578,7 @@ public static function dateToString( * Truncates a date. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|TimeUnit|string $unit The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. * Together, binSize and unit specify the time period used in the $dateTrunc calculation. * @param Optional|Decimal128|Int64|ResolvesToNumber|float|int|string $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. @@ -587,7 +588,7 @@ public static function dateToString( * unit is week. Defaults to Sunday. */ public static function dateTrunc( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, ResolvesToString|TimeUnit|string $unit, Optional|Decimal128|Int64|ResolvesToNumber|float|int|string $binSize = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, @@ -600,11 +601,11 @@ public static function dateTrunc( * Returns the day of the month for a date as a number between 1 and 31. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function dayOfMonth( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): DayOfMonthOperator { return new DayOfMonthOperator($date, $timezone); @@ -614,11 +615,11 @@ public static function dayOfMonth( * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function dayOfWeek( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): DayOfWeekOperator { return new DayOfWeekOperator($date, $timezone); @@ -628,11 +629,11 @@ public static function dayOfWeek( * Returns the day of the year for a date as a number between 1 and 366 (leap year). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function dayOfYear( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): DayOfYearOperator { return new DayOfYearOperator($date, $timezone); @@ -669,12 +670,12 @@ public static function divide( * Returns true if the values are equivalent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function eq( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): EqOperator { return new EqOperator($expression1, $expression2); } @@ -770,12 +771,12 @@ public static function function( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ * @param ResolvesToString|string $field Field in the input object for which you want to return a value. field can be any valid expression that resolves to a string constant. * If field begins with a dollar sign ($), place the field name inside of a $literal expression to return its value. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT * A valid expression that contains the field for which you want to return a value. input must resolve to an object, missing, null, or undefined. If omitted, defaults to the document currently being processed in the pipeline ($$CURRENT). */ public static function getField( ResolvesToString|string $field, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, ): GetFieldOperator { return new GetFieldOperator($field, $input); } @@ -784,12 +785,12 @@ public static function getField( * Returns true if the first value is greater than the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function gt( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): GtOperator { return new GtOperator($expression1, $expression2); } @@ -798,12 +799,12 @@ public static function gt( * Returns true if the first value is greater than or equal to the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function gte( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): GteOperator { return new GteOperator($expression1, $expression2); } @@ -812,11 +813,11 @@ public static function gte( * Returns the hour for a date as a number between 0 and 23. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function hour( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): HourOperator { return new HourOperator($date, $timezone); @@ -827,10 +828,10 @@ public static function hour( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ * @no-named-arguments - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression */ public static function ifNull( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): IfNullOperator { return new IfNullOperator(...$expression); } @@ -839,11 +840,11 @@ public static function ifNull( * Returns a boolean indicating whether a specified value is in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. * @param BSONArray|PackedArray|ResolvesToArray|array|string $array Any valid expression that resolves to an array. */ public static function in( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, PackedArray|ResolvesToArray|BSONArray|array|string $array, ): InOperator { return new InOperator($expression, $array); @@ -856,7 +857,7 @@ public static function in( * @param BSONArray|PackedArray|ResolvesToArray|array|string $array Can be any valid expression as long as it resolves to an array. * If the array expression resolves to a value of null or refers to a field that is missing, $indexOfArray returns null. * If the array expression does not resolve to an array or null nor refers to a missing field, $indexOfArray returns an error. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search * @param Optional|ResolvesToInt|int|string $start An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. * If unspecified, the starting index position for the search is the beginning of the string. * @param Optional|ResolvesToInt|int|string $end An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. @@ -864,7 +865,7 @@ public static function in( */ public static function indexOfArray( PackedArray|ResolvesToArray|BSONArray|array|string $array, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search, Optional|ResolvesToInt|int|string $start = Optional::Undefined, Optional|ResolvesToInt|int|string $end = Optional::Undefined, ): IndexOfArrayOperator { @@ -919,10 +920,10 @@ public static function indexOfCP( * Determines if the operand is an array. Returns a boolean. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function isArray( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): IsArrayOperator { return new IsArrayOperator($expression); } @@ -933,10 +934,10 @@ public static function isArray( * New in MongoDB 4.4. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function isNumber( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): IsNumberOperator { return new IsNumberOperator($expression); } @@ -945,11 +946,11 @@ public static function isNumber( * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function isoDayOfWeek( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): IsoDayOfWeekOperator { return new IsoDayOfWeekOperator($date, $timezone); @@ -959,11 +960,11 @@ public static function isoDayOfWeek( * Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year's first Thursday. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function isoWeek( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): IsoWeekOperator { return new IsoWeekOperator($date, $timezone); @@ -973,11 +974,11 @@ public static function isoWeek( * Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 (ISO 8601) and ends with the Sunday of the last week (ISO 8601). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function isoWeekYear( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): IsoWeekYearOperator { return new IsoWeekYearOperator($date, $timezone); @@ -1015,11 +1016,11 @@ public static function lastN( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ * @param Document|Serializable|array|stdClass $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ public static function let( Document|Serializable|stdClass|array $vars, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ): LetOperator { return new LetOperator($vars, $in); } @@ -1028,10 +1029,11 @@ public static function let( * Return a value without parsing. Use for values that the aggregation pipeline may interpret as an expression. For example, use a $literal expression to a string that starts with a dollar sign ($) to avoid parsing as a field path. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ - * @param Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public static function literal(Type|stdClass|array|bool|float|int|null|string $value): LiteralOperator - { + public static function literal( + DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value, + ): LiteralOperator { return new LiteralOperator($value); } @@ -1076,12 +1078,12 @@ public static function log10(Decimal128|Int64|ResolvesToNumber|float|int|string * Returns true if the first value is less than the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function lt( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): LtOperator { return new LtOperator($expression1, $expression2); } @@ -1090,12 +1092,12 @@ public static function lt( * Returns true if the first value is less than or equal to the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function lte( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): LteOperator { return new LteOperator($expression1, $expression2); } @@ -1122,12 +1124,12 @@ public static function ltrim( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ * @param BSONArray|PackedArray|ResolvesToArray|array|string $input An expression that resolves to an array. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. * @param Optional|ResolvesToString|string $as A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. */ public static function map( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, Optional|ResolvesToString|string $as = Optional::Undefined, ): MapOperator { return new MapOperator($input, $in, $as); @@ -1139,10 +1141,10 @@ public static function map( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ * @no-named-arguments - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression */ public static function max( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): MaxOperator { return new MaxOperator(...$expression); } @@ -1208,11 +1210,11 @@ public static function meta(string $keyword): MetaOperator * Returns the milliseconds of a date as a number between 0 and 999. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function millisecond( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): MillisecondOperator { return new MillisecondOperator($date, $timezone); @@ -1224,10 +1226,10 @@ public static function millisecond( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ * @no-named-arguments - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression */ public static function min( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): MinOperator { return new MinOperator(...$expression); } @@ -1250,11 +1252,11 @@ public static function minN( * Returns the minute for a date as a number between 0 and 59. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function minute( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): MinuteOperator { return new MinuteOperator($date, $timezone); @@ -1278,11 +1280,11 @@ public static function mod( * Returns the month for a date as a number between 1 (January) and 12 (December). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function month( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): MonthOperator { return new MonthOperator($date, $timezone); @@ -1306,12 +1308,12 @@ public static function multiply( * Returns true if the values are not equivalent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public static function ne( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ): NeOperator { return new NeOperator($expression1, $expression2); } @@ -1320,10 +1322,10 @@ public static function ne( * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ - * @param ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression */ public static function not( - Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): NotOperator { return new NotOperator($expression); } @@ -1345,10 +1347,10 @@ public static function objectToArray( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ * @no-named-arguments - * @param ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string ...$expression */ public static function or( - Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): OrOperator { return new OrOperator(...$expression); } @@ -1437,16 +1439,16 @@ public static function range( * @param BSONArray|PackedArray|ResolvesToArray|array|string $input Can be any valid expression that resolves to an array. * If the argument resolves to a value of null or refers to a missing field, $reduce returns null. * If the argument does not resolve to an array or null nor refers to a missing field, $reduce returns an error. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. * During evaluation of the in expression, two variables will be available: * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ public static function reduce( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ): ReduceOperator { return new ReduceOperator($input, $initialValue, $in); } @@ -1584,11 +1586,11 @@ public static function rtrim( * Returns the seconds for a date as a number between 0 and 60 (leap seconds). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function second( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): SecondOperator { return new SecondOperator($date, $timezone); @@ -1628,13 +1630,13 @@ public static function setEquals( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ * @param ResolvesToString|string $field Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. * @param Document|ResolvesToObject|Serializable|array|stdClass|string $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. * Set to $$REMOVE to remove field from the input document. */ public static function setField( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, ): SetFieldOperator { return new SetFieldOperator($field, $input, $value); } @@ -1890,12 +1892,12 @@ public static function substrCP( * Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 */ public static function subtract( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1, - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2, ): SubtractOperator { return new SubtractOperator($expression1, $expression2); } @@ -1922,12 +1924,12 @@ public static function sum( * - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. * - then Can be any valid expression. * The branches array must contain at least one branch document. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. * Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. */ public static function switch( PackedArray|BSONArray|array $branches, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ): SwitchOperator { return new SwitchOperator($branches, $default); } @@ -1961,10 +1963,10 @@ public static function tanh(Decimal128|Int64|ResolvesToNumber|float|int|string $ * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toBool( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToBoolOperator { return new ToBoolOperator($expression); } @@ -1974,10 +1976,10 @@ public static function toBool( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toDate( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToDateOperator { return new ToDateOperator($expression); } @@ -1987,10 +1989,10 @@ public static function toDate( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toDecimal( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToDecimalOperator { return new ToDecimalOperator($expression); } @@ -2000,10 +2002,10 @@ public static function toDecimal( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toDouble( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToDoubleOperator { return new ToDoubleOperator($expression); } @@ -2012,10 +2014,10 @@ public static function toDouble( * Computes and returns the hash value of the input expression using the same hash function that MongoDB uses to create a hashed index. A hash function maps a key or string to a fixed-size numeric value. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash */ public static function toHashedIndexKey( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, ): ToHashedIndexKeyOperator { return new ToHashedIndexKeyOperator($value); } @@ -2025,10 +2027,10 @@ public static function toHashedIndexKey( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toInt( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToIntOperator { return new ToIntOperator($expression); } @@ -2038,10 +2040,10 @@ public static function toInt( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toLong( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToLongOperator { return new ToLongOperator($expression); } @@ -2062,10 +2064,10 @@ public static function toLower(ResolvesToString|string $expression): ToLowerOper * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toObjectId( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToObjectIdOperator { return new ToObjectIdOperator($expression); } @@ -2075,10 +2077,10 @@ public static function toObjectId( * New in MongoDB 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function toString( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ToStringOperator { return new ToStringOperator($expression); } @@ -2154,10 +2156,10 @@ public static function tsSecond(Timestamp|ResolvesToTimestamp|int|string $expres * Return the BSON data type of the field. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function type( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): TypeOperator { return new TypeOperator($expression); } @@ -2181,11 +2183,11 @@ public static function unsetField( * Returns the week number for a date as a number between 0 (the partial week that precedes the first Sunday of the year) and 53 (leap year). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function week( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): WeekOperator { return new WeekOperator($date, $timezone); @@ -2195,11 +2197,11 @@ public static function week( * Returns the year for a date as a number (e.g. 2014). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public static function year( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ): YearOperator { return new YearOperator($date, $timezone); diff --git a/src/Builder/Expression/GetFieldOperator.php b/src/Builder/Expression/GetFieldOperator.php index 622bacb85..faf2272e8 100644 --- a/src/Builder/Expression/GetFieldOperator.php +++ b/src/Builder/Expression/GetFieldOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -35,20 +36,20 @@ final class GetFieldOperator implements ResolvesToAny, OperatorInterface public readonly ResolvesToString|string $field; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT * A valid expression that contains the field for which you want to return a value. input must resolve to an object, missing, null, or undefined. If omitted, defaults to the document currently being processed in the pipeline ($$CURRENT). */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input; /** * @param ResolvesToString|string $field Field in the input object for which you want to return a value. field can be any valid expression that resolves to a string constant. * If field begins with a dollar sign ($), place the field name inside of a $literal expression to return its value. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input Default: $$CURRENT * A valid expression that contains the field for which you want to return a value. input must resolve to an object, missing, null, or undefined. If omitted, defaults to the document currently being processed in the pipeline ($$CURRENT). */ public function __construct( ResolvesToString|string $field, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, ) { $this->field = $field; $this->input = $input; diff --git a/src/Builder/Expression/GtOperator.php b/src/Builder/Expression/GtOperator.php index fda780fff..9d92a714e 100644 --- a/src/Builder/Expression/GtOperator.php +++ b/src/Builder/Expression/GtOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class GtOperator implements ResolvesToBool, OperatorInterface public const NAME = '$gt'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/GteOperator.php b/src/Builder/Expression/GteOperator.php index 8f5792770..4a6708ca7 100644 --- a/src/Builder/Expression/GteOperator.php +++ b/src/Builder/Expression/GteOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class GteOperator implements ResolvesToBool, OperatorInterface public const NAME = '$gte'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/HourOperator.php b/src/Builder/Expression/HourOperator.php index 8110c09c4..ffbd5ac46 100644 --- a/src/Builder/Expression/HourOperator.php +++ b/src/Builder/Expression/HourOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class HourOperator implements ResolvesToInt, OperatorInterface public const NAME = '$hour'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/IfNullOperator.php b/src/Builder/Expression/IfNullOperator.php index 51c393d28..878944cdd 100644 --- a/src/Builder/Expression/IfNullOperator.php +++ b/src/Builder/Expression/IfNullOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -29,15 +30,16 @@ final class IfNullOperator implements ResolvesToAny, OperatorInterface public const NAME = '$ifNull'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression */ + /** @var list $expression */ public readonly array $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression * @no-named-arguments */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Expression/InOperator.php b/src/Builder/Expression/InOperator.php index 2bc43265f..5c4d408f1 100644 --- a/src/Builder/Expression/InOperator.php +++ b/src/Builder/Expression/InOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -34,18 +35,18 @@ final class InOperator implements ResolvesToBool, OperatorInterface public const NAME = '$in'; public const PROPERTIES = ['expression' => 'expression', 'array' => 'array']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** @var BSONArray|PackedArray|ResolvesToArray|array|string $array Any valid expression that resolves to an array. */ public readonly PackedArray|ResolvesToArray|BSONArray|array|string $array; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. * @param BSONArray|PackedArray|ResolvesToArray|array|string $array Any valid expression that resolves to an array. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, PackedArray|ResolvesToArray|BSONArray|array|string $array, ) { $this->expression = $expression; diff --git a/src/Builder/Expression/IndexOfArrayOperator.php b/src/Builder/Expression/IndexOfArrayOperator.php index d364b0a10..34c68db41 100644 --- a/src/Builder/Expression/IndexOfArrayOperator.php +++ b/src/Builder/Expression/IndexOfArrayOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -42,8 +43,8 @@ final class IndexOfArrayOperator implements ResolvesToInt, OperatorInterface */ public readonly PackedArray|ResolvesToArray|BSONArray|array|string $array; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search; /** * @var Optional|ResolvesToInt|int|string $start An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. @@ -61,7 +62,7 @@ final class IndexOfArrayOperator implements ResolvesToInt, OperatorInterface * @param BSONArray|PackedArray|ResolvesToArray|array|string $array Can be any valid expression as long as it resolves to an array. * If the array expression resolves to a value of null or refers to a field that is missing, $indexOfArray returns null. * If the array expression does not resolve to an array or null nor refers to a missing field, $indexOfArray returns an error. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $search * @param Optional|ResolvesToInt|int|string $start An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. * If unspecified, the starting index position for the search is the beginning of the string. * @param Optional|ResolvesToInt|int|string $end An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. @@ -69,7 +70,7 @@ final class IndexOfArrayOperator implements ResolvesToInt, OperatorInterface */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $array, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $search, Optional|ResolvesToInt|int|string $start = Optional::Undefined, Optional|ResolvesToInt|int|string $end = Optional::Undefined, ) { diff --git a/src/Builder/Expression/IsArrayOperator.php b/src/Builder/Expression/IsArrayOperator.php index abd075103..136fc42b4 100644 --- a/src/Builder/Expression/IsArrayOperator.php +++ b/src/Builder/Expression/IsArrayOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,14 +27,15 @@ final class IsArrayOperator implements ResolvesToBool, OperatorInterface public const NAME = '$isArray'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/IsNumberOperator.php b/src/Builder/Expression/IsNumberOperator.php index a76530242..96034de47 100644 --- a/src/Builder/Expression/IsNumberOperator.php +++ b/src/Builder/Expression/IsNumberOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -28,14 +29,15 @@ final class IsNumberOperator implements ResolvesToBool, OperatorInterface public const NAME = '$isNumber'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/IsoDayOfWeekOperator.php b/src/Builder/Expression/IsoDayOfWeekOperator.php index 7ae8e19f1..46261538a 100644 --- a/src/Builder/Expression/IsoDayOfWeekOperator.php +++ b/src/Builder/Expression/IsoDayOfWeekOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class IsoDayOfWeekOperator implements ResolvesToInt, OperatorInterface public const NAME = '$isoDayOfWeek'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/IsoWeekOperator.php b/src/Builder/Expression/IsoWeekOperator.php index 7a500f174..e59d66dc9 100644 --- a/src/Builder/Expression/IsoWeekOperator.php +++ b/src/Builder/Expression/IsoWeekOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class IsoWeekOperator implements ResolvesToInt, OperatorInterface public const NAME = '$isoWeek'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/IsoWeekYearOperator.php b/src/Builder/Expression/IsoWeekYearOperator.php index b558a38c0..2fe1440e4 100644 --- a/src/Builder/Expression/IsoWeekYearOperator.php +++ b/src/Builder/Expression/IsoWeekYearOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class IsoWeekYearOperator implements ResolvesToInt, OperatorInterface public const NAME = '$isoWeekYear'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/LetOperator.php b/src/Builder/Expression/LetOperator.php index 3f0fde195..e3dfdf805 100644 --- a/src/Builder/Expression/LetOperator.php +++ b/src/Builder/Expression/LetOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -35,17 +36,17 @@ final class LetOperator implements ResolvesToAny, OperatorInterface */ public readonly Document|Serializable|stdClass|array $vars; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; /** * @param Document|Serializable|array|stdClass $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ public function __construct( Document|Serializable|stdClass|array $vars, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ) { $this->vars = $vars; $this->in = $in; diff --git a/src/Builder/Expression/LiteralOperator.php b/src/Builder/Expression/LiteralOperator.php index fc80506e4..fe65495d0 100644 --- a/src/Builder/Expression/LiteralOperator.php +++ b/src/Builder/Expression/LiteralOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; @@ -25,13 +26,13 @@ final class LiteralOperator implements ResolvesToAny, OperatorInterface public const NAME = '$literal'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Expression/LtOperator.php b/src/Builder/Expression/LtOperator.php index 7ea54defa..b29d33ef7 100644 --- a/src/Builder/Expression/LtOperator.php +++ b/src/Builder/Expression/LtOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class LtOperator implements ResolvesToBool, OperatorInterface public const NAME = '$lt'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/LteOperator.php b/src/Builder/Expression/LteOperator.php index caeec2165..2bd7ab4fd 100644 --- a/src/Builder/Expression/LteOperator.php +++ b/src/Builder/Expression/LteOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class LteOperator implements ResolvesToBool, OperatorInterface public const NAME = '$lte'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/MapOperator.php b/src/Builder/Expression/MapOperator.php index bafa03ef8..a965e69c6 100644 --- a/src/Builder/Expression/MapOperator.php +++ b/src/Builder/Expression/MapOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -38,20 +39,20 @@ final class MapOperator implements ResolvesToArray, OperatorInterface /** @var BSONArray|PackedArray|ResolvesToArray|array|string $input An expression that resolves to an array. */ public readonly PackedArray|ResolvesToArray|BSONArray|array|string $input; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; /** @var Optional|ResolvesToString|string $as A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. */ public readonly Optional|ResolvesToString|string $as; /** * @param BSONArray|PackedArray|ResolvesToArray|array|string $input An expression that resolves to an array. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. * @param Optional|ResolvesToString|string $as A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, Optional|ResolvesToString|string $as = Optional::Undefined, ) { if (is_string($input) && ! str_starts_with($input, '$')) { diff --git a/src/Builder/Expression/MaxOperator.php b/src/Builder/Expression/MaxOperator.php index 5c1923377..acac1c5d6 100644 --- a/src/Builder/Expression/MaxOperator.php +++ b/src/Builder/Expression/MaxOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -30,15 +31,16 @@ final class MaxOperator implements ResolvesToAny, OperatorInterface public const NAME = '$max'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression */ + /** @var list $expression */ public readonly array $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression * @no-named-arguments */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Expression/MillisecondOperator.php b/src/Builder/Expression/MillisecondOperator.php index c7bc41dfd..91dc5917c 100644 --- a/src/Builder/Expression/MillisecondOperator.php +++ b/src/Builder/Expression/MillisecondOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class MillisecondOperator implements ResolvesToInt, OperatorInterface public const NAME = '$millisecond'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/MinOperator.php b/src/Builder/Expression/MinOperator.php index 31f30e807..28b707d45 100644 --- a/src/Builder/Expression/MinOperator.php +++ b/src/Builder/Expression/MinOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -30,15 +31,16 @@ final class MinOperator implements ResolvesToAny, OperatorInterface public const NAME = '$min'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression */ + /** @var list $expression */ public readonly array $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression * @no-named-arguments */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Expression/MinuteOperator.php b/src/Builder/Expression/MinuteOperator.php index 23b1ad12d..ff86f8857 100644 --- a/src/Builder/Expression/MinuteOperator.php +++ b/src/Builder/Expression/MinuteOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class MinuteOperator implements ResolvesToInt, OperatorInterface public const NAME = '$minute'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/MonthOperator.php b/src/Builder/Expression/MonthOperator.php index e6351e1a8..7fd6e1760 100644 --- a/src/Builder/Expression/MonthOperator.php +++ b/src/Builder/Expression/MonthOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class MonthOperator implements ResolvesToInt, OperatorInterface public const NAME = '$month'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/NeOperator.php b/src/Builder/Expression/NeOperator.php index 1688d7406..b9d60c6e6 100644 --- a/src/Builder/Expression/NeOperator.php +++ b/src/Builder/Expression/NeOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,19 +27,19 @@ final class NeOperator implements ResolvesToBool, OperatorInterface public const NAME = '$ne'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression2 */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Expression/NotOperator.php b/src/Builder/Expression/NotOperator.php index 983fabc80..212898961 100644 --- a/src/Builder/Expression/NotOperator.php +++ b/src/Builder/Expression/NotOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,14 +27,14 @@ final class NotOperator implements ResolvesToBool, OperatorInterface public const NAME = '$not'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression */ public function __construct( - Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ) { $this->expression = $expression; } diff --git a/src/Builder/Expression/OrOperator.php b/src/Builder/Expression/OrOperator.php index 758e73a70..4289c2b7e 100644 --- a/src/Builder/Expression/OrOperator.php +++ b/src/Builder/Expression/OrOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -29,15 +30,15 @@ final class OrOperator implements ResolvesToBool, OperatorInterface public const NAME = '$or'; public const PROPERTIES = ['expression' => 'expression']; - /** @var list $expression */ + /** @var list $expression */ public readonly array $expression; /** - * @param ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string ...$expression + * @param DateTimeInterface|ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string ...$expression * @no-named-arguments */ public function __construct( - Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); diff --git a/src/Builder/Expression/ReduceOperator.php b/src/Builder/Expression/ReduceOperator.php index 27d0d6398..d285a4532 100644 --- a/src/Builder/Expression/ReduceOperator.php +++ b/src/Builder/Expression/ReduceOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -41,31 +42,31 @@ final class ReduceOperator implements ResolvesToAny, OperatorInterface */ public readonly PackedArray|ResolvesToArray|BSONArray|array|string $input; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue; /** - * @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. + * @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. * During evaluation of the in expression, two variables will be available: * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; /** * @param BSONArray|PackedArray|ResolvesToArray|array|string $input Can be any valid expression that resolves to an array. * If the argument resolves to a value of null or refers to a missing field, $reduce returns null. * If the argument does not resolve to an array or null nor refers to a missing field, $reduce returns an error. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. * During evaluation of the in expression, two variables will be available: * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ) { if (is_string($input) && ! str_starts_with($input, '$')) { throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Expression/SecondOperator.php b/src/Builder/Expression/SecondOperator.php index dc65f410e..48ee9ad85 100644 --- a/src/Builder/Expression/SecondOperator.php +++ b/src/Builder/Expression/SecondOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class SecondOperator implements ResolvesToInt, OperatorInterface public const NAME = '$second'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/SetFieldOperator.php b/src/Builder/Expression/SetFieldOperator.php index 96e86ee60..660832772 100644 --- a/src/Builder/Expression/SetFieldOperator.php +++ b/src/Builder/Expression/SetFieldOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -40,21 +41,21 @@ final class SetFieldOperator implements ResolvesToObject, OperatorInterface public readonly Document|Serializable|ResolvesToObject|stdClass|array|string $input; /** - * @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. + * @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. * Set to $$REMOVE to remove field from the input document. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value; + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value; /** * @param ResolvesToString|string $field Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. * @param Document|ResolvesToObject|Serializable|array|stdClass|string $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value The value that you want to assign to field. value can be any valid expression. * Set to $$REMOVE to remove field from the input document. */ public function __construct( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array|string $input, - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, ) { $this->field = $field; if (is_string($input) && ! str_starts_with($input, '$')) { diff --git a/src/Builder/Expression/SubtractOperator.php b/src/Builder/Expression/SubtractOperator.php index 86e396ef0..351f520cb 100644 --- a/src/Builder/Expression/SubtractOperator.php +++ b/src/Builder/Expression/SubtractOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -30,19 +31,19 @@ final class SubtractOperator implements ResolvesToInt, ResolvesToLong, ResolvesT public const NAME = '$subtract'; public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2']; - /** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 */ - public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1; + /** @var DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 */ + public readonly DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1; - /** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 */ - public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2; + /** @var DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 */ + public readonly DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 - * @param Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression1 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int|string $expression2 */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1, - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2, ) { if (is_string($expression1) && ! str_starts_with($expression1, '$')) { throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); diff --git a/src/Builder/Expression/SwitchOperator.php b/src/Builder/Expression/SwitchOperator.php index 4179a5d52..7af40b0f1 100644 --- a/src/Builder/Expression/SwitchOperator.php +++ b/src/Builder/Expression/SwitchOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -42,22 +43,22 @@ final class SwitchOperator implements ResolvesToAny, OperatorInterface public readonly PackedArray|BSONArray|array $branches; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. * Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; /** * @param BSONArray|PackedArray|array $branches An array of control branch documents. Each branch is a document with the following fields: * - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. * - then Can be any valid expression. * The branches array must contain at least one branch document. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. * Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. */ public function __construct( PackedArray|BSONArray|array $branches, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ) { if (is_array($branches) && ! array_is_list($branches)) { throw new InvalidArgumentException('Expected $branches argument to be a list, got an associative array.'); diff --git a/src/Builder/Expression/ToBoolOperator.php b/src/Builder/Expression/ToBoolOperator.php index 15416abc6..6affe2ea5 100644 --- a/src/Builder/Expression/ToBoolOperator.php +++ b/src/Builder/Expression/ToBoolOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToBoolOperator implements ResolvesToBool, OperatorInterface public const NAME = '$toBool'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToDateOperator.php b/src/Builder/Expression/ToDateOperator.php index 10e36c4af..9c5a42b1c 100644 --- a/src/Builder/Expression/ToDateOperator.php +++ b/src/Builder/Expression/ToDateOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToDateOperator implements ResolvesToDate, OperatorInterface public const NAME = '$toDate'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToDecimalOperator.php b/src/Builder/Expression/ToDecimalOperator.php index a10075ef6..b1440e9a0 100644 --- a/src/Builder/Expression/ToDecimalOperator.php +++ b/src/Builder/Expression/ToDecimalOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToDecimalOperator implements ResolvesToDecimal, OperatorInterface public const NAME = '$toDecimal'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToDoubleOperator.php b/src/Builder/Expression/ToDoubleOperator.php index 0b90d8732..8c0d336f5 100644 --- a/src/Builder/Expression/ToDoubleOperator.php +++ b/src/Builder/Expression/ToDoubleOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToDoubleOperator implements ResolvesToDouble, OperatorInterface public const NAME = '$toDouble'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToHashedIndexKeyOperator.php b/src/Builder/Expression/ToHashedIndexKeyOperator.php index c6219e0dd..15f919544 100644 --- a/src/Builder/Expression/ToHashedIndexKeyOperator.php +++ b/src/Builder/Expression/ToHashedIndexKeyOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,14 +27,15 @@ final class ToHashedIndexKeyOperator implements ResolvesToLong, OperatorInterfac public const NAME = '$toHashedIndexKey'; public const PROPERTIES = ['value' => 'value']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, + ) { $this->value = $value; } } diff --git a/src/Builder/Expression/ToIntOperator.php b/src/Builder/Expression/ToIntOperator.php index b4cd77f20..a769d69ad 100644 --- a/src/Builder/Expression/ToIntOperator.php +++ b/src/Builder/Expression/ToIntOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToIntOperator implements ResolvesToInt, OperatorInterface public const NAME = '$toInt'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToLongOperator.php b/src/Builder/Expression/ToLongOperator.php index a386d0c63..7b68c2f55 100644 --- a/src/Builder/Expression/ToLongOperator.php +++ b/src/Builder/Expression/ToLongOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToLongOperator implements ResolvesToLong, OperatorInterface public const NAME = '$toLong'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToObjectIdOperator.php b/src/Builder/Expression/ToObjectIdOperator.php index cdc95d275..bb70f957e 100644 --- a/src/Builder/Expression/ToObjectIdOperator.php +++ b/src/Builder/Expression/ToObjectIdOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToObjectIdOperator implements ResolvesToObjectId, OperatorInterface public const NAME = '$toObjectId'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/ToStringOperator.php b/src/Builder/Expression/ToStringOperator.php index 802112cb6..4d0f59968 100644 --- a/src/Builder/Expression/ToStringOperator.php +++ b/src/Builder/Expression/ToStringOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ToStringOperator implements ResolvesToString, OperatorInterface public const NAME = '$toString'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/TypeOperator.php b/src/Builder/Expression/TypeOperator.php index 34457be7c..78a25aa6e 100644 --- a/src/Builder/Expression/TypeOperator.php +++ b/src/Builder/Expression/TypeOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -26,14 +27,15 @@ final class TypeOperator implements ResolvesToString, OperatorInterface public const NAME = '$type'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Expression/WeekOperator.php b/src/Builder/Expression/WeekOperator.php index 3cca670fa..a895012dc 100644 --- a/src/Builder/Expression/WeekOperator.php +++ b/src/Builder/Expression/WeekOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class WeekOperator implements ResolvesToInt, OperatorInterface public const NAME = '$week'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Expression/YearOperator.php b/src/Builder/Expression/YearOperator.php index 2c1c649bf..314b1de9f 100644 --- a/src/Builder/Expression/YearOperator.php +++ b/src/Builder/Expression/YearOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; @@ -31,18 +32,18 @@ final class YearOperator implements ResolvesToInt, OperatorInterface public const NAME = '$year'; public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone']; - /** @var ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; + /** @var DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public readonly DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date; /** @var Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; /** - * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public function __construct( - ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, + DateTimeInterface|ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { if (is_string($date) && ! str_starts_with($date, '$')) { diff --git a/src/Builder/Query/AllOperator.php b/src/Builder/Query/AllOperator.php index db84daf0a..8c448eef6 100644 --- a/src/Builder/Query/AllOperator.php +++ b/src/Builder/Query/AllOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -29,15 +30,16 @@ final class AllOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$all'; public const PROPERTIES = ['value' => 'value']; - /** @var list $value */ + /** @var list $value */ public readonly array $value; /** - * @param FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string ...$value + * @param DateTimeInterface|FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string ...$value * @no-named-arguments */ - public function __construct(Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string ...$value) - { + public function __construct( + DateTimeInterface|Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string ...$value, + ) { if (\count($value) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $value, got %d.', 1, \count($value))); } diff --git a/src/Builder/Query/ElemMatchOperator.php b/src/Builder/Query/ElemMatchOperator.php index b2195d269..59d59528b 100644 --- a/src/Builder/Query/ElemMatchOperator.php +++ b/src/Builder/Query/ElemMatchOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -30,14 +31,14 @@ final class ElemMatchOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$elemMatch'; public const PROPERTIES = ['query' => 'query']; - /** @var FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query */ - public readonly Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query; + /** @var DateTimeInterface|FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query */ + public readonly DateTimeInterface|Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query; /** - * @param FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query + * @param DateTimeInterface|FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query */ public function __construct( - Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query, + DateTimeInterface|Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query, ) { if (is_array($query)) { $query = QueryObject::create($query); diff --git a/src/Builder/Query/EqOperator.php b/src/Builder/Query/EqOperator.php index 2b38feed8..73eaae719 100644 --- a/src/Builder/Query/EqOperator.php +++ b/src/Builder/Query/EqOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class EqOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$eq'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/ExprOperator.php b/src/Builder/Query/ExprOperator.php index 9e8350a98..15562f046 100644 --- a/src/Builder/Query/ExprOperator.php +++ b/src/Builder/Query/ExprOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class ExprOperator implements QueryInterface, OperatorInterface public const NAME = '$expr'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Query/FactoryTrait.php b/src/Builder/Query/FactoryTrait.php index e9900f935..cedc2adb7 100644 --- a/src/Builder/Query/FactoryTrait.php +++ b/src/Builder/Query/FactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; @@ -36,10 +37,10 @@ trait FactoryTrait * * @see https://www.mongodb.com/docs/manual/reference/operator/query/all/ * @no-named-arguments - * @param FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string ...$value + * @param DateTimeInterface|FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string ...$value */ public static function all( - Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string ...$value, + DateTimeInterface|Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string ...$value, ): AllOperator { return new AllOperator(...$value); } @@ -148,10 +149,10 @@ public static function comment(string $comment): CommentOperator * The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/ - * @param FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query + * @param DateTimeInterface|FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query */ public static function elemMatch( - Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query, + DateTimeInterface|Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query, ): ElemMatchOperator { return new ElemMatchOperator($query); } @@ -160,9 +161,9 @@ public static function elemMatch( * Matches values that are equal to a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/eq/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function eq(Type|stdClass|array|bool|float|int|null|string $value): EqOperator + public static function eq(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): EqOperator { return new EqOperator($value); } @@ -182,10 +183,10 @@ public static function exists(bool $exists = true): ExistsOperator * Allows use of aggregation expressions within the query language. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function expr( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): ExprOperator { return new ExprOperator($expression); } @@ -234,9 +235,9 @@ public static function geoWithin( * Matches values that are greater than a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/gt/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function gt(Type|stdClass|array|bool|float|int|null|string $value): GtOperator + public static function gt(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): GtOperator { return new GtOperator($value); } @@ -245,9 +246,9 @@ public static function gt(Type|stdClass|array|bool|float|int|null|string $value) * Matches values that are greater than or equal to a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/gte/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function gte(Type|stdClass|array|bool|float|int|null|string $value): GteOperator + public static function gte(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): GteOperator { return new GteOperator($value); } @@ -278,9 +279,9 @@ public static function jsonSchema(Document|Serializable|stdClass|array $schema): * Matches values that are less than a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function lt(Type|stdClass|array|bool|float|int|null|string $value): LtOperator + public static function lt(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): LtOperator { return new LtOperator($value); } @@ -289,9 +290,9 @@ public static function lt(Type|stdClass|array|bool|float|int|null|string $value) * Matches values that are less than or equal to a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/lte/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function lte(Type|stdClass|array|bool|float|int|null|string $value): LteOperator + public static function lte(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): LteOperator { return new LteOperator($value); } @@ -336,9 +337,9 @@ public static function mod( * Matches all values that are not equal to a specified value. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/ne/ - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public static function ne(Type|stdClass|array|bool|float|int|null|string $value): NeOperator + public static function ne(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value): NeOperator { return new NeOperator($value); } @@ -402,10 +403,10 @@ public static function nor(QueryInterface|array ...$queries): NorOperator * Inverts the effect of a query expression and returns documents that do not match the query expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/not/ - * @param FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function not( - Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression, ): NotOperator { return new NotOperator($expression); } diff --git a/src/Builder/Query/GtOperator.php b/src/Builder/Query/GtOperator.php index 5f79cd078..235e26c7b 100644 --- a/src/Builder/Query/GtOperator.php +++ b/src/Builder/Query/GtOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class GtOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$gt'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/GteOperator.php b/src/Builder/Query/GteOperator.php index 00606e571..05d8e5961 100644 --- a/src/Builder/Query/GteOperator.php +++ b/src/Builder/Query/GteOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class GteOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$gte'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/LtOperator.php b/src/Builder/Query/LtOperator.php index ac4e88a95..b4c2dd449 100644 --- a/src/Builder/Query/LtOperator.php +++ b/src/Builder/Query/LtOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class LtOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$lt'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/LteOperator.php b/src/Builder/Query/LteOperator.php index 2c8a7cf6f..d0ca1fc9c 100644 --- a/src/Builder/Query/LteOperator.php +++ b/src/Builder/Query/LteOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class LteOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$lte'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/NeOperator.php b/src/Builder/Query/NeOperator.php index 58cdc129c..e5a8cd31d 100644 --- a/src/Builder/Query/NeOperator.php +++ b/src/Builder/Query/NeOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,13 +27,13 @@ final class NeOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$ne'; public const PROPERTIES = ['value' => 'value']; - /** @var Type|array|bool|float|int|null|stdClass|string $value */ - public readonly Type|stdClass|array|bool|float|int|null|string $value; + /** @var DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value; /** - * @param Type|array|bool|float|int|null|stdClass|string $value + * @param DateTimeInterface|Type|array|bool|float|int|null|stdClass|string $value */ - public function __construct(Type|stdClass|array|bool|float|int|null|string $value) + public function __construct(DateTimeInterface|Type|stdClass|array|bool|float|int|null|string $value) { $this->value = $value; } diff --git a/src/Builder/Query/NotOperator.php b/src/Builder/Query/NotOperator.php index f3b422f24..b2ba0894b 100644 --- a/src/Builder/Query/NotOperator.php +++ b/src/Builder/Query/NotOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Query; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\FieldQueryInterface; @@ -26,14 +27,15 @@ final class NotOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$not'; public const PROPERTIES = ['expression' => 'expression']; - /** @var FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Search/EqualsOperator.php b/src/Builder/Search/EqualsOperator.php index bbfe75b8e..092a9ca48 100644 --- a/src/Builder/Search/EqualsOperator.php +++ b/src/Builder/Search/EqualsOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Search; +use DateTimeInterface; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; @@ -36,20 +37,20 @@ final class EqualsOperator implements SearchOperatorInterface, OperatorInterface /** @var array|string $path */ public readonly array|string $path; - /** @var Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value */ - public readonly Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value; + /** @var Binary|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value */ + public readonly DateTimeInterface|Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** * @param array|string $path - * @param Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value + * @param Binary|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value, + DateTimeInterface|Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Search/FactoryTrait.php b/src/Builder/Search/FactoryTrait.php index 3a7762521..c5f3b009c 100644 --- a/src/Builder/Search/FactoryTrait.php +++ b/src/Builder/Search/FactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Search; +use DateTimeInterface; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; @@ -99,12 +100,12 @@ public static function embeddedDocument( * * @see https://www.mongodb.com/docs/atlas/atlas-search/equals/ * @param array|string $path - * @param Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value + * @param Binary|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value * @param Optional|Document|Serializable|array|stdClass $score */ public static function equals( array|string $path, - Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value, + DateTimeInterface|Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): EqualsOperator { return new EqualsOperator($path, $value, $score); @@ -185,12 +186,12 @@ public static function geoWithin( * * @see https://www.mongodb.com/docs/atlas/atlas-search/in/ * @param array|string $path - * @param BSONArray|PackedArray|Type|array|bool|float|int|null|stdClass|string $value + * @param BSONArray|DateTimeInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $value * @param Optional|Document|Serializable|array|stdClass $score */ public static function in( array|string $path, - PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value, + DateTimeInterface|PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): InOperator { return new InOperator($path, $value, $score); @@ -217,13 +218,13 @@ public static function moreLikeThis( * * @see https://www.mongodb.com/docs/atlas/atlas-search/near/ * @param array|string $path - * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin + * @param DateTimeInterface|Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin * @param Decimal128|Int64|float|int $pivot * @param Optional|Document|Serializable|array|stdClass $score */ public static function near( array|string $path, - Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, + DateTimeInterface|Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, Decimal128|Int64|float|int $pivot, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): NearOperator { @@ -266,18 +267,18 @@ public static function queryString(array|string $defaultPath, string $query): Qu * * @see https://www.mongodb.com/docs/atlas/atlas-search/range/ * @param array|string $path - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte * @param Optional|Document|Serializable|array|stdClass $score */ public static function range( array|string $path, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): RangeOperator { return new RangeOperator($path, $gt, $gte, $lt, $lte, $score); diff --git a/src/Builder/Search/InOperator.php b/src/Builder/Search/InOperator.php index f050a1679..b9aaf5875 100644 --- a/src/Builder/Search/InOperator.php +++ b/src/Builder/Search/InOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Search; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; @@ -38,20 +39,20 @@ final class InOperator implements SearchOperatorInterface, OperatorInterface /** @var array|string $path */ public readonly array|string $path; - /** @var BSONArray|PackedArray|Type|array|bool|float|int|null|stdClass|string $value */ - public readonly PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value; + /** @var BSONArray|DateTimeInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $value */ + public readonly DateTimeInterface|PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** * @param array|string $path - * @param BSONArray|PackedArray|Type|array|bool|float|int|null|stdClass|string $value + * @param BSONArray|DateTimeInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $value * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value, + DateTimeInterface|PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Search/NearOperator.php b/src/Builder/Search/NearOperator.php index ab1b9b0c1..b22013ead 100644 --- a/src/Builder/Search/NearOperator.php +++ b/src/Builder/Search/NearOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Search; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; @@ -35,8 +36,8 @@ final class NearOperator implements SearchOperatorInterface, OperatorInterface /** @var array|string $path */ public readonly array|string $path; - /** @var Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin */ - public readonly Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin; + /** @var DateTimeInterface|Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin */ + public readonly DateTimeInterface|Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin; /** @var Decimal128|Int64|float|int $pivot */ public readonly Decimal128|Int64|float|int $pivot; @@ -46,13 +47,13 @@ final class NearOperator implements SearchOperatorInterface, OperatorInterface /** * @param array|string $path - * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin + * @param DateTimeInterface|Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin * @param Decimal128|Int64|float|int $pivot * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, + DateTimeInterface|Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, Decimal128|Int64|float|int $pivot, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { diff --git a/src/Builder/Search/RangeOperator.php b/src/Builder/Search/RangeOperator.php index a728d7477..e277f2b06 100644 --- a/src/Builder/Search/RangeOperator.php +++ b/src/Builder/Search/RangeOperator.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Search; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; @@ -44,35 +45,35 @@ final class RangeOperator implements SearchOperatorInterface, OperatorInterface /** @var array|string $path */ public readonly array|string $path; - /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt */ - public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt; + /** @var Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt */ + public readonly Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt; - /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte */ - public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte; + /** @var Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte */ + public readonly Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte; - /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt */ - public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt; + /** @var Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt */ + public readonly Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt; - /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte */ - public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte; + /** @var Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte */ + public readonly Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** * @param array|string $path - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt - * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt + * @param Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt = Optional::Undefined, - Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt = Optional::Undefined, + Optional|DateTimeInterface|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 2232a0975..2dbbfd972 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -4,6 +4,7 @@ namespace MongoDB\Builder; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Stage\MatchStage; use MongoDB\Builder\Type\FieldQueryInterface; @@ -21,9 +22,9 @@ final class Stage * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ * - * @param QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries The query predicates to match + * @param DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries The query predicates to match */ - public static function match(QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries): MatchStage + public static function match(DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries): MatchStage { // Override the generated method to allow variadic arguments return self::generatedMatch($queries); diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php index 7fedc8b2c..f6385a391 100644 --- a/src/Builder/Stage/AddFieldsStage.php +++ b/src/Builder/Stage/AddFieldsStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -30,14 +31,15 @@ final class AddFieldsStage implements StageInterface, OperatorInterface public const NAME = '$addFields'; public const PROPERTIES = ['expression' => 'expression']; - /** @var stdClass $expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ + /** @var stdClass $expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public readonly stdClass $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index 11c456e69..21975208c 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -36,8 +37,8 @@ final class BucketAutoStage implements StageInterface, OperatorInterface 'granularity' => 'granularity', ]; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; /** @var int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. */ public readonly int $buckets; @@ -55,7 +56,7 @@ final class BucketAutoStage implements StageInterface, OperatorInterface public readonly Optional|string $granularity; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. @@ -63,7 +64,7 @@ final class BucketAutoStage implements StageInterface, OperatorInterface * Available only if the all groupBy values are numeric and none of them are NaN. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 211987c66..334f73dd7 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; @@ -43,10 +44,10 @@ final class BucketStage implements StageInterface, OperatorInterface ]; /** - * @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; /** * @var BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. @@ -55,12 +56,12 @@ final class BucketStage implements StageInterface, OperatorInterface public readonly PackedArray|BSONArray|array $boundaries; /** - * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. + * @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; /** * @var Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. @@ -70,11 +71,11 @@ final class BucketStage implements StageInterface, OperatorInterface public readonly Optional|Document|Serializable|stdClass|array $output; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. @@ -83,9 +84,9 @@ final class BucketStage implements StageInterface, OperatorInterface * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, PackedArray|BSONArray|array $boundaries, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ) { $this->groupBy = $groupBy; diff --git a/src/Builder/Stage/FactoryTrait.php b/src/Builder/Stage/FactoryTrait.php index 7f02da728..df5860ded 100644 --- a/src/Builder/Stage/FactoryTrait.php +++ b/src/Builder/Stage/FactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; @@ -38,10 +39,10 @@ trait FactoryTrait * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public static function addFields( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$expression, ): AddFieldsStage { return new AddFieldsStage(...$expression); } @@ -50,11 +51,11 @@ public static function addFields( * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. @@ -63,9 +64,9 @@ public static function addFields( * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public static function bucket( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, PackedArray|BSONArray|array $boundaries, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ): BucketStage { return new BucketStage($groupBy, $boundaries, $default, $output); @@ -75,7 +76,7 @@ public static function bucket( * Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. @@ -83,7 +84,7 @@ public static function bucket( * Available only if the all groupBy values are numeric and none of them are NaN. */ public static function bucketAuto( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, @@ -284,7 +285,7 @@ public static function geoNear( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ * @param string $from Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. - * @param BSONArray|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. + * @param BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. @@ -294,7 +295,7 @@ public static function geoNear( */ public static function graphLookup( string $from, - PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, + DateTimeInterface|PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, string $connectFromField, string $connectToField, string $as, @@ -309,11 +310,11 @@ public static function graphLookup( * Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. */ public static function group( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id, Document|Serializable|AccumulatorInterface|stdClass|array ...$field, ): GroupStage { return new GroupStage($_id, ...$field); @@ -477,10 +478,10 @@ public static function planCacheStats(): PlanCacheStatsStage * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification */ public static function project( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$specification, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$specification, ): ProjectStage { return new ProjectStage(...$specification); } @@ -489,10 +490,10 @@ public static function project( * Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function redact( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): RedactStage { return new RedactStage($expression); } @@ -592,10 +593,11 @@ public static function searchMeta( * Alias for $addFields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field */ - public static function set(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$field): SetStage - { + public static function set( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$field, + ): SetStage { return new SetStage(...$field); } @@ -607,12 +609,12 @@ public static function set(Type|ExpressionInterface|stdClass|array|bool|float|in * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public static function setWindowFields( Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, ): SetWindowFieldsStage { return new SetWindowFieldsStage($sortBy, $output, $partitionBy); } @@ -643,10 +645,10 @@ public static function skip(int $skip): SkipStage * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ - * @param ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort + * @param DateTimeInterface|ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort */ public static function sort( - Type|ExpressionInterface|Sort|stdClass|array|bool|float|int|null|string ...$sort, + DateTimeInterface|Type|ExpressionInterface|Sort|stdClass|array|bool|float|int|null|string ...$sort, ): SortStage { return new SortStage(...$sort); } @@ -655,10 +657,10 @@ public static function sort( * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public static function sortByCount( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, ): SortByCountStage { return new SortByCountStage($expression); } diff --git a/src/Builder/Stage/FluentFactoryTrait.php b/src/Builder/Stage/FluentFactoryTrait.php index 3746e9bcc..1b9e542ac 100644 --- a/src/Builder/Stage/FluentFactoryTrait.php +++ b/src/Builder/Stage/FluentFactoryTrait.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; @@ -47,10 +48,10 @@ public function getPipeline(): Pipeline * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ * - * @param QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries The query predicates to match + * @param DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array|bool|float|int|string|null ...$queries The query predicates to match */ public function match( - QueryInterface|FieldQueryInterface|Type|stdClass|array|string|int|float|bool|null ...$queries, + DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array|string|int|float|bool|null ...$queries, ): static { $this->pipeline[] = Stage::match(...$queries); @@ -61,10 +62,10 @@ public function match( * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public function addFields( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$expression, ): static { $this->pipeline[] = Stage::addFields(...$expression); @@ -75,11 +76,11 @@ public function addFields( * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. @@ -88,9 +89,9 @@ public function addFields( * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public function bucket( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, PackedArray|BSONArray|array $boundaries, - Optional|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $default = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $default = Optional::Undefined, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ): static { $this->pipeline[] = Stage::bucket($groupBy, $boundaries, $default, $output); @@ -102,7 +103,7 @@ public function bucket( * Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. @@ -110,7 +111,7 @@ public function bucket( * Available only if the all groupBy values are numeric and none of them are NaN. */ public function bucketAuto( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, @@ -333,7 +334,7 @@ public function geoNear( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ * @param string $from Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. - * @param BSONArray|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. + * @param BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. @@ -343,7 +344,7 @@ public function geoNear( */ public function graphLookup( string $from, - PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|string|int|float|bool|null $startWith, + DateTimeInterface|PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|string|int|float|bool|null $startWith, string $connectFromField, string $connectToField, string $as, @@ -360,11 +361,11 @@ public function graphLookup( * Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. */ public function group( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $_id, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $_id, Document|Serializable|AccumulatorInterface|stdClass|array ...$field, ): static { $this->pipeline[] = Stage::group($_id, ...$field); @@ -538,10 +539,10 @@ public function planCacheStats(): static * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification */ public function project( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$specification, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$specification, ): static { $this->pipeline[] = Stage::project(...$specification); @@ -552,10 +553,11 @@ public function project( * Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function redact(Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $expression): static - { + public function redact( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $expression, + ): static { $this->pipeline[] = Stage::redact($expression); return $this; @@ -664,10 +666,11 @@ public function searchMeta( * Alias for $addFields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field */ - public function set(Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$field): static - { + public function set( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null ...$field, + ): static { $this->pipeline[] = Stage::set(...$field); return $this; @@ -681,12 +684,12 @@ public function set(Type|ExpressionInterface|stdClass|array|string|int|float|boo * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public function setWindowFields( Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Optional|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $partitionBy = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $partitionBy = Optional::Undefined, ): static { $this->pipeline[] = Stage::setWindowFields($sortBy, $output, $partitionBy); @@ -723,10 +726,11 @@ public function skip(int $skip): static * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ - * @param ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort + * @param DateTimeInterface|ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort */ - public function sort(Type|ExpressionInterface|Sort|stdClass|array|string|int|float|bool|null ...$sort): static - { + public function sort( + DateTimeInterface|Type|ExpressionInterface|Sort|stdClass|array|string|int|float|bool|null ...$sort, + ): static { $this->pipeline[] = Stage::sort(...$sort); return $this; @@ -736,10 +740,10 @@ public function sort(Type|ExpressionInterface|Sort|stdClass|array|string|int|flo * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ public function sortByCount( - Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $expression, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $expression, ): static { $this->pipeline[] = Stage::sortByCount($expression); diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index 936b59861..d15b51bdf 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; @@ -52,8 +53,8 @@ final class GraphLookupStage implements StageInterface, OperatorInterface */ public readonly string $from; - /** @var BSONArray|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. */ - public readonly PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith; + /** @var BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. */ + public readonly DateTimeInterface|PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith; /** @var string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. */ public readonly string $connectFromField; @@ -76,7 +77,7 @@ final class GraphLookupStage implements StageInterface, OperatorInterface /** * @param string $from Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. - * @param BSONArray|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. + * @param BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array|bool|float|int|null|stdClass|string $startWith Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. @@ -86,7 +87,7 @@ final class GraphLookupStage implements StageInterface, OperatorInterface */ public function __construct( string $from, - PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, + DateTimeInterface|PackedArray|Type|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, string $connectFromField, string $connectToField, string $as, diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index b44cbc764..8577b4ad1 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -33,18 +34,18 @@ final class GroupStage implements StageInterface, OperatorInterface public const NAME = '$group'; public const PROPERTIES = ['_id' => '_id', 'field' => null]; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id; /** @var stdClass $field Computed using the accumulator operators. */ public readonly stdClass $field; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_id The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. */ public function __construct( - Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id, + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id, Document|Serializable|AccumulatorInterface|stdClass|array ...$field, ) { $this->_id = $_id; diff --git a/src/Builder/Stage/ProjectStage.php b/src/Builder/Stage/ProjectStage.php index 4b1c0f350..e2f6c4977 100644 --- a/src/Builder/Stage/ProjectStage.php +++ b/src/Builder/Stage/ProjectStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -30,14 +31,15 @@ final class ProjectStage implements StageInterface, OperatorInterface public const NAME = '$project'; public const PROPERTIES = ['specification' => 'specification']; - /** @var stdClass $specification */ + /** @var stdClass $specification */ public readonly stdClass $specification; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$specification) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$specification, + ) { if (\count($specification) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); } diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php index a1db25265..0da03aba5 100644 --- a/src/Builder/Stage/RedactStage.php +++ b/src/Builder/Stage/RedactStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class RedactStage implements StageInterface, OperatorInterface public const NAME = '$redact'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php index 45c545474..a9c2a53ec 100644 --- a/src/Builder/Stage/SetStage.php +++ b/src/Builder/Stage/SetStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -31,14 +32,15 @@ final class SetStage implements StageInterface, OperatorInterface public const NAME = '$set'; public const PROPERTIES = ['field' => 'field']; - /** @var stdClass $field */ + /** @var stdClass $field */ public readonly stdClass $field; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$field */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$field) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$field, + ) { if (\count($field) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); } diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index ba8d63edf..7d45bc5aa 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; @@ -40,19 +41,19 @@ final class SetWindowFieldsStage implements StageInterface, OperatorInterface */ public readonly Document|Serializable|stdClass|array $output; - /** @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ - public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy; + /** @var Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ + public readonly Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy; /** * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. - * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. + * @param Optional|DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public function __construct( Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, + Optional|DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, ) { $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php index 5e8f8821a..e616470b9 100644 --- a/src/Builder/Stage/SortByCountStage.php +++ b/src/Builder/Stage/SortByCountStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -27,14 +28,15 @@ final class SortByCountStage implements StageInterface, OperatorInterface public const NAME = '$sortByCount'; public const PROPERTIES = ['expression' => 'expression']; - /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; + /** @var DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ + public readonly DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression + * @param DateTimeInterface|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */ - public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php index f913d2897..fc8899a4c 100644 --- a/src/Builder/Stage/SortStage.php +++ b/src/Builder/Stage/SortStage.php @@ -8,6 +8,7 @@ namespace MongoDB\Builder\Stage; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; @@ -31,14 +32,15 @@ final class SortStage implements StageInterface, OperatorInterface public const NAME = '$sort'; public const PROPERTIES = ['sort' => 'sort']; - /** @var stdClass $sort */ + /** @var stdClass $sort */ public readonly stdClass $sort; /** - * @param ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort + * @param DateTimeInterface|ExpressionInterface|Sort|Type|array|bool|float|int|null|stdClass|string ...$sort */ - public function __construct(Type|ExpressionInterface|Sort|stdClass|array|bool|float|int|null|string ...$sort) - { + public function __construct( + DateTimeInterface|Type|ExpressionInterface|Sort|stdClass|array|bool|float|int|null|string ...$sort, + ) { if (\count($sort) < 1) { throw new InvalidArgumentException(\sprintf('Expected at least %d values for $sort, got %d.', 1, \count($sort))); } diff --git a/src/Builder/Type/QueryObject.php b/src/Builder/Type/QueryObject.php index d2298837a..af27069d4 100644 --- a/src/Builder/Type/QueryObject.php +++ b/src/Builder/Type/QueryObject.php @@ -4,6 +4,7 @@ namespace MongoDB\Builder\Type; +use DateTimeInterface; use MongoDB\BSON\Type; use MongoDB\Exception\InvalidArgumentException; use stdClass; @@ -25,7 +26,7 @@ final class QueryObject implements QueryInterface { public readonly array $queries; - /** @param array $queries */ + /** @param array $queries */ public static function create(array $queries): QueryInterface { // We don't wrap a single query in a QueryObject @@ -36,7 +37,7 @@ public static function create(array $queries): QueryInterface return new self($queries); } - /** @param array $queriesOrArrayOfQueries */ + /** @param array $queriesOrArrayOfQueries */ private function __construct(array $queriesOrArrayOfQueries) { // If the first element is an array and not an operator, we assume variadic arguments were not used diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 4e9cd76f2..893803a94 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -4,8 +4,11 @@ namespace MongoDB\Tests\Builder; +use DateTime; +use DateTimeImmutable; use Generator; use MongoDB\BSON\Document; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Accumulator; use MongoDB\Builder\BuilderEncoder; use MongoDB\Builder\Expression; @@ -337,6 +340,45 @@ public function testRedactStage(): void $this->assertSamePipeline($expected, $pipeline); } + public function testDateTimeEncoding(): void + { + $dateTimeImmutable = new DateTimeImmutable(); + $dateTime = DateTime::createFromImmutable($dateTimeImmutable); + $utcDateTime = new UTCDateTime($dateTime); + + $pipeline = new Pipeline( + Stage::match( + utc: $utcDateTime, + mutable: $dateTime, + immutable: $dateTimeImmutable, + ), + Stage::addFields( + utc: Expression::dateToString($utcDateTime), + mutable: Expression::dateToString($dateTime), + immutable: Expression::dateToString($dateTimeImmutable), + ), + ); + + $expected = [ + [ + '$match' => [ + 'utc' => $utcDateTime, + 'mutable' => $utcDateTime, + 'immutable' => $utcDateTime, + ], + ], + [ + '$addFields' => [ + 'utc' => ['$dateToString' => ['date' => $utcDateTime]], + 'mutable' => ['$dateToString' => ['date' => $utcDateTime]], + 'immutable' => ['$dateToString' => ['date' => $utcDateTime]], + ], + ], + ]; + + $this->assertSamePipeline($expected, $pipeline); + } + /** @param list> $expected */ private static function assertSamePipeline(array $expected, Pipeline $pipeline): void { From 36fca42852d3b8599920915abbe42dcec593ad05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 26 Feb 2025 11:28:14 +0100 Subject: [PATCH 3/5] PHPLIB-1635 BuilderEncoder accepts an instance of encoder instead of a class string (#1608) BuilderEncoder accepts an instance of encoder instead of a class string Remove AbstractExpressionEncoder and ExpressionEncoder interface --- psalm-baseline.xml | 17 ++++--- src/Builder/BuilderEncoder.php | 25 ++++++---- .../Encoder/CombinedFieldQueryEncoder.php | 6 ++- src/Builder/Encoder/DateTimeEncoder.php | 5 +- src/Builder/Encoder/DictionaryEncoder.php | 5 +- src/Builder/Encoder/ExpressionEncoder.php | 21 --------- src/Builder/Encoder/FieldPathEncoder.php | 5 +- src/Builder/Encoder/OperatorEncoder.php | 6 ++- src/Builder/Encoder/OutputWindowEncoder.php | 6 ++- src/Builder/Encoder/PipelineEncoder.php | 8 ++-- src/Builder/Encoder/QueryEncoder.php | 6 ++- ...ressionEncoder.php => RecursiveEncode.php} | 11 +---- src/Builder/Encoder/VariableEncoder.php | 5 +- tests/Builder/BuilderEncoderTest.php | 47 ++++++++++++++++++- 14 files changed, 108 insertions(+), 65 deletions(-) delete mode 100644 src/Builder/Encoder/ExpressionEncoder.php rename src/Builder/Encoder/{AbstractExpressionEncoder.php => RecursiveEncode.php} (75%) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fb84ad5ca..a02fc0fc8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -41,12 +41,10 @@ - - - - - - + + + encode($value)]]> + @@ -99,6 +97,13 @@ + + + + + + + diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index a630d4f0d..695d3fb14 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -9,7 +9,6 @@ use MongoDB\Builder\Encoder\CombinedFieldQueryEncoder; use MongoDB\Builder\Encoder\DateTimeEncoder; use MongoDB\Builder\Encoder\DictionaryEncoder; -use MongoDB\Builder\Encoder\ExpressionEncoder; use MongoDB\Builder\Encoder\FieldPathEncoder; use MongoDB\Builder\Encoder\OperatorEncoder; use MongoDB\Builder\Encoder\OutputWindowEncoder; @@ -33,6 +32,7 @@ use function array_key_exists; use function is_object; +use function is_string; /** @template-implements Encoder */ final class BuilderEncoder implements Encoder @@ -40,7 +40,7 @@ final class BuilderEncoder implements Encoder /** @template-use EncodeIfSupported */ use EncodeIfSupported; - /** @var array> */ + /** @var array> */ private array $defaultEncoders = [ Pipeline::class => PipelineEncoder::class, Variable::class => VariableEncoder::class, @@ -53,10 +53,10 @@ final class BuilderEncoder implements Encoder DateTimeInterface::class => DateTimeEncoder::class, ]; - /** @var array */ + /** @var array */ private array $cachedEncoders = []; - /** @param array> $customEncoders */ + /** @param array $customEncoders */ public function __construct(private readonly array $customEncoders = []) { } @@ -82,7 +82,7 @@ public function encode(mixed $value): Type|stdClass|array|string|int return $encoder->encode($value); } - private function getEncoderFor(object $value): ExpressionEncoder|null + private function getEncoderFor(object $value): Encoder|null { $valueClass = $value::class; if (array_key_exists($valueClass, $this->cachedEncoders)) { @@ -93,13 +93,22 @@ private function getEncoderFor(object $value): ExpressionEncoder|null // First attempt: match class name exactly if (isset($encoderList[$valueClass])) { - return $this->cachedEncoders[$valueClass] = new $encoderList[$valueClass]($this); + $encoder = $encoderList[$valueClass]; + if (is_string($encoder)) { + $encoder = new $encoder($this); + } + + return $this->cachedEncoders[$valueClass] = $encoder; } // Second attempt: catch child classes - foreach ($encoderList as $className => $encoderClass) { + foreach ($encoderList as $className => $encoder) { if ($value instanceof $className) { - return $this->cachedEncoders[$valueClass] = new $encoderClass($this); + if (is_string($encoder)) { + $encoder = new $encoder($this); + } + + return $this->cachedEncoders[$valueClass] = $encoder; } } diff --git a/src/Builder/Encoder/CombinedFieldQueryEncoder.php b/src/Builder/Encoder/CombinedFieldQueryEncoder.php index b933953be..118757901 100644 --- a/src/Builder/Encoder/CombinedFieldQueryEncoder.php +++ b/src/Builder/Encoder/CombinedFieldQueryEncoder.php @@ -7,6 +7,7 @@ use LogicException; use MongoDB\Builder\Type\CombinedFieldQuery; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; @@ -17,13 +18,14 @@ use function sprintf; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class CombinedFieldQueryEncoder extends AbstractExpressionEncoder +final class CombinedFieldQueryEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; + use RecursiveEncode; public function canEncode(mixed $value): bool { diff --git a/src/Builder/Encoder/DateTimeEncoder.php b/src/Builder/Encoder/DateTimeEncoder.php index c4b98f2c4..6926bd813 100644 --- a/src/Builder/Encoder/DateTimeEncoder.php +++ b/src/Builder/Encoder/DateTimeEncoder.php @@ -7,13 +7,14 @@ use DateTimeInterface; use MongoDB\BSON\UTCDateTime; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class DateTimeEncoder extends AbstractExpressionEncoder +final class DateTimeEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; diff --git a/src/Builder/Encoder/DictionaryEncoder.php b/src/Builder/Encoder/DictionaryEncoder.php index f228fa2d7..dc89cff11 100644 --- a/src/Builder/Encoder/DictionaryEncoder.php +++ b/src/Builder/Encoder/DictionaryEncoder.php @@ -6,14 +6,15 @@ use MongoDB\Builder\Type\DictionaryInterface; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class DictionaryEncoder extends AbstractExpressionEncoder +final class DictionaryEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; diff --git a/src/Builder/Encoder/ExpressionEncoder.php b/src/Builder/Encoder/ExpressionEncoder.php deleted file mode 100644 index f50da33d3..000000000 --- a/src/Builder/Encoder/ExpressionEncoder.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @internal - */ -interface ExpressionEncoder extends Encoder -{ - public function __construct(BuilderEncoder $encoder); -} diff --git a/src/Builder/Encoder/FieldPathEncoder.php b/src/Builder/Encoder/FieldPathEncoder.php index 4dc7b6f2c..3766f9a0e 100644 --- a/src/Builder/Encoder/FieldPathEncoder.php +++ b/src/Builder/Encoder/FieldPathEncoder.php @@ -6,13 +6,14 @@ use MongoDB\Builder\Type\FieldPathInterface; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class FieldPathEncoder extends AbstractExpressionEncoder +final class FieldPathEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; diff --git a/src/Builder/Encoder/OperatorEncoder.php b/src/Builder/Encoder/OperatorEncoder.php index 5c18d7c0b..8f81edfa2 100644 --- a/src/Builder/Encoder/OperatorEncoder.php +++ b/src/Builder/Encoder/OperatorEncoder.php @@ -9,6 +9,7 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; @@ -17,13 +18,14 @@ use function sprintf; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class OperatorEncoder extends AbstractExpressionEncoder +final class OperatorEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; + use RecursiveEncode; public function canEncode(mixed $value): bool { diff --git a/src/Builder/Encoder/OutputWindowEncoder.php b/src/Builder/Encoder/OutputWindowEncoder.php index 830c2cacb..4e435a987 100644 --- a/src/Builder/Encoder/OutputWindowEncoder.php +++ b/src/Builder/Encoder/OutputWindowEncoder.php @@ -9,6 +9,7 @@ use MongoDB\Builder\Type\OutputWindow; use MongoDB\Builder\Type\WindowInterface; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; @@ -18,13 +19,14 @@ use function sprintf; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class OutputWindowEncoder extends AbstractExpressionEncoder +final class OutputWindowEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; + use RecursiveEncode; public function canEncode(mixed $value): bool { diff --git a/src/Builder/Encoder/PipelineEncoder.php b/src/Builder/Encoder/PipelineEncoder.php index 5a343e0fb..c4c0829ce 100644 --- a/src/Builder/Encoder/PipelineEncoder.php +++ b/src/Builder/Encoder/PipelineEncoder.php @@ -6,16 +6,18 @@ use MongoDB\Builder\Pipeline; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; /** - * @template-extends AbstractExpressionEncoder, Pipeline> + * @template-implements Encoder, Pipeline> * @internal */ -final class PipelineEncoder extends AbstractExpressionEncoder +final class PipelineEncoder implements Encoder { /** @template-use EncodeIfSupported, Pipeline> */ use EncodeIfSupported; + use RecursiveEncode; /** @psalm-assert-if-true Pipeline $value */ public function canEncode(mixed $value): bool @@ -32,7 +34,7 @@ public function encode(mixed $value): array $encoded = []; foreach ($value->getIterator() as $stage) { - $encoded[] = $this->encoder->encodeIfSupported($stage); + $encoded[] = $this->recursiveEncode($stage); } return $encoded; diff --git a/src/Builder/Encoder/QueryEncoder.php b/src/Builder/Encoder/QueryEncoder.php index 2193edb02..6a43f37c0 100644 --- a/src/Builder/Encoder/QueryEncoder.php +++ b/src/Builder/Encoder/QueryEncoder.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Type\QueryInterface; use MongoDB\Builder\Type\QueryObject; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; @@ -16,13 +17,14 @@ use function sprintf; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class QueryEncoder extends AbstractExpressionEncoder +final class QueryEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; + use RecursiveEncode; public function canEncode(mixed $value): bool { diff --git a/src/Builder/Encoder/AbstractExpressionEncoder.php b/src/Builder/Encoder/RecursiveEncode.php similarity index 75% rename from src/Builder/Encoder/AbstractExpressionEncoder.php rename to src/Builder/Encoder/RecursiveEncode.php index 7a0f437b2..d93fdd998 100644 --- a/src/Builder/Encoder/AbstractExpressionEncoder.php +++ b/src/Builder/Encoder/RecursiveEncode.php @@ -4,20 +4,13 @@ namespace MongoDB\Builder\Encoder; -use MongoDB\BSON\Type; use MongoDB\Builder\BuilderEncoder; use stdClass; use function get_object_vars; use function is_array; -/** - * @template BSONType of Type|stdClass|array|string|int - * @template NativeType - * @template-implements ExpressionEncoder - * @internal - */ -abstract class AbstractExpressionEncoder implements ExpressionEncoder +trait RecursiveEncode { final public function __construct(protected readonly BuilderEncoder $encoder) { @@ -33,7 +26,7 @@ final public function __construct(protected readonly BuilderEncoder $encoder) * * @template T */ - final protected function recursiveEncode(mixed $value): mixed + private function recursiveEncode(mixed $value): mixed { if (is_array($value)) { foreach ($value as $key => $val) { diff --git a/src/Builder/Encoder/VariableEncoder.php b/src/Builder/Encoder/VariableEncoder.php index 31f73b6d8..051977976 100644 --- a/src/Builder/Encoder/VariableEncoder.php +++ b/src/Builder/Encoder/VariableEncoder.php @@ -6,13 +6,14 @@ use MongoDB\Builder\Expression\Variable; use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; /** - * @template-extends AbstractExpressionEncoder + * @template-implements Encoder * @internal */ -final class VariableEncoder extends AbstractExpressionEncoder +final class VariableEncoder implements Encoder { /** @template-use EncodeIfSupported */ use EncodeIfSupported; diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 893803a94..719ab9f7e 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -15,8 +15,11 @@ use MongoDB\Builder\Pipeline; use MongoDB\Builder\Query; use MongoDB\Builder\Stage; +use MongoDB\Builder\Type\FieldPathInterface; use MongoDB\Builder\Type\Sort; use MongoDB\Builder\Variable; +use MongoDB\Codec\EncodeIfSupported; +use MongoDB\Codec\Encoder; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -379,10 +382,50 @@ public function testDateTimeEncoding(): void $this->assertSamePipeline($expected, $pipeline); } + public function testCustomEncoder(): void + { + $customEncoders = [ + FieldPathInterface::class => new class implements Encoder { + use EncodeIfSupported; + + public function canEncode(mixed $value): bool + { + return $value instanceof FieldPathInterface; + } + + public function encode(mixed $value) + { + return '$prefix.' . $value->name; + } + }, + ]; + $codec = new BuilderEncoder($customEncoders); + + $pipeline = new Pipeline( + Stage::project( + threeFavorites: Expression::slice( + Expression::arrayFieldPath('items'), + n: 3, + ), + ), + ); + + $expected = [ + [ + '$project' => [ + 'threeFavorites' => [ + '$slice' => ['$prefix.items', 3], + ], + ], + ], + ]; + + $this->assertSamePipeline($expected, $pipeline, $codec); + } + /** @param list> $expected */ - private static function assertSamePipeline(array $expected, Pipeline $pipeline): void + private static function assertSamePipeline(array $expected, Pipeline $pipeline, $codec = new BuilderEncoder()): void { - $codec = new BuilderEncoder(); $actual = $codec->encode($pipeline); // Normalize with BSON round-trip From 481cffa093d00799a4aefc192013eb8773ce5a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 26 Feb 2025 15:48:15 +0100 Subject: [PATCH 4/5] Pre-init all sub-encoders of the builder encoder (#1613) Use weak reference to prevent circular reference Avoid having the same encoder initialized multiple times --- src/Builder/BuilderEncoder.php | 50 +++++++++++-------------- src/Builder/Encoder/QueryEncoder.php | 2 +- src/Builder/Encoder/RecursiveEncode.php | 16 ++++++-- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 695d3fb14..833409b07 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -29,10 +29,10 @@ use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; +use WeakReference; use function array_key_exists; use function is_object; -use function is_string; /** @template-implements Encoder */ final class BuilderEncoder implements Encoder @@ -40,25 +40,28 @@ final class BuilderEncoder implements Encoder /** @template-use EncodeIfSupported */ use EncodeIfSupported; - /** @var array> */ - private array $defaultEncoders = [ - Pipeline::class => PipelineEncoder::class, - Variable::class => VariableEncoder::class, - DictionaryInterface::class => DictionaryEncoder::class, - FieldPathInterface::class => FieldPathEncoder::class, - CombinedFieldQuery::class => CombinedFieldQueryEncoder::class, - QueryObject::class => QueryEncoder::class, - OutputWindow::class => OutputWindowEncoder::class, - OperatorInterface::class => OperatorEncoder::class, - DateTimeInterface::class => DateTimeEncoder::class, - ]; + /** @var array */ + private array $encoders; /** @var array */ private array $cachedEncoders = []; - /** @param array $customEncoders */ - public function __construct(private readonly array $customEncoders = []) + /** @param array $encoders */ + public function __construct(array $encoders = []) { + $self = WeakReference::create($this); + + $this->encoders = $encoders + [ + Pipeline::class => new PipelineEncoder($self), + Variable::class => new VariableEncoder(), + DictionaryInterface::class => new DictionaryEncoder(), + FieldPathInterface::class => new FieldPathEncoder(), + CombinedFieldQuery::class => new CombinedFieldQueryEncoder($self), + QueryObject::class => new QueryEncoder($self), + OutputWindow::class => new OutputWindowEncoder($self), + OperatorInterface::class => new OperatorEncoder($self), + DateTimeInterface::class => new DateTimeEncoder(), + ]; } /** @psalm-assert-if-true object $value */ @@ -89,25 +92,14 @@ private function getEncoderFor(object $value): Encoder|null return $this->cachedEncoders[$valueClass]; } - $encoderList = $this->customEncoders + $this->defaultEncoders; - // First attempt: match class name exactly - if (isset($encoderList[$valueClass])) { - $encoder = $encoderList[$valueClass]; - if (is_string($encoder)) { - $encoder = new $encoder($this); - } - - return $this->cachedEncoders[$valueClass] = $encoder; + if (isset($this->encoders[$valueClass])) { + return $this->cachedEncoders[$valueClass] = $this->encoders[$valueClass]; } // Second attempt: catch child classes - foreach ($encoderList as $className => $encoder) { + foreach ($this->encoders as $className => $encoder) { if ($value instanceof $className) { - if (is_string($encoder)) { - $encoder = new $encoder($this); - } - return $this->cachedEncoders[$valueClass] = $encoder; } } diff --git a/src/Builder/Encoder/QueryEncoder.php b/src/Builder/Encoder/QueryEncoder.php index 6a43f37c0..19f21897c 100644 --- a/src/Builder/Encoder/QueryEncoder.php +++ b/src/Builder/Encoder/QueryEncoder.php @@ -53,7 +53,7 @@ public function encode(mixed $value): stdClass throw new LogicException(sprintf('Duplicate key "%s" in query object', $key)); } - $result->{$key} = $this->encoder->encodeIfSupported($value); + $result->{$key} = $this->recursiveEncode($value); } } diff --git a/src/Builder/Encoder/RecursiveEncode.php b/src/Builder/Encoder/RecursiveEncode.php index d93fdd998..e83af8a22 100644 --- a/src/Builder/Encoder/RecursiveEncode.php +++ b/src/Builder/Encoder/RecursiveEncode.php @@ -4,15 +4,18 @@ namespace MongoDB\Builder\Encoder; -use MongoDB\Builder\BuilderEncoder; +use MongoDB\Codec\Encoder; use stdClass; +use WeakReference; use function get_object_vars; use function is_array; +/** @internal */ trait RecursiveEncode { - final public function __construct(protected readonly BuilderEncoder $encoder) + /** @param WeakReference $encoder */ + final public function __construct(private readonly WeakReference $encoder) { } @@ -44,6 +47,13 @@ private function recursiveEncode(mixed $value): mixed return $value; } - return $this->encoder->encodeIfSupported($value); + /** + * If the BuilderEncoder instance is removed from the memory, the + * instances of the classes using this trait will be removed as well. + * Therefore, the weak reference will never return null. + * + * @psalm-suppress PossiblyNullReference + */ + return $this->encoder->get()->encodeIfSupported($value); } } From ad5b49a6dd0d5b9109e00c4d57d2601a52c9102d Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 27 Feb 2025 09:24:48 -0500 Subject: [PATCH 5/5] Add return type hint for Encoder::encode() implementation This was not applicable to the commit in v1.x (36fca42852d3b8599920915abbe42dcec593ad05), but is necessary in v2.x since 5dda098ee48c2be5d485968ff6fda2a6f74df15e added return types to all methods. --- tests/Builder/BuilderEncoderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 719ab9f7e..5d80184c7 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -393,7 +393,7 @@ public function canEncode(mixed $value): bool return $value instanceof FieldPathInterface; } - public function encode(mixed $value) + public function encode(mixed $value): mixed { return '$prefix.' . $value->name; }