Maslosoft Mangan Logo 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:

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;
}