Skip to content

Commit

Permalink
Replace AbstractIdGenerator with IdGenerator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jun 19, 2024
1 parent 98e2e1b commit 797872d
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ object ID. The available strategies are:

- ``AUTO`` - Uses the native generated ObjectId.
- ``ALNUM`` - Generates an alpha-numeric string (based on an incrementing value).
- ``CUSTOM`` - Defers generation to a AbstractIdGenerator implementation specified in the ``class`` option.
- ``CUSTOM`` - Defers generation to an implementation of ``IdGenerator`` specified in the ``class`` option.
- ``INCREMENT`` - Uses another collection to auto increment an integer identifier.
- ``UUID`` - Generates a UUID identifier.
- ``NONE`` - Do not generate any identifier. ID must be manually set.
Expand Down Expand Up @@ -349,9 +349,28 @@ Now you can retrieve the document later:
$document = $dm->find(MyPersistentClass::class, 'my_unique_identifier');
You can define your own ID generator by extending the
``Doctrine\ODM\MongoDB\Id\AbstractIdGenerator`` class and specifying the class
as an option for the ``CUSTOM`` strategy:
You can define your own ID generator by implementing the
``Doctrine\ODM\MongoDB\Id\IdGenerator`` interface:

.. code-block:: php
<?php
namespace Vendor\Specific;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Id\IdGenerator;
class Generator implements IdGenerator
{
public function generate(DocumentManager $dm, object $document)
{
// Your own logic here
return 'my_generated_id';
}
}
Then specify the ``class`` option for the ``CUSTOM`` strategy:

.. configuration-block::

Expand Down

0 comments on commit 797872d

Please sign in to comment.