@@ -158,9 +158,40 @@ following methods to create a ``Uuid`` object from it::
158
158
$uuid = Uuid::fromBase58('TuetYWNHhmuSQ3xPoVLv9M');
159
159
$uuid = Uuid::fromRfc4122('d9e7a184-5d5b-11ea-a62a-3499710062d0');
160
160
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\S ervice;
165
+
166
+ use Symfony\C omponent\U id\F actory\U uidFactory;
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::
164
195
165
196
.. configuration-block ::
166
197
@@ -169,10 +200,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
169
200
# config/packages/uid.yaml
170
201
framework :
171
202
uid :
172
- default_uuid_version : 7
173
- name_based_uuid_version : 5
203
+ default_uuid_version : 6
204
+ name_based_uuid_version : 3
174
205
name_based_uuid_namespace : 6ba7b810-9dad-11d1-80b4-00c04fd430c8
175
- time_based_uuid_version : 7
206
+ time_based_uuid_version : 6
176
207
time_based_uuid_node : 121212121212
177
208
178
209
.. code-block :: xml
@@ -188,10 +219,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
188
219
189
220
<framework : config >
190
221
<framework : uid
191
- default_uuid_version =" 7 "
192
- name_based_uuid_version =" 5 "
222
+ default_uuid_version =" 6 "
223
+ name_based_uuid_version =" 6 "
193
224
name_based_uuid_namespace =" 6ba7b810-9dad-11d1-80b4-00c04fd430c8"
194
- time_based_uuid_version =" 7 "
225
+ time_based_uuid_version =" 6 "
195
226
time_based_uuid_node =" 121212121212"
196
227
/>
197
228
</framework : config >
@@ -210,10 +241,10 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
210
241
211
242
$container->extension('framework', [
212
243
'uid' => [
213
- 'default_uuid_version' => 7 ,
214
- 'name_based_uuid_version' => 5 ,
244
+ 'default_uuid_version' => 6 ,
245
+ 'name_based_uuid_version' => 3 ,
215
246
'name_based_uuid_namespace' => '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
216
- 'time_based_uuid_version' => 7 ,
247
+ 'time_based_uuid_version' => 6 ,
217
248
'time_based_uuid_node' => 121212121212,
218
249
],
219
250
]);
@@ -224,33 +255,6 @@ UUIDv4 for random-based UUIDs, but you can configure this behavior::
224
255
Starting from Symfony 7.4, the default version for both UUIDs and time-based
225
256
UUIDs is UUIDv7. In previous versions, the default was UUIDv6.
226
257
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
-
254
258
Converting UUIDs
255
259
~~~~~~~~~~~~~~~~
256
260
0 commit comments