Skip to content

Commit d052a00

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [VarExporter] Deprecate per-property lazy-initializers
2 parents 5ae70e7 + 9a4d0c4 commit d052a00

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

components/var_exporter.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ LazyGhostTrait
195195

196196
Ghost objects are empty objects, which see their properties populated the first
197197
time any method is called. Thanks to :class:`Symfony\\Component\\VarExporter\\LazyGhostTrait`,
198-
the implementation of the lazy mechanism is eased. In the following example, the
199-
``$hash`` property is defined as lazy. Also, the ``MyLazyObject::computeHash()``
200-
method should be called only when ``$hash``'s value need to be known::
198+
the implementation of the lazy mechanism is eased. The ``MyLazyObject::populateHash()``
199+
method will be called only when the object is actually used and needs to be
200+
initialized::
201201

202202
namespace App\Hash;
203203

@@ -215,17 +215,21 @@ method should be called only when ``$hash``'s value need to be known::
215215

216216
public function __construct()
217217
{
218-
self::createLazyGhost(initializer: [
219-
'hash' => $this->computeHash(...),
220-
], instance: $this);
218+
self::createLazyGhost(initializer: $this->populateHash(...), instance: $this);
221219
}
222220

223-
private function computeHash(array $data): string
221+
private function populateHash(array $data): void
224222
{
225223
// Compute $this->hash value with the passed data
226224
}
227225
}
228226

227+
.. deprecated:: 6.4
228+
229+
Using an array of closures for property-based initialization in the
230+
``createLazyGhost()`` method is deprecated since Symfony 6.4. Pass
231+
a single closure that initializes the whole object instead.
232+
229233
:class:`Symfony\\Component\\VarExporter\\LazyGhostTrait` also allows to
230234
convert non-lazy classes to lazy ones::
231235

@@ -239,10 +243,10 @@ convert non-lazy classes to lazy ones::
239243

240244
public function __construct(array $data)
241245
{
242-
$this->hash = $this->computeHash($data);
246+
$this->populateHash($data);
243247
}
244248

245-
private function computeHash(array $data): string
249+
private function populateHash(array $data): void
246250
{
247251
// ...
248252
}
@@ -322,10 +326,10 @@ code::
322326
{
323327
public function __construct(array $data)
324328
{
325-
$this->hash = $this->computeHash($data);
329+
$this->populateHash($data);
326330
}
327331

328-
private function computeHash(array $data): string
332+
private function populateHash(array $data): void
329333
{
330334
// ...
331335
}

0 commit comments

Comments
 (0)