Maslosoft Mangan Documentation
MongoDB Object Persister
Edit
ObjectId Sanitizers
ObjectId sanitizers will ensure that value is MongoId. This sanitizers will not be autodetected and need to be explicitly set.
There are two distinct, but similar sanitizer for MongoDB ObjectId:
MongoObjectId
- will ensure object ID as an objectMongoStringId
- will ensure object ID as a string
Both sanitizers have $nullable
option to allow null
values,
defaults to false.
If not set, or set to false
, ObjectId will be generated as needed.
Full example of using MongoStringId
and MongoObjectId
:
use Maslosoft\Addendum\Interfaces\AnnotatedInterface use Maslosoft\Mangan\Sanitizers\MongoObjectId; use Maslosoft\Mangan\Sanitizers\MongoStringId; class MyClass implements AnnotatedInterface { /** * @Sanitizer(MongoStringId) */ public $myStringId = ''; /** * @Sanitizer(MongoObjectId) */ public $myObjectId = null; }