Skip to content
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

[LiveComponent] Fix methods visibility #2511

Open
jakubtobiasz opened this issue Jan 19, 2025 · 2 comments
Open

[LiveComponent] Fix methods visibility #2511

jakubtobiasz opened this issue Jan 19, 2025 · 2 comments

Comments

@jakubtobiasz
Copy link
Contributor

Hello,

Considering the ComponentWithFormTrait we can notice there are few private methods. In general, it's not messing anything up, but when we deal with projects like Sylius, it becomes problematic.

  1. We have a FormComponent class using ComponentWithFormTrait.
  2. We want to override some behavior or FormComponent by extending it. Let's call it a BetterFormComponent.
  3. We need to add use ComponentWithFormTrait inside the BetterFormComponent as they're private (we cannot access them nor use e.g. formValues.

And yes, it can be easily done by a use statement; however (real case), I had an overridden trait's method in the parent class, and I couldn't find why my component is misbehaving compared to the original one :P.

So my suggestion is to mark all private methods in this trait as protected. It seems it wouldn't come with any side effects.

@Kocal
Copy link
Member

Kocal commented Jan 19, 2025

Hey,

And yes, it can be easily done by a use statement; however (real case), I had an overridden trait's method in the parent class, and I couldn't find why my component is misbehaving compared to the original one :P.

I'm not 100% sure to understand, but the following code won't work as you want?

class FormComponent {
    use ComponentWithFormTrait { thePrivateMethod as protected; }
}
class BetterFormComponent extends FormComponent {
    // ...
}

@Kocal Kocal changed the title [Live Component] Fix methods visibility [LiveComponent] Fix methods visibility Jan 19, 2025
@smnandre
Copy link
Member

Hmm... as much as I understand your situation, this is exactly what private properties / methods ... protect us from.

Let me explain :)

Due to the Symfony BC promise, as long methods are private, we can do things (not all, but still have some freedom to recode things and / or improves them..)

But anything protected cannot be touched anymore in interface / behaviour / signature / etc.... for many years.

And this is not something we should risk.
... and not something we can do without opening BC for existing users :)

Symfony BC Promise detailed here: https://symfony.com/doc/current/contributing/code/bc.html

Maybe here we could imagine some new contract / interface ?

I'm the first one to dream about a lot of opening / extension points / composition in components, but we're really not enough for the moment :l

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