ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
24require_once './Services/WorkflowEngine/classes/class.ilWorkflowEngine.php';
25
59{
63 protected $db;
64
65 protected $listener; // [array]
66
70 protected $logger;
71
75 public function __construct()
76 {
77 global $DIC;
78
79 $this->db = $DIC->database();
80 $this->initListeners();
81
82 $this->logger = \ilLoggerFactory::getLogger('evnt');
83 }
84
85 protected function initListeners()
86 {
87 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
89 $cached_listeners = $ilGlobalCache->get('listeners');
90 if (is_array($cached_listeners)) {
91 $this->listener = $cached_listeners;
92
93 return;
94 }
95
97
98 $this->listener = array();
99
100 $sql = "SELECT * FROM il_event_handling" .
101 " WHERE type = " . $ilDB->quote("listen", "text");
102 $res = $ilDB->query($sql);
103 while ($row = $ilDB->fetchAssoc($res)) {
104 $this->listener[$row["id"]][] = $row["component"];
105 }
106
107 $ilGlobalCache->set('listeners', $this->listener);
108 }
109
110
111
119 public function raise($a_component, $a_event, $a_parameter = "")
120 {
121 $this->logger->debug(sprintf(
122 "Received event '%s' from component '%s'.",
123 $a_event,
124 $a_component
125 ));
126
127 // lazy transforming event data to string
128 $this->logger->debug(new class($a_parameter) {
132 protected $parameter;
133
137 public function __construct($parameter)
138 {
139 $this->parameter = $parameter;
140 }
141
145 public function __toString()
146 {
147 if (is_object($this->parameter)) {
148 return 'Event data class: ' . get_class($this->parameter);
149 }
150
151 return 'Event data size: ' . sizeof($this->parameter);
152 //return 'Event data: ' . print_r($this->parameter, 1);
153 }
154 });
155
156 $this->logger->debug("Started event propagation for event listeners ...");
157
158 if (is_array($this->listener[$a_component])) {
159 foreach ($this->listener[$a_component] as $listener) {
160 // Allow listeners like Services/WebServices/ECS
161 $last_slash = strripos($listener, '/');
162 $comp = substr($listener, 0, $last_slash);
163
164 // any kind of plugins with events in their plugin.xml
165 if ($comp == 'Plugins') {
166 $name = substr($listener, $last_slash + 1);
167
168 foreach (ilPluginAdmin::getActivePlugins() as $pdata) {
169 if ($pdata['name'] == $name) {
171 $pdata['component_type'],
172 $pdata['component_name'],
173 $pdata['slot_id'],
174 $pdata['name']
175 );
176
177 $plugin->handleEvent($a_component, $a_event, $a_parameter);
178 }
179 }
180 } else {
181 $class = 'il' . substr($listener, $last_slash + 1) . 'AppEventListener';
182 $file = "./" . $listener . "/classes/class." . $class . ".php";
183
184 // if file exists, call listener
185 if (is_file($file)) {
186 include_once($file);
187 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
188 }
189 }
190 }
191 }
192
193 $this->logger->debug("Finished event listener handling, started event propagation for event hook plugins ...");
194
195 // get all event hook plugins and forward the event to them
196 include_once("./Services/Component/classes/class.ilPluginAdmin.php");
197 $plugins = ilPluginAdmin::getActivePluginsForSlot("Services", "EventHandling", "evhk");
198 foreach ($plugins as $pl) {
200 "Services",
201 "EventHandling",
202 "evhk",
203 $pl
204 );
205 $plugin->handleEvent($a_component, $a_event, $a_parameter);
206 }
207
208 $this->logger->debug("Finished event hook plugin handling, started event propagation for workflow engine ...");
209
210 $workflow_engine = new ilWorkflowEngine(false);
211 $workflow_engine->handleEvent($a_component, $a_event, $a_parameter);
212
213 $this->logger->debug("Finished workflow engine handling.");
214 }
215}
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.
ilWorkflowEngine is part of the petri net based workflow engine.
$row
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB