Skip to content

Commit 3d19d98

Browse files
committed
Improve docs
1 parent 70ab5b9 commit 3d19d98

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

components/uid.rst

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,40 @@ following methods to create a ``Uuid`` object from it::
158158
$uuid = Uuid::fromBase58('TuetYWNHhmuSQ3xPoVLv9M');
159159
$uuid = Uuid::fromRfc4122('d9e7a184-5d5b-11ea-a62a-3499710062d0');
160160

161-
You can also use the ``UuidFactory`` to generate UUIDs. By default, this factory
162-
uses UUIDv7 for default and time-based UUIDs, UUIDv5 for name-based UUIDS, and
163-
UUIDv4 for random-based UUIDs, but you can configure this behavior::
161+
You can also use the ``UuidFactory`` to generate UUIDs. Inject the factory in
162+
your services and use it as follows:
163+
164+
namespace App\Service;
165+
166+
use Symfony\Component\Uid\Factory\UuidFactory;
167+
168+
class FooService
169+
{
170+
public function __construct(
171+
private UuidFactory $uuidFactory,
172+
) {
173+
}
174+
175+
public function generate(): void
176+
{
177+
$uuid = $this->uuidFactory->create();
178+
179+
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
180+
$randomBasedUuid = $this->uuidFactory->randomBased();
181+
$timestampBased = $this->uuidFactory->timeBased();
182+
183+
// ...
184+
}
185+
}
186+
187+
By default, this factory generates the folllowing UUIDs:
188+
189+
* Default and time-based UUIDs: UUIDv7
190+
* Name-based UUIDs: UUIDv5
191+
* Random-based UUIDs: UUIDv4
192+
* Time-based node and UUID namespace: ``null``
193+
194+
You can configure these default values::
164195

165196
.. configuration-block::
166197

@@ -169,10 +200,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
169200
# config/packages/uid.yaml
170201
framework:
171202
uid:
172-
default_uuid_version: 7
173-
name_based_uuid_version: 5
203+
default_uuid_version: 6
204+
name_based_uuid_version: 3
174205
name_based_uuid_namespace: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
175-
time_based_uuid_version: 7
206+
time_based_uuid_version: 6
176207
time_based_uuid_node: 121212121212
177208
178209
.. code-block:: xml
@@ -188,10 +219,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
188219
189220
<framework:config>
190221
<framework:uid
191-
default_uuid_version="7"
192-
name_based_uuid_version="5"
222+
default_uuid_version="6"
223+
name_based_uuid_version="6"
193224
name_based_uuid_namespace="6ba7b810-9dad-11d1-80b4-00c04fd430c8"
194-
time_based_uuid_version="7"
225+
time_based_uuid_version="6"
195226
time_based_uuid_node="121212121212"
196227
/>
197228
</framework:config>
@@ -210,10 +241,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
210241
211242
$container->extension('framework', [
212243
'uid' => [
213-
'default_uuid_version' => 7,
214-
'name_based_uuid_version' => 5,
244+
'default_uuid_version' => 6,
245+
'name_based_uuid_version' => 3,
215246
'name_based_uuid_namespace' => '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
216-
'time_based_uuid_version' => 7,
247+
'time_based_uuid_version' => 6,
217248
'time_based_uuid_node' => 121212121212,
218249
],
219250
]);
@@ -224,33 +255,6 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
224255
Starting from Symfony 7.4, the default version for both UUIDs and time-based
225256
UUIDs is UUIDv7. In previous versions, the default was UUIDv6.
226257

227-
Then, you can inject the factory in your services and use it to generate UUIDs based
228-
on the configuration you defined::
229-
230-
namespace App\Service;
231-
232-
use Symfony\Component\Uid\Factory\UuidFactory;
233-
234-
class FooService
235-
{
236-
public function __construct(
237-
private UuidFactory $uuidFactory,
238-
) {
239-
}
240-
241-
public function generate(): void
242-
{
243-
// This creates a UUID of the version given in the configuration file (v7 by default)
244-
$uuid = $this->uuidFactory->create();
245-
246-
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
247-
$randomBasedUuid = $this->uuidFactory->randomBased();
248-
$timestampBased = $this->uuidFactory->timeBased();
249-
250-
// ...
251-
}
252-
}
253-
254258
Converting UUIDs
255259
~~~~~~~~~~~~~~~~
256260

0 commit comments

Comments
 (0)