@@ -394,6 +394,51 @@ and ``removeChild()`` methods to access to the ``children`` property.
394
394
395
395
If available, *adder * and *remover * methods have priority over a *setter * method.
396
396
397
+ Using non-standard adder/remover methods
398
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
399
+
400
+ Like we just said, ``PropertyAccessor `` class allows to update the content of arrays stored in properties through
401
+ *adder * and *remover * methods. But sometimes theses methods doesn't use the standard ``add `` and ``remove `` prefix::
402
+
403
+ // ...
404
+ class PeopleList
405
+ {
406
+ /**
407
+ * @var string[]
408
+ */
409
+ private $peoples = [];
410
+
411
+ public function getPeoples(): array
412
+ {
413
+ return $this->peoples;
414
+ }
415
+
416
+ public function joinPeople(string $people): void
417
+ {
418
+ $this->peoples[] = $people;
419
+ }
420
+
421
+ public function leavePeople(string $people): void
422
+ {
423
+ foreach ($this->peoples as $id => $item) {
424
+ if ($people === $item) {
425
+ unset($this->peoples[$id]);
426
+ break;
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ $list = new PeopleList();
433
+ $reflectionExtractor = new ReflectionExtractor(null, null, ['join', 'leave']);
434
+ $propertyAccessor = new PropertyAccessor(false, false, null, true, $reflectionExtractor, $reflectionExtractor);
435
+ $propertyAccessor->setValue($person, 'peoples', ['kevin', 'wouter']);
436
+
437
+ var_dump($person->getPeoples()); // ['kevin', 'wouter']
438
+
439
+ Instead of call ``add<SingularOfThePropertyName>() `` and ``remove<SingularOfThePropertyName>() ``, the PropertyAccess
440
+ component will call ``join<SingularOfThePropertyName>() `` and ``leave<SingularOfThePropertyName>() `` methods.
441
+
397
442
Checking Property Paths
398
443
-----------------------
399
444
0 commit comments