Skip to content
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: Model.initialize event (originally: Apply Events to TableRegistry) #4796

Closed
robertpustulka opened this issue Oct 2, 2014 · 24 comments
Closed
Assignees
Milestone

Comments

@robertpustulka
Copy link
Member

I was wondering if there could be some way of observing Table creation process.
ie: after every new Table object TR could dispatch an event (using global EventManager) allowing an app or a plugin to hook into this Table and do some stuff with it. This could be helpful if we wanted to apply some changes to every table in registry upon their creation.

I'm not sure it feels right, so I open this for discussion for now.

@lorenzo
Copy link
Member

lorenzo commented Oct 2, 2014

What kind of changers would you apply?

@robertpustulka
Copy link
Member Author

For example I'd like to load some behaviors to every table in my app.

@ADmad
Copy link
Member

ADmad commented Oct 2, 2014

You can make an AppTable and have all tables extend it. Then do whatever initializations you like in AppTable::initialize().

@ADmad ADmad added this to the 3.0.0 milestone Oct 2, 2014
@robertpustulka
Copy link
Member Author

@ADmad , I can't do that with plugin tables. Or do that from a plugin scope.

@ADmad
Copy link
Member

ADmad commented Oct 2, 2014

I guess we should just make AppTable a requirement like AppController.

@robertpustulka
Copy link
Member Author

But that's not the point. The point is to have some control over table creation. TableRegistry is static and it's really hard to hook into it.

Besides having an AppTable wouldn't help to attach behaviors from plugin scope.

@lorenzo
Copy link
Member

lorenzo commented Oct 2, 2014

I guess we could have an initialize event like controllers do

@markstory
Copy link
Member

This doesn't seem unreasonable to me. What would you call the event?

@lorenzo
Copy link
Member

lorenzo commented Oct 2, 2014

Table.initialize or just Model.initialize to make it similar to the rest

@robertpustulka
Copy link
Member Author

Model.initialize sounds good.

If I'm not mistaken this event could be dispatched by Table itself and could be easely "fetched" by an EventManager singleton?

@markstory
Copy link
Member

Firing the event from the table is far more palatable than from the registry. In that case I would go with 'Model.initialize'.

@robertpustulka
Copy link
Member Author

So what about Table::initialize()? Now it feels like that this should be run by EventManager as another callback... But it also would force every developer to update their initialize(array $config) to initialize(Event $event, array $config)

@robertpustulka robertpustulka changed the title 3.0: Apply Events to TableRegistry 3.0: Model.initialize Event (originally: Apply Events to TableRegistry) Oct 3, 2014
@robertpustulka robertpustulka changed the title 3.0: Model.initialize Event (originally: Apply Events to TableRegistry) 3.0: Model.initialize event (originally: Apply Events to TableRegistry) Oct 3, 2014
@lorenzo
Copy link
Member

lorenzo commented Oct 3, 2014

No, the method should stay the same. And the event should be called after that method

@ADmad
Copy link
Member

ADmad commented Oct 3, 2014

@lorenzo That would make Table::initialize() the only callback method which doesn't have Event instance as first param. I would rather cause inconvenience to existing early adopters than have all future users deal with this inconsistency.

@robertpustulka
Copy link
Member Author

@ADmad - this is my point.
I also think this should be dealt with sooner than later. Having all callbacks triggered the same way for clarity. BTW isn't initialize() in its current form a callback which resembles pre 2.1 callbacks :)?

@markstory
Copy link
Member

Not the only method. The Controller::initialize() method works the same. I see those initialize() methods as simpler ways too add constructor logic.

@ADmad
Copy link
Member

ADmad commented Oct 3, 2014

But Controller::initialize() isn't used as an event callback. All callbacks methods that take event instance as an argument should take it as 1st param for consistency imho.

@robertpustulka
Copy link
Member Author

But we have Controller.initialize event... which is mapped to Controller::beforeFilter().
And in Component we have initialize() which is a callback for actual Controller.initialize event...

Isn't that a bit messy?

@ADmad
Copy link
Member

ADmad commented Oct 3, 2014

@robertpustulka Yeah, Controller::initialize() was added very recently. May be should have named it init() to avoid confusion with the Controller::initialize event name.

@markstory
Copy link
Member

If anything is messy it is the component method. I think the initialize() as a constructor hook is a nicer pattern to follow than the event based one. Perhaps we should make the component method follow the controller workflow, and not have a Controller.initialze event listener on Component by default?

@ADmad
Copy link
Member

ADmad commented Oct 3, 2014

@markstory That sounds reasonable.

@robertpustulka
Copy link
Member Author

But it still leaves Controller.initialize event mapped to beforeFilter(), which does not follow this event-method naming convention.
Maybe we could just leave Controller.startup (and map it to beforeFilter()), as these two events are fired one after another.

@markstory
Copy link
Member

The beforeFilter method must be called before the startup event, or many workflows around component setup will no longer work.

@markstory markstory self-assigned this Oct 6, 2014
@markstory
Copy link
Member

Closing, as there is a pull request up now that we can discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants