Answer the question
In order to leave comments, you need to log in
How to set up a hook system for your site?
At the moment, it is necessary to tie a system of hooks to a self-written site for some modules to work. I did not find a clean description of the system outside cms. Tell me how to properly implement this technology for connecting modules.
Answer the question
In order to leave comments, you need to log in
Try something like this:
$modules = array();
function addToModule($module, $func) {
$modules[$module][] = $func;
}
function getModule($module, $arguments) {
foreach($modules[$module] as $func) $func($arguments);
}
function one ($arguments) { include 'test.html'; }
addToModule('test', 'one');
function two ($arguments) { echo $arguments[1]->greating; }
addToModule('test', 'two');
getModule('test', array($var1, $var2, $var3));
You can take my code:
https://github.com/nazar-pc/CleverStyle-CMS/blob/m...
It is very easy to transfer it to your project by taking the trait from core/traits/Singleton.php
and modifying the code in the method ::run()
, it scans everything on the first run places where hooks can lie (in the terminology of my engine they are event triggers), if you do not need file scanning, you can delete that section altogether.
When registering a trigger, a closure is passed, so that use
you can use it to pass the necessary data there from the place of declaration.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question