-
-
Notifications
You must be signed in to change notification settings - Fork 513
[Encryption] Add Int64 type #2805
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Types; | ||
|
||
use MongoDB\BSON\Int64; | ||
|
||
/** | ||
* The Int64 type (long) | ||
*/ | ||
class Int64Type extends IntType implements Incrementable, Versionable | ||
{ | ||
public function convertToDatabaseValue($value) | ||
{ | ||
return $value !== null ? new Int64($value) : null; | ||
} | ||
|
||
public function closureToMongo(): string | ||
{ | ||
return '$return = new \MongoDB\BSON\Int64($value);'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
<field name="intField" type="int"> | ||
<encrypt queryType="range" min="5" max="10"/> | ||
</field> | ||
<field name="int64Field" type="int64"> | ||
<encrypt queryType="range" min="5" max="9223372036854775802"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it even necessary to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a type assertion in My idea for using a low and a high value for the min and max was to test that they are both converted to |
||
</field> | ||
<field name="floatField" type="float"> | ||
<encrypt queryType="range" min="5.5" max="10.5"/> | ||
</field> | ||
|
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.
Contrary to the PR description,
int64
might have uses beyond encryption such as satisfying a general schema or improving compatibility in cross-language apps (other drivers might not play nice with interchangeable integer types).Uh oh!
There was an error while loading. Please reload this page.
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.
Ok, the new type can be used independently from encryption.
Note that the
int
type will encode to Int64 when the value exceeds 32 bits. That would be a programmer issue. I could add an Int32 type to throw an error when the value does not fit in 32 bits.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.
That's legacy behavior for ODM and the expected behavior for the server (e.g. incrementing an int32 BSON type server-side could yield an int64), so I'm not worried about it. And so long as ODM continues to accept int64 BSON types for
int
mappings I think we're OK.This could certainly be added down the line. I'd probably wait until it was requested, though.