@@ -406,20 +406,21 @@ Using non-standard adder/remover methods
406406Sometimes, adder and remover methods don't use the standard ``add `` or ``remove `` prefix, like in this example::
407407
408408 // ...
409- class PeopleList
409+ class Team
410410 {
411411 // ...
412412
413- public function joinPeople (string $people ): void
413+ public function joinTeam (string $person ): void
414414 {
415- $this->peoples [] = $people ;
415+ $this->team [] = $person ;
416416 }
417417
418- public function leavePeople (string $people ): void
418+ public function leaveTeam (string $person ): void
419419 {
420- foreach ($this->peoples as $id => $item) {
421- if ($people === $item) {
422- unset($this->peoples[$id]);
420+ foreach ($this->team as $id => $item) {
421+ if ($person === $item) {
422+ unset($this->team[$id]);
423+
423424 break;
424425 }
425426 }
@@ -429,12 +430,12 @@ Sometimes, adder and remover methods don't use the standard ``add`` or ``remove`
429430 use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
430431 use Symfony\Component\PropertyAccess\PropertyAccessor;
431432
432- $list = new PeopleList ();
433+ $list = new Team ();
433434 $reflectionExtractor = new ReflectionExtractor(null, null, ['join', 'leave']);
434435 $propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH, null, $reflectionExtractor, $reflectionExtractor);
435- $propertyAccessor->setValue($person, 'peoples ', ['kevin', 'wouter']);
436+ $propertyAccessor->setValue($person, 'team ', ['kevin', 'wouter']);
436437
437- var_dump($person->getPeoples ()); // ['kevin', 'wouter']
438+ var_dump($person->getTeam ()); // ['kevin', 'wouter']
438439
439440Instead of calling ``add<SingularOfThePropertyName>() `` and ``remove<SingularOfThePropertyName>() ``, the PropertyAccess
440441component will call ``join<SingularOfThePropertyName>() `` and ``leave<SingularOfThePropertyName>() `` methods.
0 commit comments