@@ -459,20 +459,21 @@ Using non-standard adder/remover methods
459
459
Sometimes, adder and remover methods don't use the standard ``add `` or ``remove `` prefix, like in this example::
460
460
461
461
// ...
462
- class PeopleList
462
+ class Team
463
463
{
464
464
// ...
465
465
466
- public function joinPeople (string $people ): void
466
+ public function joinTeam (string $person ): void
467
467
{
468
- $this->peoples [] = $people ;
468
+ $this->team [] = $person ;
469
469
}
470
470
471
- public function leavePeople (string $people ): void
471
+ public function leaveTeam (string $person ): void
472
472
{
473
- foreach ($this->peoples as $id => $item) {
474
- if ($people === $item) {
475
- unset($this->peoples[$id]);
473
+ foreach ($this->team as $id => $item) {
474
+ if ($person === $item) {
475
+ unset($this->team[$id]);
476
+
476
477
break;
477
478
}
478
479
}
@@ -482,12 +483,12 @@ Sometimes, adder and remover methods don't use the standard ``add`` or ``remove`
482
483
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
483
484
use Symfony\Component\PropertyAccess\PropertyAccessor;
484
485
485
- $list = new PeopleList ();
486
+ $list = new Team ();
486
487
$reflectionExtractor = new ReflectionExtractor(null, null, ['join', 'leave']);
487
488
$propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH, null, $reflectionExtractor, $reflectionExtractor);
488
- $propertyAccessor->setValue($person, 'peoples ', ['kevin', 'wouter']);
489
+ $propertyAccessor->setValue($person, 'team ', ['kevin', 'wouter']);
489
490
490
- var_dump($person->getPeoples ()); // ['kevin', 'wouter']
491
+ var_dump($person->getTeam ()); // ['kevin', 'wouter']
491
492
492
493
Instead of calling ``add<SingularOfThePropertyName>() `` and ``remove<SingularOfThePropertyName>() ``, the PropertyAccess
493
494
component will call ``join<SingularOfThePropertyName>() `` and ``leave<SingularOfThePropertyName>() `` methods.
0 commit comments