-
-
Notifications
You must be signed in to change notification settings - Fork 514
Add Type::getBSONType()
#2786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.12.x
Are you sure you want to change the base?
Add Type::getBSONType()
#2786
Conversation
/** | ||
* Returns the alias name of the BSON type. | ||
* | ||
* @link https://www.mongodb.com/docs/manual/reference/bson-types/ | ||
*/ | ||
public function getBSONType(): BsonType | ||
{ | ||
// This method will be abstract in the next major version. | ||
throw new BadMethodCallException(sprintf('The method "%s::getBSONType" is not implemented. You must implement this method in the concrete type class.', static::class)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot make this method abstract in a minor version, that would be a breaking change for custom type classes that extend this class.
/** | ||
* Raw data type. | ||
*/ | ||
class RawType extends Type | ||
{ | ||
public function getBSONType(): BsonType | ||
{ | ||
throw new LogicException(sprintf('Cannot determine BSON type for "%s".', self::class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field type can be anything.
/** | ||
* The Key type. | ||
*/ | ||
class KeyType extends Type | ||
{ | ||
public function getBSONType(): BsonType | ||
{ | ||
throw new LogicException(sprintf('Cannot determine BSON type for "%s".', self::class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field type can be maxKey
or minKey
.
@@ -11,6 +11,11 @@ | |||
*/ | |||
class IntType extends Type implements Incrementable, Versionable | |||
{ | |||
public function getBSONType(): BsonType | |||
{ | |||
return BsonType::Int32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the system and the value, I think the type can be an int 32 bits or 64 bits.
/** | ||
* The Id type. | ||
*/ | ||
class CustomIdType extends Type | ||
{ | ||
public function getBSONType(): BsonType | ||
{ | ||
throw new LogicException(sprintf('Cannot determine BSON type for "%s".', self::class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field type can be anything.
Summary
While working on
encryptedFieldsMap
(#2785 (comment)), we found that it would be useful if every ODM Type could indicate its BSON type.It's possible to assign 1 BSON type for most of the ODM types, but there are some exception with some ODM types that can return multiple BSON types (see comments).