Skip to content

Commit 176fbed

Browse files
Fine-tuning codeblock (#9176)
* Deleting "Not needed for XML and YAML mapping" - this was stupid of me, since *all* annotations are obviously not needed in XML&YAML ;-) * Shortening the @column annotation, for consistency with the following event handlers * Removing some blank lines from XML, for consistency with YAML * Adding PHP Attributes
1 parent 8336420 commit 176fbed

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

docs/en/reference/events.rst

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,52 @@ specific to a particular entity class's lifecycle.
293293

294294
.. configuration-block::
295295

296-
.. code-block:: php
296+
.. code-block:: attribute
297+
298+
<?php
299+
300+
/**
301+
* #[Entity]
302+
* #[HasLifecycleCallbacks]
303+
*/
304+
class User
305+
{
306+
// ...
307+
308+
#[Column(type: 'string', length: 255)]
309+
public $value;
310+
311+
#[PrePersist]
312+
public function doStuffOnPrePersist()
313+
{
314+
$this->createdAt = date('Y-m-d H:i:s');
315+
}
316+
317+
#[PrePersist]
318+
public function doOtherStuffOnPrePersist()
319+
{
320+
$this->value = 'changed from prePersist callback!';
321+
}
322+
323+
#[PostLoad]
324+
public function doStuffOnPostLoad()
325+
{
326+
$this->value = 'changed from postLoad callback!';
327+
}
328+
}
329+
.. code-block:: annotation
297330
298331
<?php
299332
300333
/**
301334
* @Entity
302-
* @HasLifecycleCallbacks // Not needed for XML and YAML mapping
335+
* @HasLifecycleCallbacks
303336
*/
304337
class User
305338
{
306339
// ...
307340
308-
/**
309-
* @Column(type="string", length=255)
310-
*/
341+
/** @Column(type="string", length=255) */
311342
public $value;
312343
313344
/** @PrePersist */
@@ -336,17 +367,14 @@ specific to a particular entity class's lifecycle.
336367
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
337368
xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping
338369
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
339-
340370
<entity name="User">
341-
371+
<!-- ... -->
342372
<lifecycle-callbacks>
343373
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
344374
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersist"/>
345375
<lifecycle-callback type="postLoad" method="doStuffOnPostLoad"/>
346376
</lifecycle-callbacks>
347-
348377
</entity>
349-
350378
</doctrine-mapping>
351379
.. code-block:: yaml
352380

0 commit comments

Comments
 (0)