Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[VarExporter] Deprecate per-property lazy-initializers#19132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletionscomponents/var_exporter.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -199,9 +199,9 @@ LazyGhostTrait

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

namespace App\Hash;

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

public function __construct()
{
self::createLazyGhost(initializer: [
'hash' => $this->computeHash(...),
], instance: $this);
self::createLazyGhost(initializer: $this->populateHash(...), instance: $this);
}

private functioncomputeHash(array $data):string
private functionpopulateHash(array $data):void
{
// Compute $this->hash value with the passed data
}
}

.. deprecated:: 6.4

Using an array of closures for property-based initialization in the
``createLazyGhost()`` method is deprecated since Symfony 6.4. Pass
a single closure that initializes the whole object instead.

:class:`Symfony\\Component\\VarExporter\\LazyGhostTrait` also allows to
convert non-lazy classes to lazy ones::

Expand All@@ -243,10 +247,10 @@ convert non-lazy classes to lazy ones::

public function __construct(array $data)
{
$this->hash = $this->computeHash($data);
$this->populateHash($data);
}

private functioncomputeHash(array $data):string
private functionpopulateHash(array $data):void
{
// ...
}
Expand DownExpand Up@@ -330,10 +334,10 @@ code::
{
public function __construct(array $data)
{
$this->hash = $this->computeHash($data);
$this->populateHash($data);
}

private functioncomputeHash(array $data):string
private functionpopulateHash(array $data):void
{
// ...
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp