Skip to content

Support using Enum and UnitEnum implementations in BSON - #71

Merged
thekid merged 1 commit into
masterfrom
feature/enum-handling
Aug 29, 2026
Merged

thekid merged 1 commit into
masterfrom
feature/enum-handling

Conversation

@thekid

@thekid thekid commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

This pull request makes XP enums and PHP enums usable in the MongoDB API. Both are stored as strings using their names.

Example:

use com\mongodb\{MongoConnection, Document};
use util\Currency;

enum Coin : int {
  case Penny = 1;
  case Nickel = 5;
  case Dime = 10;
  case Quarter = 25;
}

// We can now directly use it in queries, criteria, pipelines etc.
$conn= new MongoConnection('...');
$assessment= $conn->collection('inventory.users')->insert(new Document([
  'owner'    => $user,
  'coin'     => Coin::Penny, 
  'currency' => Currency::$USD,
]));

This is consistent with marshalling in this library.

@thekid thekid added the enhancement New feature or request label Aug 29, 2026
@thekid
thekid merged commit 0712b49 into master Aug 29, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant