ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAppEventHandler.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
57{
61 protected $db;
62
63 protected $listener; // [array]
64
68 protected $logger;
69
73 public function __construct()
74 {
75 global $DIC;
76
77 $this->db = $DIC->database();
78 $this->initListeners();
79
80 $this->logger = \ilLoggerFactory::getLogger('evnt');
81 }
82
83 protected function initListeners()
84 {
85 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
87 $cached_listeners = $ilGlobalCache->get('listeners');
88 if (is_array($cached_listeners)) {
89 $this->listener = $cached_listeners;
90
91 return;
92 }
93
95
96 $this->listener = array();
97
98 $sql = "SELECT * FROM il_event_handling" .
99 " WHERE type = " . $ilDB->quote("listen", "text");
100 $res = $ilDB->query($sql);
101 while ($row = $ilDB->fetchAssoc($res)) {
102 $this->listener[$row["id"]][] = $row["component"];
103 }
104
105 $ilGlobalCache->set('listeners', $this->listener);
106 }
107
108
109
117 public function raise($a_component, $a_event, $a_parameter = "")
118 {
119 $this->logger->debug(sprintf(
120 "Received event '%s' from component '%s'.",
121 $a_event,
122 $a_component
123 ));
124
125 // lazy transforming event data to string
126 $this->logger->debug(new class($a_parameter) {
130 protected $parameter;
131
135 public function __construct($parameter)
136 {
137 $this->parameter = $parameter;
138 }
139
143 public function __toString()
144 {
145 if (is_object($this->parameter)) {
146 return 'Event data class: ' . get_class($this->parameter);
147 }
148
149 return 'Event data size: ' . sizeof($this->parameter);
150 //return 'Event data: ' . print_r($this->parameter, 1);
151 }
152 });
153
154 $this->logger->debug("Started event propagation for event listeners ...");
155
156 if (is_array($this->listener[$a_component])) {
157 foreach ($this->listener[$a_component] as $listener) {
158 // Allow listeners like Services/WebServices/ECS
159 $last_slash = strripos($listener, '/');
160 $comp = substr($listener, 0, $last_slash);
161
162 // any kind of plugins with events in their plugin.xml
163 if ($comp == 'Plugins') {
164 $name = substr($listener, $last_slash + 1);
165
166 foreach (ilPluginAdmin::getActivePlugins() as $pdata) {
167 if ($pdata['name'] == $name) {
169 $pdata['component_type'],
170 $pdata['component_name'],
171 $pdata['slot_id'],
172 $pdata['name']
173 );
174
175 $plugin->handleEvent($a_component, $a_event, $a_parameter);
176 }
177 }
178 } else {
179 $class = 'il' . substr($listener, $last_slash + 1) . 'AppEventListener';
180 $file = "./" . $listener . "/classes/class." . $class . ".php";
181
182 // if file exists, call listener
183 if (is_file($file)) {
184 include_once($file);
185 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
186 }
187 }
188 }
189 }
190
191 $this->logger->debug("Finished event listener handling, started event propagation for event hook plugins ...");
192
193 // get all event hook plugins and forward the event to them
194 include_once("./Services/Component/classes/class.ilPluginAdmin.php");
195 $plugins = ilPluginAdmin::getActivePluginsForSlot("Services", "EventHandling", "evhk");
196 foreach ($plugins as $pl) {
198 "Services",
199 "EventHandling",
200 "evhk",
201 $pl
202 );
203 $plugin->handleEvent($a_component, $a_event, $a_parameter);
204 }
205
206 $this->logger->debug("Finished event hook plugin handling, started event propagation for workflow engine ...");
207 }
208}
An exception for terminatinating execution or to throw for unit testing.
Global event handler.
static getInstance($component)
static getLogger($a_component_id)
Get component logger.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
static getActivePlugins()
Get info for all active plugins.
global $DIC
Definition: goto.php:24
if($format !==null) $name
Definition: metadata.php:230
foreach($_POST as $key=> $value) $res
global $ilDB