8000 minor #14427 [Lock] Replace LockInterface by LockFactory in DI (jderu… · symfony/symfony-docs@12855f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12855f7

Browse files
committed
minor #14427 [Lock] Replace LockInterface by LockFactory in DI (jderusse)
This PR was merged into the 5.x branch. Discussion ---------- [Lock] Replace LockInterface by LockFactory in DI Fixes #14416 and fixes #14425 Commits ------- 81d6877 Replace LockInterface by LockFactory in DI
2 parents fbd06ce + 81d6877 commit 12855f7

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lock.rst

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,23 @@ this behavior by using the ``lock`` key like:
159159
Locking a Resource
160160
------------------
161161

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``)::
164164

165165
// src/Controller/PdfController.php
166166
namespace App\Controller;
167167

168168
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
169-
use Symfony\Component\Lock\LockInterface;
169+
use Symfony\Component\Lock\LockFactory;
170170

171171
class PdfController extends AbstractController
172172
{
173173
/**
174174
* @Route("/download/terms-of-use.pdf")
175175
*/
176-
public function downloadPdf(LockInterface $lock, MyPdfGeneratorService $pdf)
176+
public function downloadPdf(LockFactory $factory, MyPdfGeneratorService $pdf)
177177
{
178+
$lock = $factory->createLock('pdf-creation');
178179
$lock->acquire(true);
179180

180181
// heavy computation
@@ -273,18 +274,12 @@ provides :ref:`named lock <reference-lock-resources-name>`::
273274
],
274275
]);
275276
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`.
288283

289284
Blocking Store
290285
--------------

0 commit comments

Comments
 (0)
0