mirror of
https://github.com/slawkens/myaac.git
synced 2025-11-30 15:06:50 +01:00
Refactoring classes into src/ folder, so they will be auto-loaded by composer
This commit is contained in:
44
system/src/Hooks.php
Normal file
44
system/src/Hooks.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC;
|
||||
|
||||
class Hooks
|
||||
{
|
||||
private static $_hooks = array();
|
||||
|
||||
public function register($hook, $type = '', $file = null) {
|
||||
if(!($hook instanceof Hook))
|
||||
$hook = new Hook($hook, $type, $file);
|
||||
|
||||
self::$_hooks[$hook->type()][] = $hook;
|
||||
}
|
||||
|
||||
public function trigger($type, $params = array())
|
||||
{
|
||||
$ret = true;
|
||||
if(isset(self::$_hooks[$type]))
|
||||
{
|
||||
foreach(self::$_hooks[$type] as $name => $hook) {
|
||||
/** @var $hook Hook */
|
||||
if (!$hook->execute($params)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function exist($type) {
|
||||
return isset(self::$_hooks[$type]);
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
foreach(Plugins::getHooks() as $hook) {
|
||||
$this->register($hook['name'], $hook['type'], $hook['file']);
|
||||
}
|
||||
|
||||
Plugins::clearWarnings();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user