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
Change Controller::__construct() to accept an array as its argument #7312
Conversation
*/ | ||
public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null, $components = null) | ||
public function __construct($options = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a bunch of code and makes type-hinting harder, what is the benefit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't exactly remember where I say see this: Future Proof APIs, Options parameters make growing easy.
:)
50a95bc
to
1814ada
Compare
I'm 👎 on this. It makes harder to work with reflection. |
Given that the developer almost never needs to instantiate controller "by hand" I too don't see the benefit of accepting args as array. |
On the fence here, I think that if we had a compelling reason to do this in the future we could just do it. So far I don't see a big benefit, on the other hand it will break my dependency injection plugin as no typehints will be found :( |
The bag of stuff parameter works ok when we have a servicelocator/factory like TableRegistry. But we don't have one of those for controllers. |
It feels ugly. Especially the Pity php has no named params. :( |
Named params would make everything so much better :D |
Indeed. |
Closing :( |
A class should never have too many dependencies. 3-4 are OK, 5 are max. If you need more then your class is badly designed. I don't see why we should make such future-proof changes. If the need emerges, we'll find another, more elegant way to deal with many dependencies. |
#7301 (comment)