Skip to content

[DependencyInjection] Allow calling custom processors directly on EnvConfigurator #40779

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
Apr 13, 2021

Conversation

jvasseur
Copy link
Contributor

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR

This is a proposition of addition to the feature added by #40682 to allow calling custom processors in the same way we call builtin ones. This is not perfect since it doesn't allow auto-completion for these custom methods but I think this provides a cleaner API for custom processors.

Add magic __call method to EnvConfigurator to allow calling custom
processors as methods instead of using the custom method.
@jvasseur jvasseur changed the title Allow calling custom processors directly on EnvConfigurator [DependencyInjection] Allow calling custom processors directly on EnvConfigurator Apr 12, 2021
*/
public function __call(string $name, array $arguments): self
{
$processor = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $name));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a dependency on the string component instead here but not sure if it is worth it.

@nicolas-grekas nicolas-grekas added this to the 5.x milestone Apr 12, 2021
{
$processor = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $name));

$this->custom($processor, ...$arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove custom() instead, don't you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use custom over magic methods.

@carsonbot carsonbot changed the title [DependencyInjection] Allow calling custom processors directly on EnvConfigurator Allow calling custom processors directly on EnvConfigurator Apr 12, 2021
@carsonbot carsonbot changed the title Allow calling custom processors directly on EnvConfigurator [DependencyInjection] Allow calling custom processors directly on EnvConfigurator Apr 13, 2021
@nicolas-grekas
Copy link
Member

Thank you @jvasseur.

@nicolas-grekas nicolas-grekas merged commit 0a32a7d into symfony:5.x Apr 13, 2021
@jvasseur jvasseur deleted the env-configurator-call branch April 13, 2021 08:00
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.

4 participants