@@ -406,20 +406,21 @@ Using non-standard adder/remover methods
406
406
Sometimes, adder and remover methods don't use the standard ``add `` or ``remove `` prefix, like in this example::
407
407
408
408
// ...
409
- class PeopleList
409
+ class Team
410
410
{
411
411
// ...
412
412
413
- public function joinPeople (string $people ): void
413
+ public function joinTeam (string $person ): void
414
414
{
415
- $this->peoples [] = $people ;
415
+ $this->team [] = $person ;
416
416
}
417
417
418
- public function leavePeople (string $people ): void
418
+ public function leaveTeam (string $person ): void
419
419
{
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
+
423
424
break;
424
425
}
425
426
}
@@ -429,12 +430,12 @@ Sometimes, adder and remover methods don't use the standard ``add`` or ``remove`
429
430
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
430
431
use Symfony\Component\PropertyAccess\PropertyAccessor;
431
432
432
- $list = new PeopleList ();
433
+ $list = new Team ();
433
434
$reflectionExtractor = new ReflectionExtractor(null, null, ['join', 'leave']);
434
435
$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']);
436
437
437
- var_dump($person->getPeoples ()); // ['kevin', 'wouter']
438
+ var_dump($person->getTeam ()); // ['kevin', 'wouter']
438
439
439
440
Instead of calling ``add<SingularOfThePropertyName>() `` and ``remove<SingularOfThePropertyName>() ``, the PropertyAccess
440
441
component will call ``join<SingularOfThePropertyName>() `` and ``leave<SingularOfThePropertyName>() `` methods.
0 commit comments