Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[PropertyAccess] Add a predictable convention for Adders and Removers  #52809

Copy link
Copy link
Open
@janopae

Description

@janopae
Issue body actions

Description

When using adders and removers to modify collections, PropertyAccess currently assumes that property names are English words and tries to apply English grammar transformations to singularise them (see #21569 and #5013). This is super flaky and makes this feature basically unusable in a lot of cases, as it 1. doesn't work for other languages than English (you really don't want to confuse people with English grammar if your applications domain language is something else), and 2. doesn't even work for all English words (see the ever-growing exception list).

Of course, we can't just remove the ever-growing exception list due to BC, but we could at least add another convention on top that works without natural language grammar transformations.

I propose the following one:

Calling PropertyAccessor::setValue for property 'singularWordCollection' should call the methods getSingularWordCollection, addSingularWord and removeSingularWord.

Example

<?php
public class Veroeffentlichung {
    public function __construct(
        private array $kommentare,
    ){}

    public function getKommentarCollection(): array
    {
        return $this->kommentare;
    }

    public function addKommentar(string $kommentar): void
    {
        $this->kommentare[] = $kommentar;
    }

    public function removeKommentar(string $kommentar): void
    {
        array_splice($this->kommentare, array_search($kommentar, $this->kommentare), 1);
    }
}

$propertyAccessor = new \Symfony\Component\PropertyAccess\PropertyAccessor();
$veroeffentlichung = new Veroeffentlichung([]);

$propertyAccessor->setValue($veroeffentlichung, 'kommentarCollection', ['Nice, bro!', 'Amazing post!']);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.