Skip to content

[Console] Allow dynamic properties in ProgressBar #47898

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

Closed

Conversation

ostrolucky
Copy link
Contributor

Q A
Branch? 6.2
Bug fix? no
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

I rely on dynamic props in ProgressBar in https://github.com/ostrolucky/stdinho/blob/43c89658ae9d991f0daf7978d5d2877c2816cc68/src/ProgressBar.php#L32. However that will stop working starting PHP 8.2 unless this attribute is added. I see this attribute quite necessary here unless component is refactored, because of combination of static functions and final keyword usage.

Before this workaround, there was an issue #31193 that I closed because I've solved it by using dynamic properties.

I'm also open to move this to lower branch. The way I see it, this can go as low as Symfony 4.4, as it's perfectly safe patch.

@chalasr
Copy link
Member

chalasr commented Oct 18, 2022

I think this cannot be a durable solution. But I'm ok with merging this in lower branches (as the use case at hand seems legit) only if we find a proper solution for the dev branch that doesn't imply dynamic properties.

@ostrolucky
Copy link
Contributor Author

ostrolucky commented Oct 20, 2022

Fine with merging it only to 6.2 if your condition to merge it lower would be refactoring of a whole thing; that would be a lot of work.

@wouterj
Copy link
Member

wouterj commented Oct 20, 2022

Would removing final from ProgressBar fix your use-case without this attribute?

@ostrolucky
Copy link
Contributor Author

yes definitely

@GromNaN
Copy link
Member

GromNaN commented Nov 11, 2022

You can remove usage of dynamic properties by resolving the values before setting the format, and update the format string when the state changes. Here is a suggested solution: ostrolucky/stdinho#5

@ostrolucky
Copy link
Contributor Author

Indeed, so there is a different way to do this, thanks @GromNaN! So me personally I don't need this change anymore, we can close.

@ostrolucky ostrolucky closed this Nov 12, 2022
fabpot added a commit that referenced this pull request Dec 9, 2022
…nstance (GromNaN)

This PR was merged into the 6.3 branch.

Discussion
----------

[Console] Add placeholder formatters per ProgressBar instance

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #34929 #47898
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

The `ProgressBar` class abuse of static properties to define formats and callables for placeholders. While it is possible to set the format pattern directly without using the statically defined formats, the placeholder formatters have to be defined globally which add limitations and produce unintended side effects.

Example on this command class: https://github.com/ostrolucky/stdinho/blob/76a54db4ff379fe428acc12cbe66d319a289eb3b/src/ProgressBar.php

Commits
-------

c5fdfbc Add placeholder formatters per ProgressBar instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants