J
J
jacksparrow2013-12-28 22:25:07
CMS
jacksparrow, 2013-12-28 22:25:07

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

3 answer(s)
A
Alexander Wolf, 2013-12-29
@mannaro

Try something like this:

$modules = array();
  
  function addToModule($module, $func) {
    $modules[$module][] = $func;
  }
  function getModule($module, $arguments) {
    foreach($modules[$module] as $func) $func($arguments);
  }

Add modules like this:
function one ($arguments) { include 'test.html'; }
addToModule('test', 'one');
function two ($arguments) { echo $arguments[1]->greating; }
addToModule('test', 'two');

And in the right place on the page, do this:
getModule('test', array($var1, $var2, $var3));

N
Nazar Mokrinsky, 2013-12-29
@nazarpc

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.phpand 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 useyou can use it to pass the necessary data there from the place of declaration.

A
Alexander Wolf, 2013-12-29
@mannaro

Can you write at least what kind of CMS you have?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question