@@ -427,6 +427,9 @@ You can also mix objects and arrays::
427
427
Custom method calls and virtual properties in a class
428
428
-----------------------------------------------------
429
429
430
+ .. versionadded :: 3.4
431
+ Support for custom accessors was introduced in Symfony 3.4.
432
+
430
433
Sometimes you may not want the component to guess which method has to be called
431
434
when reading or writing properties. This is especially interesting when property
432
435
names are not in English or its singularization is not properly detected.
@@ -453,7 +456,7 @@ configuration files.
453
456
There are four method calls that can be overriden: ``getter ``, ``setter ``, ``adder `` and
454
457
``remover ``.
455
458
456
- When using annotations you can precede a property with ``@Property `` to state which
459
+ When using annotations you can precede a property with ``@PropertyAccessor `` to state which
457
460
method should be called when a get, set, add or remove operation is needed on the
458
461
property.
459
462
@@ -462,17 +465,17 @@ property.
462
465
.. code-block :: php-annotations
463
466
464
467
// ...
465
- use Symfony\Component\PropertyAccess\Annotation\Property ;
468
+ use Symfony\Component\PropertyAccess\Annotation\PropertyAccessor ;
466
469
467
470
class Person
468
471
{
469
472
/**
470
- * @Property (getter="getFullName", setter="setFullName")
473
+ * @PropertyAccessor (getter="getFullName", setter="setFullName")
471
474
*/
472
475
private $name;
473
476
474
477
/**
475
- * @Property (adder="addNewChild", remover="discardChild")
478
+ * @PropertyAccessor (adder="addNewChild", remover="discardChild")
476
479
*/
477
480
private $children;
478
481
@@ -527,8 +530,8 @@ Then, using the overriden methods is automatic:
527
530
// will return 'Hello John Doe'
528
531
529
532
You can also associate a particular method with an operation on a property
530
- using the ``@PropertyGetter ``, ``@PropertySetter ``, ``@PropertyAdder `` and
531
- ``@PropertyRemover `` annotations. All of them take only one parameter: ``property ``.
533
+ using the ``@GetterAccessor ``, ``@SetterAccessor ``, ``@AdderAccessor `` and
534
+ ``@RemoverAccessor `` annotations. All of them take only one parameter: ``property ``.
532
535
533
536
This allows creating virtual properties that are not directly stored in the
534
537
object:
@@ -538,8 +541,8 @@ object:
538
541
.. code-block :: php-annotations
539
542
540
543
// ...
541
- use Symfony\Component\PropertyAccess\Annotation\PropertyGetter ;
542
- use Symfony\Component\PropertyAccess\Annotation\PropertySetter ;
544
+ use Symfony\Component\PropertyAccess\Annotation\GetterAccessor ;
545
+ use Symfony\Component\PropertyAccess\Annotation\SetterAccessor ;
543
546
544
547
class Invoice
545
548
{
@@ -550,7 +553,7 @@ object:
550
553
// Notice that there is no real "total" property
551
554
552
555
/**
553
- * @PropertyGetter (property="total")
556
+ * @GetterAccessor (property="total")
554
557
*/
555
558
public function getTotal()
556
559
{
@@ -559,7 +562,7 @@ object:
559
562
560
563
// Notice that 'property' can be omitted in the parameter
561
564
/**
562
- * @PropertySetter ("total")
565
+ * @SetterAccessor ("total")
563
566
*
564
567
* @param mixed $total
565
568
*/
0 commit comments