8000 [PropertyAccess] Add a predictable convention for Adders and Removers · Issue #52809 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

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

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

Open
janopae opened this issue Nov 29, 2023 · 6 comments
Open

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

janopae opened this issue Nov 29, 2023 · 6 comments

Comments

@janopae
Copy link
janopae commented Nov 29, 2023

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!']);
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@janopae
Copy link
Author
janopae commented Jun 24, 2024

Okay, you asked for it. I don't think comments like this one help anyone.

@carsonbot carsonbot removed the Stalled label Jun 24, 2024
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?
Every feature is developed by the community.
Perhaps someone would like to try?
You can read how to contribute to get started.

@carsonbot
Copy link

Hello? This issue is about to be closed if nobody replies.

@janopae
Copy link
Author
janopae commented Jan 8, 2025

Okay, you asked for it. I don't think comments like this help anyone.

@carsonbot carsonbot removed the Stalled label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0