@@ -159,22 +159,23 @@ this behavior by using the ``lock`` key like:
159
159
Locking a Resource
160
160
------------------
161
161
162
- To lock the default resource, autowire the lock using
163
- :class: `Symfony\\ Component\\ Lock\\ LockInterface ` (service id ``lock ``)::
162
+ To lock the default resource, autowire the lock factory using
163
+ :class: `Symfony\\ Component\\ Lock\\ LockFactory ` (service id ``lock.factory ``)::
164
164
165
165
// src/Controller/PdfController.php
166
166
namespace App\Controller;
167
167
168
168
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
169
- use Symfony\Component\Lock\LockInterface ;
169
+ use Symfony\Component\Lock\LockFactory ;
170
170
171
171
class PdfController extends AbstractController
172
172
{
173
173
/**
174
174
* @Route("/download/terms-of-use.pdf")
175
175
*/
176
- public function downloadPdf(LockInterface $lock , MyPdfGeneratorService $pdf)
176
+ public function downloadPdf(LockFactory $factory , MyPdfGeneratorService $pdf)
177
177
{
178
+ $lock = $factory->createLock('pdf-creation');
178
179
$lock->acquire(true);
179
180
180
181
// heavy computation
@@ -193,6 +194,11 @@ To lock the default resource, autowire the lock using
193
194
same lock, inject the ``LockFactory `` instead to create a separate lock
194
195
instance for each service.
195
196
197
+ .. deprecated :: 5.2
198
+
199
+ The ``LockInterface `` service and ``lock `` alias are deprecated since
200
+ Symfony 5.2.
201
+
196
202
Locking a Dynamic Resource
197
203
--------------------------
198
204
@@ -273,18 +279,20 @@ provides :ref:`named lock <reference-lock-resources-name>`::
273
279
],
274
280
]);
275
281
276
- Each name becomes a service where the service id suffixed by the name of the
277
- lock (e.g. ``lock.invoice ``). An autowiring alias is also created for each lock
278
- using the camel case version of its name suffixed by ``Lock `` - e.g. ``invoice ``
279
- can be injected automatically by naming the argument ``$invoiceLock `` and
280
- type-hinting it with :class: `Symfony\\ Component\\ Lock\\ LockInterface `.
281
-
282
- Symfony also provide a corresponding factory and store following the same rules
283
- (e.g. ``invoice `` generates a ``lock.invoice.factory `` and
284
- ``lock.invoice.store ``, both can be injected automatically by naming
285
- respectively ``$invoiceLockFactory `` and ``$invoiceLockStore `` and type-hinted
286
- with :class: `Symfony\\ Component\\ Lock\\ LockFactory ` and
287
- :class: `Symfony\\ Component\\ Lock\\ PersistingStoreInterface `)
282
+ Each name becomes a service where the service id is part of the name of the
283
+ lock (e.g. ``lock.invoice.factory ``). An autowiring alias is also created for
284
+ each lock using the camel case version of its name suffixed by ``LockFactory ``
285
+ - e.g. ``invoice `` can be injected automatically by naming the argument
286
+ ``$invoiceLockFactory `` and type-hinting it with
287
+ :class: `Symfony\\ Component\\ Lock\\ LockFactory `.
288
+
289
+ .. deprecated :: 5.2
290
+
291
+ The services for ``LockInterface `` (ie. ``lock ``, ``lock.invoice ``,
292
+ ``LockInterface $invoiceLock ``) and ``PersistingStoreInterface `` (ie.
293
+ ``lock.store ``, ``lock.invoice.store ``, ``PersistingStoreInterface
294
+ $invoiceLockStore ``) are deprecated Symfony 5.2.
295
+
288
296
289
297
Blocking Store
290
298
--------------
0 commit comments