php - Observer Pattern Logic Without OOP? -
I was thinking about applying the same logic to the supervisor pattern to apply hooks to my website.
Although the code is very limited, because I can not add several hooks to the same listener.
I do not know about how this can be extended, enables the code to listen to many verbs in an event.
Thanks
You can do as a suggestion of ircmaxell: add hook . But clearly, the information you provided was not enough for you.
If you like to learn from the example, you can see CMS Droup, which is not OOP, but uses the Investigator pattern at all places to allow a modular design.
A hook works as follows:
- There is a piece of php for the existence of a specially named function
- If it exists , Then call it and use its output (or do nothing with it)
For example:
- Just before an article In Drupal, the article system
- calls
- ModuleName_insert will have a function named after which each module will call that function Dahrn: Pirates. The function can be pirate_insert () in the module. The article system creates a roundtrip with all the modules and sees that ModuleName_inert exists. It passes through the pirate module and finds pirate_insert () then it will call that function (as well as pass some arguments). Like, Pirates. Allows modification of the module before entering the module (or changing some body functions to fire some tasks, such as pirate-speck). The magic is called user_backbacks:
$ hook = 'insert' foreach (module_aption ($ hook) as $ modules) {$ Function = $ module.'_ '$ hook; $ Result = call_user_fancy_array ($ function, $ args); }
and the function
module_emplement
might look something like this:$ list = module_list (incorrect, right, $ sort ); // Looks for files which are considered "modules" or "adsense" foreign currency ($ list as $ module) {if (function_exists ($ module.'_ '. $ Hook)) // See that What is the module hook 'registered' $ implementation [$ hook] [] = $ module; // If so: Add it to a list with the task to call}}
Comments
Post a Comment