@@ -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
@@ -273,18 +274,12 @@ provides :ref:`named lock <reference-lock-resources-name>`::
273
274
],
274
275
]);
275
276
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 `)
277
+ Each name becomes a service where the service id is part of the name of the
278
+ lock (e.g. ``lock.invoice.factory ``). An autowiring alias is also created for
279
+ each lock using the camel case version of its name suffixed by ``LockFactory ``
280
+ - e.g. ``invoice `` can be injected automatically by naming the argument
281
+ ``$invoiceLockFactory `` and type-hinting it with
282
+ :class: `Symfony\\ Component\\ Lock\\ LockFactory `.
288
283
289
284
Blocking Store
290
285
--------------
0 commit comments