objectId = $id; } elseif (is_string($id)) { $this->objectId = new MongoObjectId($id); } else { $this->objectId = new MongoObjectId(); } } /** * Get the string representation of the ObjectId */ public function __toString(): string { return (string) $this->objectId; } /** * Get the underlying MongoDB ObjectId * Used internally when interacting with MongoDB driver */ public function toBSON(): MongoObjectId { return $this->objectId; } /** * Get the timestamp from the ObjectId */ public function getTimestamp(): int { return $this->objectId->getTimestamp(); } /** * Create ObjectId from string */ public static function fromString(string $id): self { return new self($id); } /** * Check if a string is a valid ObjectId */ public static function isValid(string $id): bool { return MongoObjectId::isValid($id); } }