Skip to content

Fix wording at property_access.rst #19092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,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 @@ -429,12 +430,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