Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  Fix wording at `property_access.rst`
  • Loading branch information
OskarStark committed Oct 28, 2023
2 parents 00d50e5 + 6ad9a5a commit c99dd22
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,21 @@ Using non-standard adder/remover methods
Sometimes, adder and remover methods don't use the standard ``add`` or ``remove`` prefix, like in this example::

// ...
class PeopleList
class Team
{
// ...

public function joinPeople(string $people): void
public function joinTeam(string $person): void
{
$this->peoples[] = $people;
$this->team[] = $person;
}

public function leavePeople(string $people): void
public function leaveTeam(string $person): void
{
foreach ($this->peoples as $id => $item) {
if ($people === $item) {
unset($this->peoples[$id]);
foreach ($this->team as $id => $item) {
if ($person === $item) {
unset($this->team[$id]);

break;
}
}
Expand All @@ -482,12 +483,12 @@ Sometimes, adder and remover methods don't use the standard ``add`` or ``remove`
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyAccess\PropertyAccessor;

$list = new PeopleList();
$list = new Team();
$reflectionExtractor = new ReflectionExtractor(null, null, ['join', 'leave']);
$propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH, null, $reflectionExtractor, $reflectionExtractor);
$propertyAccessor->setValue($person, 'peoples', ['kevin', 'wouter']);
$propertyAccessor->setValue($person, 'team', ['kevin', 'wouter']);

var_dump($person->getPeoples()); // ['kevin', 'wouter']
var_dump($person->getTeam()); // ['kevin', 'wouter']

Instead of calling ``add<SingularOfThePropertyName>()`` and ``remove<SingularOfThePropertyName>()``, the PropertyAccess
component will call ``join<SingularOfThePropertyName>()`` and ``leave<SingularOfThePropertyName>()`` methods.
Expand Down

0 comments on commit c99dd22

Please sign in to comment.