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
[3.0] [DependencyInjection] Remove the *.class parameters from core #11881
Comments
I like this. When dealing with large projects with many classes/services it becomes tedious and never really used this "feature". |
I love this proposal. Any given Symfony app has more than 300 |
By the way, I'm not even sure that this is a documented "feature" ;) |
👍 as well. Btw, I suggest we update the documentation ASAP to stop showing this kind of definition in the samples (IIRC, we have a few places showing it), or at least adding a note explaining it is discouraged |
IIRC, we even explicitly document that for any bundle exposing a semantic configuration, messing with the parameters defined by the bundle is an unsupported extension point |
👍 |
👍 less magic, more speed for Symfony 3 🚤 |
👍 But this is currently documented in the conventions for service and parameter names, let's change that :) |
👍 |
👍 Although it has never been best practice to override those *.class parameters for framework services, I've seen people doing that. I like the idea of removing those parameters, but there should be a good documentation pointing out a migration path away from this practice. |
👍 But I have another approach. Keep everything like it's done now, but we could add a compiler pass to remove all
I disagree with that, I override some some part of symfony / monolog to tweak 2/3 things. I did that on private projects... |
👍 For removal |
@lyrixx I'm also using this for some classes. But you can using services decoration for this. |
👍 I never found these params to be a good design. |
👍 I've always wondered why this was done and people recommended doing this for open-source packages without being able to specify why. This will however, break a lot of things. It might be an idea to explain service decoration more thoroughly in the documentation. There's 1 page I could find about it in the docs which doesn't even explain how to build your service (php class) if you want to do some decorating: http://symfony.com/doc/current/components/dependency_injection/advanced.html |
👍 |
👎 Agree with @lyrixx. If the problem is that the Container definition becomes too big, okay, they could be removed using a simple compiler pass (Like unused private services). There is a point you should take in account when planning Symfony3. Big BC Breaks are very tedious to be migrated, and big migrations are a bad idea for any technology. If you remove all |
If decided to not implement this change, a compiler pass could optimize the container by removing unused parameters ending with Enforcing better development options can make the code a lot better on the long term. A service decorator is a far more elegant solution than replacing the arguments. |
We can also do this in the 2.x serie and include a compiler pass which changes the class of a service definition when a parameter with |
@wouterj No, you cannot. What about someone using the parameter outside the DIC (something like |
You could make it configurable, off by default. If someone is using those parameters run-time, they are doing funky stuff either way. It doesn't justify a BC break, but it should not be considered a common use-case in my opinion.
|
@fabpot the advantage of being able to mark parameters as private (same meaning than with private services) would be that we could remove much more parameters from the runtime container than only the .class ones. Lots of parameters are used only in service definitions. |
👍 |
I totally agree with @stof but I propose a "better" solution: I prefer to introduce private parameter in symfony 2.6. All Then, IIRC (and @stof noticed that too), symfony itself uses parameters to configure some services from a compiler pass, and they not always remove theses param. I (we?) do the same thing in ours projects. I can work on this feature, it seems quite easy. |
Introducing private parameters without removing them from the DIC makes them useless. It would mean that private parameters are the same than public ones |
This PR was squashed before being merged into the 3.x-dev branch (closes #170). Discussion ---------- remove class parameters The idea was initially discussed in symfony/symfony/issues/11881. If I understand things correctly, we should provide a service for each removed parameter to allow bundle users to decorate or override corresponding services. But I'm not sure if services should be listed in DI config of bundle, or it is OK to add them during DI Extension load. I'm using those services to map handler type to handler class (this is done [here](https://github.com/avant1/monolog-bundle/blob/remove-class-parameters/DependencyInjection/MonologExtension.php#L133-L134)). But those handler services can be replaced by hash mapping. If anything else related to this changes should be done (like updating README or adding note to symfony logging cookbook) - I'm ready to work on this too. Commits ------- 6398efc remove class parameters
For details see symfony/symfony#11881
Bad practice and error prone: also see symfony/symfony#11881 and symfony/symfony#9003
Bad practice and error prone: also see symfony/symfony#11881 and symfony/symfony#9003
All services in core define their classes as parameters. The convention is to create a
foo.class
parameter for the class of thefoo
service. This approach comes with several problems:For all these reasons, I like to remove all those parameters for Symfony 3.0.
On a side note, it's now possible to easily replace a service by decorating it (see #9003).
The text was updated successfully, but these errors were encountered: