-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add Model.initialize event and rework how Component::initialize() works #4823
Conversation
This event follows the same pattern as Controller.initialize where it is fired *after* the initialize() method and after other subscribers have been attached. The initialize() method is *not* an event subscriber as it is intended to be a post-constructor hook method like Controller::initialize(). This will likely result in Component::initialize() being modified to be conformant. There have been a number of reported issues in the past around Component::initialize() not being called. It would be nice to put those issues to rest and have consistency across the framework.
Make Component::initialize() consistent with Controller and Table, this makes the framework easier to understand as methods with the same name work consistently everywhere. While I'm not totally sure about what to do with the Controller.initialize event hook in components, I feel this change is a good one even though it breaks existing API compatibility. The primary use of this event hook was RequestHandler which has been updated to not rely on the event hook. I've also ensure that Controllers always have a request and response object as that was causing me some grief and logically makes sense.
This method is an event listener that listens to the Controller.initialize event. I decided to copy the controller method name so there was some semblance of consistency. This may be a bad idea though.
👍 for this great consistency feature :) |
By default there are no callbacks listening for |
Great! But I still don't quite get, why do we need two events dispatched one after another in Controller, that is |
@ADmad Correct. |
@robertpustulka Its mostly to afford a component to run code before/after Controller::beforeFilter(). |
👍 Sounds reasonable |
Add Model.initialize event and rework how Component::initialize() works
Docs will need updating :) |
I can update the docs today. |
Component::initialize() has been updated in CakePHP 3 to match other initialize() methods. As per cakephp/cakephp#4823
Component::initialize() has been updated in CakePHP 3 to match other initialize() methods. As per cakephp/cakephp#4823
Component::Initialize has moved to earlier in the bootstrap process in order to match other objects. See cakephp/cakephp#4823
This is a possibly controversial change that solves #4796 and an annoying difference around components vs. everything else.
New Shiny
Model.initialize
event that is fired after the initialize() method, just like in controllers.Breaking changes