Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,12 @@ object ID. The available strategies are:
- ``ALNUM`` - Generates an alpha-numeric string (based on an incrementing value).
- ``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 (deprecated).
- ``NONE`` - Do not generate any identifier. ID must be manually set.

When using the ``AUTO`` strategy in combination with a UUID identifier, the generator can create UUIDs of type 1, type 4,
and type 7 automatically. For all other UUID types, assign the identifier manually in combination with the ``NONE``
strategy.

.. note::

The ``UUID`` generator is deprecated, as it stores UUIDs as strings. It is recommended to use the ``AUTO`` strategy
with a ``uuid`` type identifier field instead. If you need to keep generating string UUIDs, you can use the
``CUSTOM`` strategy with your own generator.

Here is an example how to manually set a string identifier for your documents:

.. configuration-block::
Expand All @@ -315,7 +308,7 @@ Here is an example how to manually set a string identifier for your documents:
#[Document]
class MyPersistentClass
{
#[Id(strategy: 'NONE', type: 'string')]
#[Id(strategy: 'NONE')]
public string $id;

//...
Expand Down
10 changes: 0 additions & 10 deletions src/Id/AbstractIdGenerator.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Id/AutoGenerator.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Id/IncrementGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* collection. If not specified it defaults to the name of the collection for the
* document.
*/
class IncrementGenerator extends AbstractIdGenerator
class IncrementGenerator implements IdGenerator
{
/** @var string|null */
protected $collection = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Id/ObjectIdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use MongoDB\BSON\ObjectId;

/** @internal */
final class ObjectIdGenerator extends AbstractIdGenerator
final class ObjectIdGenerator implements IdGenerator
{
public function generate(DocumentManager $dm, object $document): ObjectId
{
Expand Down
2 changes: 1 addition & 1 deletion src/Id/SymfonyUuidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function sprintf;

/** @internal */
final class SymfonyUuidGenerator extends AbstractIdGenerator
final class SymfonyUuidGenerator implements IdGenerator
{
private const SUPPORTED_TYPES = [
1 => UuidV1::class,
Expand Down
141 changes: 0 additions & 141 deletions src/Id/UuidGenerator.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@
*/
public const GENERATOR_TYPE_INCREMENT = 2;

/**
* UUID means Doctrine will generate a uuid for us.
*
* @deprecated without replacement. Use a custom generator or switch to binary UUIDs.
*/
public const GENERATOR_TYPE_UUID = 3;

/**
* ALNUM means Doctrine will generate Alpha-numeric string identifiers, using the INCREMENT
* generator to ensure identifier uniqueness
Expand Down Expand Up @@ -2168,14 +2161,6 @@ public function isIdGeneratorIncrement(): bool
return $this->generatorType === self::GENERATOR_TYPE_INCREMENT;
}

/**
* Checks whether the class will generate a uuid id.
*/
public function isIdGeneratorUuid(): bool
{
return $this->generatorType === self::GENERATOR_TYPE_UUID;
}
Comment on lines -2171 to -2177
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a deprecation before removing this method: #2896


/**
* Checks whether the class uses no id generator.
*/
Expand Down
9 changes: 0 additions & 9 deletions src/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ODM\MongoDB\Id\IncrementGenerator;
use Doctrine\ODM\MongoDB\Id\ObjectIdGenerator;
use Doctrine\ODM\MongoDB\Id\SymfonyUuidGenerator;
use Doctrine\ODM\MongoDB\Id\UuidGenerator;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
Expand Down Expand Up @@ -292,14 +291,6 @@ private function completeIdGeneratorMapping(ClassMetadata $class): void

$class->setIdGenerator($incrementGenerator);
break;
case ClassMetadata::GENERATOR_TYPE_UUID:
$uuidGenerator = new UuidGenerator();
if (isset($idGenOptions['salt'])) {
$uuidGenerator->setSalt((string) $idGenOptions['salt']);
}

$class->setIdGenerator($uuidGenerator);
break;
case ClassMetadata::GENERATOR_TYPE_ALNUM:
$alnumGenerator = new AlnumGenerator();
if (isset($idGenOptions['pad'])) {
Expand Down
61 changes: 0 additions & 61 deletions tests/Tests/Functional/IdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use DateTime;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Id\UuidGenerator;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use InvalidArgumentException;
use MongoDB\BSON\Binary;
Expand All @@ -22,35 +20,11 @@
use function gettype;
use function is_object;
use function md5;
use function serialize;
use function sprintf;
use function ucfirst;
use function unserialize;

class IdTest extends BaseTestCase
{
public function testUuidId(): void
{
$user = new UuidUser('Jonathan H. Wage');
$this->dm->persist($user);
$this->dm->flush();
$id = $user->id;

$this->dm->clear();
$check1 = $this->dm->getRepository(UuidUser::class)->findOneBy(['id' => $id]);
self::assertNotNull($check1);

$check2 = $this->dm->createQueryBuilder(UuidUser::class)
->field('id')->equals($id)->getQuery()->getSingleResult();
self::assertNotNull($check2);
self::assertSame($check1, $check2);

$check3 = $this->dm->createQueryBuilder(UuidUser::class)
->field('name')->equals('Jonathan H. Wage')->getQuery()->getSingleResult();
self::assertNotNull($check3);
self::assertSame($check2, $check3);
}

public function testAlnumIdChars(): void
{
$user = new AlnumCharsUser('Jonathan H. Wage');
Expand Down Expand Up @@ -146,23 +120,6 @@ public function testEmbeddedDocumentWithId(): void
self::assertEquals(4, $user2->embedded[1]->id);
}

public function testIdGeneratorInstance(): void
{
$class = $this->dm->getClassMetadata(UuidUser::class);
self::assertEquals(ClassMetadata::GENERATOR_TYPE_UUID, $class->generatorType);
self::assertEquals(['salt' => 'test'], $class->generatorOptions);
self::assertInstanceOf(UuidGenerator::class, $class->idGenerator);
self::assertEquals('test', $class->idGenerator->getSalt());

$serialized = serialize($class);
$class = unserialize($serialized);

self::assertEquals(ClassMetadata::GENERATOR_TYPE_UUID, $class->generatorType);
self::assertEquals(['salt' => 'test'], $class->generatorOptions);
self::assertInstanceOf(UuidGenerator::class, $class->idGenerator);
self::assertEquals('test', $class->idGenerator->getSalt());
}

/** @param int|float $user2Id */
#[DataProvider('provideEqualButNotIdenticalIds')]
public function testEqualButNotIdenticalIds(string $user1Id, $user2Id): void
Expand Down Expand Up @@ -293,7 +250,6 @@ public static function getTestIdTypesAndStrategiesData(): array

// bin
['bin', 'none', 'test-data', 'test-data', Binary::class],
['bin', 'uuid', null, null, Binary::class],
['bin_func', 'none', 'test-data', 'test-data', Binary::class],
['bin_bytearray', 'none', 'test-data', 'test-data', Binary::class],
['bin_uuid', 'none', 'TestTestTestTest', 'TestTestTestTest', Binary::class],
Expand Down Expand Up @@ -392,23 +348,6 @@ class %s
}
}

#[ODM\Document]
class UuidUser
{
/** @var string|null */
#[ODM\Id(strategy: 'uuid', options: ['salt' => 'test'])]
public $id;

/** @var string */
#[ODM\Field(name: 't', type: 'string')]
public $name;

public function __construct(string $name)
{
$this->name = $name;
}
}

#[ODM\Document]
class CollectionIdUser
{
Expand Down
Loading