Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
I'm not sure if hooks is the word for it... However, I noticed with vBulletin and WordPress, they use something that I think is called "hooks" to include code which is added by third party plugins. Correct me if I'm wrong.
The Plugin specifies what section of a certain page they want to add the code to and the hook includes that PHP into that location.
Hiopefully I'm making sense. I did a search for "php hooks" in google but found nothing. Perhaps you can shed some light on the correct name and even tutorials if you have any...
Without seeing the code recently for vB, it would appear to be an implementation of the Observer pattern, which updates on each section of the page, in a flow of the model relaying messages to the observer with such messages as (in paraphased pseudo) "I'm making the header now, any plugins for the header?" and the plugins responding when appropriate, and being included when necessary.
For a quick and dirty example, without class def's (assume that Plugin eval's it content):
As far as I know hooks are used with the template methode pattern (or sometimes easily called Template Pattern). Hooks are called within that template pattern to delegate functionality at certain points in the process chain to subclasses.
Shame that wkipedia has no php example. Atleast I've got something to work with now.
I found the class code for the hook file. I can't share the code due to their copyright but I'll have a look through it and see what I can find out. It reads an xml file to determine all the different areas you can "hook" your code.
A really good book for this kind of thing is "Head First: Design Patterns" by Oreilly Press. Its written for Java, but damn, if you want to learn this kind of stuff go get this book right now.
I second I saw 'hook' I thought of HFDP. I finished reading that book about 2 or 3 months ago and whilst I'm not completely sure about the heads first style, I think my dyslexia responds badly to the exercises, the sheer comprehensiveness and focus on explaining the principles behind the patterns just cannot be bettered. I felt like my potential salary just went up about 7K.
ole wrote:I second I saw 'hook' I thought of HFDP. I finished reading that book about 2 or 3 months ago and whilst I'm not completely sure about the heads first style, I think my dyslexia responds badly to the exercises, the sheer comprehensiveness and focus on explaining the principles behind the patterns just cannot be bettered. I felt like my potential salary just went up about 7K.
You should check out the new head first OO analysis and desing book. It just came out, and I started reading it yesterday. Its also excellent.
You should check out the new head first OO analysis and desing book. It just came out, and I started reading it yesterday. Its also excellent.
ooooooo yes!
* searches *
hmmm must be very new, i can't find it on O'Reilly safari or Amazon but I will definitely look at that when I can track it down.
You should check out the new head first OO analysis and desing book. It just came out, and I started reading it yesterday. Its also excellent.
ooooooo yes!
* searches *
hmmm must be very new, i can't find it on O'Reilly safari or Amazon but I will definitely look at that when I can track it down.