59 static $instance =
false;
62 $instance = new \Xoops\Core\Events();
80 $this->eventsEnabled =
false;
83 $this->eventsEnabled =
true;
94 $key =
'system/modules/preloads';
95 if (!$this->preloadList = $cache->read($key)) {
98 if (empty($modules_list)) {
100 $modules_list = array (
'system');
102 $this->preloadList =array();
104 foreach ($modules_list as
$module) {
106 $file_list = \XoopsLists::getFileListAsArray(
$dir);
107 foreach ($file_list as
$file) {
108 if (preg_match(
'/(\.php)$/i', $file)) {
109 $file = substr($file, 0, -4);
110 $this->preloadList[
$i][
'module'] =
$module;
111 $this->preloadList[
$i][
'file'] =
$file;
117 $cache->write($key, $this->preloadList);
147 foreach ($this->preloadList as $preload) {
148 include_once \XoopsBaseConfig::get(
'root-path') .
'/modules/' . $preload[
'module'] .
'/preloads/' . $preload[
'file'].
'.php';
149 $class_name = ucfirst($preload[
'module'])
150 . ($preload[
'file'] ==
'preload' ?
'' : ucfirst($preload[
'file']) )
152 if (!class_exists($class_name)) {
155 $class_methods = get_class_methods($class_name);
156 foreach ($class_methods as $method) {
157 if (strpos($method,
'event') === 0) {
158 $eventName = strtolower(str_replace(
'event',
'', $method));
159 $event = array($class_name, $method);
160 $this->eventListeners[$eventName][] = $event;
176 if ($this->eventsEnabled) {
178 if (isset($this->eventListeners[$eventName])) {
179 foreach ($this->eventListeners[$eventName] as $event) {
180 if (is_callable($event)) {
181 call_user_func($event, $args);
198 return strtolower(str_replace(
'.',
'', $eventName));
212 $this->eventListeners[$eventName][]=$callback;
234 return array_key_exists($eventName, $this->eventListeners);
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
addListener($eventName, $callback)
toInternalEventName($eventName)
triggerEvent($eventName, $args=array())