Hook suggestion

Hello. I am thinking of re-doing my MVC web application and I was thinking of deploying a hook system. I would like to know what is the best way of going about it.

I was thinking that I should connect to the database first. Pull all hook plugin names, find their directory and call the class before I actually call the core file.

Does that sound right?

What do you need the hooks for? If you programmed an object oriented MVC system, you only extend the system.

Scott

Event driven systems are typically more flexible and avoid collisions with other peoples code. Using inheritance to override core functionality can become a problem as a the number of extensions/modules increases. To that end you should use an event system rather hooks. Even Drupal is moving toward completely replacing hooks with events for 9. Many aspects of it already use events over the antiquated hook system.

The hook system was suppose to be there because I feel like the MVC extends is going to be hard for the noobies. If I make a hook system along with a documentation, it would just be easier for the noobies. If I did a documentation with the MVC extends class. It’s going to confuse the user because I don’t think they will understand what every single function does. If it was just hooks, it’ll just be arrays. So it would be easier for a noobie to work with arrays instead of classes. I also feel like in the later updates, if people had their own hooks/plugins, it’ll be easier to update the source codes so I don’t screw up what they have already customized.

I’m not sure if this was directed towards me or towards Scott, but I agree with the first sentence. It is easier to allow hooks so that when someone does indeed change the source code, they would only need to change the source code of their hook/plugin. The actual core files wouldn’t need to be updated at all unless a huge major source code change was done.

@oddz - thanks for the info. Just reading up on event driven architecture and a number of the articles or questions end up pointing to Symfony’s event dispatcher component, which is one of the few components I had yet to dig into myself. I like this paragraph.

Consider the real-world example where you want to provide a plugin system for your project. A plugin should be able to add methods, or do something before or after a method is executed, without interfering with other plugins. This is not an easy problem to solve with single and multiple inheritance (were it possible with PHP) has its own drawbacks.

So, sounds good. Events solve a good number of the problems for a plug-in system.

Then I ran into someone mentioning AOP as a possible solution (which I had never thought of either). What do you think about AOP and AOSD for a plug-in system?

Scott

What’s the difference between hooks and events?

http://programmers.stackexchange.com/questions/237876/what-should-plugins-use-hooks-events-or-something-else

Scott

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.