From 2d4ba43093b407ca4f8ed42a5595ab272d1fa522 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 31 Jan 2023 13:03:30 +0100 Subject: [PATCH] [Lock] Complete Lock example for less ambiguity --- components/lock.rst | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/components/lock.rst b/components/lock.rst index bce846ef0b7..fa048e56264 100644 --- a/components/lock.rst +++ b/components/lock.rst @@ -75,8 +75,42 @@ Serializing Locks The :class:`Symfony\\Component\\Lock\\Key` contains the state of the :class:`Symfony\\Component\\Lock\\Lock` and can be serialized. This allows the user to begin a long job in a process by acquiring the lock, and -continue the job in another process using the same lock:: +continue the job in another process using the same lock. +First, you may create a serializable class containing the resource and the +key of the lock:: + + // src/Lock/RefreshTaxonomy.php + namespace App\Lock; + + use Symfony\Component\Lock\Key; + + class RefreshTaxonomy + { + private object $article; + private Key $key; + + public function __construct(object $article, Key $key) + { + $this->article = $article; + $this->key = $key; + } + + public function getArticle(): object + { + return $this->article; + } + + public function getKey(): Key + { + return $this->key; + } + } + +Then, you can use this class to dispatch all that's needed for another process +to handle the rest of the job:: + + use App\Lock\RefreshTaxonomy; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\Lock;