@@ -374,6 +374,9 @@ You can also mix objects and arrays::
374
374
Custom method calls and virtual properties in a class
375
375
-----------------------------------------------------
376
376
377
+ .. versionadded :: 3.4
378
+ Support for custom accessors was introduced in Symfony 3.4.
379
+
377
380
Sometimes you may not want the component to guess which method has to be called
378
381
when reading or writing properties. This is especially interesting when property
379
382
names are not in English or its singularization is not properly detected.
@@ -400,7 +403,7 @@ configuration files.
400
403
There are four method calls that can be overriden: ``getter ``, ``setter ``, ``adder `` and
401
404
``remover ``.
402
405
403
- When using annotations you can precede a property with ``@Property `` to state which
406
+ When using annotations you can precede a property with ``@PropertyAccessor `` to state which
404
407
method should be called when a get, set, add or remove operation is needed on the
405
408
property.
406
409
@@ -409,17 +412,17 @@ property.
409
412
.. code-block :: php-annotations
410
413
411
414
// ...
412
- use Symfony\Component\PropertyAccess\Annotation\Property ;
415
+ use Symfony\Component\PropertyAccess\Annotation\PropertyAccessor ;
413
416
414
417
class Person
415
418
{
416
419
/**
417
- * @Property (getter="getFullName", setter="setFullName")
420
+ * @PropertyAccessor (getter="getFullName", setter="setFullName")
418
421
*/
419
422
private $name;
420
423
421
424
/**
422
- * @Property (adder="addNewChild", remover="discardChild")
425
+ * @PropertyAccessor (adder="addNewChild", remover="discardChild")
423
426
*/
424
427
private $children;
425
428
@@ -474,8 +477,8 @@ Then, using the overriden methods is automatic:
474
477
// will return 'Hello John Doe'
475
478
476
479
You can also associate a particular method with an operation on a property
477
- using the ``@PropertyGetter ``, ``@PropertySetter ``, ``@PropertyAdder `` and
478
- ``@PropertyRemover `` annotations. All of them take only one parameter: ``property ``.
480
+ using the ``@GetterAccessor ``, ``@SetterAccessor ``, ``@AdderAccessor `` and
481
+ ``@RemoverAccessor `` annotations. All of them take only one parameter: ``property ``.
479
482
480
483
This allows creating virtual properties that are not directly stored in the
481
484
object:
@@ -485,8 +488,8 @@ object:
485
488
.. code-block :: php-annotations
486
489
487
490
// ...
488
- use Symfony\Component\PropertyAccess\Annotation\PropertyGetter ;
489
- use Symfony\Component\PropertyAccess\Annotation\PropertySetter ;
491
+ use Symfony\Component\PropertyAccess\Annotation\GetterAccessor ;
492
+ use Symfony\Component\PropertyAccess\Annotation\SetterAccessor ;
490
493
491
494
class Invoice
492
495
{
@@ -497,7 +500,7 @@ object:
497
500
// Notice that there is no real "total" property
498
501
499
502
/**
500
- * @PropertyGetter (property="total")
503
+ * @GetterAccessor (property="total")
501
504
*/
502
505
public function getTotal()
503
506
{
@@ -506,7 +509,7 @@ object:
506
509
507
510
// Notice that 'property' can be omitted in the parameter
508
511
/**
509
- * @PropertySetter ("total")
512
+ * @SetterAccessor ("total")
510
513
*
511
514
* @param mixed $total
512
515
*/
0 commit comments