ILIAS  release_8 Revision v8.24
ilAppEventHandler Class Reference

Global event handler. More...

+ Collaboration diagram for ilAppEventHandler:

Public Member Functions

 __construct ()
 
 raise (string $a_component, string $a_event, array $a_parameter=[])
 Raise an event. More...
 

Protected Member Functions

 initListeners ()
 

Protected Attributes

ilDBInterface $db
 
array $listener
 
ilLogger $logger
 
ilComponentRepository $component_repository
 
ilComponentFactory $component_factory
 

Detailed Description

Global event handler.

The event handler delegates application events (not gui events) between components that trigger events and components that listen to events. A component is a module or a service.

The component that triggers an event calls the raise function of the event handler through the global instance ilAppEventHandler:

E.g. in ilObjUser->delete(): $ilAppEventHandler->raise("Services/User", "deleteUser", array("id" => ..., ...))

A listener has to subscribe to the events of another component. This currently is done here in the constructor, e.g. if the News service listens to the User service, add a $this->listener["Services/User"] = array("Services/News"); This information will go to xml files in the future.

A component has to implement a listener class that implements Services/EventHandling/interfaces/interface.ilAppEventListener.php

The location must be <component>/classes/class.il<comp_name>AppEventListener.php, e.g. ./Services/News/classes/class.ilNewsAppEventListener.php

The class name must be il<comp_name>AppEventListener.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 51 of file class.ilAppEventHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilAppEventHandler::__construct ( )

Definition at line 59 of file class.ilAppEventHandler.php.

60 {
61 global $DIC;
62
63 $this->db = $DIC->database();
64 $this->component_repository = $DIC["component.repository"];
65 $this->component_factory = $DIC["component.factory"];
66 $this->initListeners();
67
68 $this->logger = \ilLoggerFactory::getLogger('evnt');
69 }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28

References $DIC, ilLoggerFactory\getLogger(), initListeners(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ initListeners()

ilAppEventHandler::initListeners ( )
protected

Definition at line 71 of file class.ilAppEventHandler.php.

71 : void
72 {
74 $cached_listeners = $ilGlobalCache->get('listeners');
75 if (is_array($cached_listeners)) {
76 $this->listener = $cached_listeners;
77
78 return;
79 }
80
82
83 $this->listener = array();
84
85 $sql = "SELECT * FROM il_event_handling" .
86 " WHERE type = " . $ilDB->quote("listen", "text");
87 $res = $ilDB->query($sql);
88 while ($row = $ilDB->fetchAssoc($res)) {
89 $this->listener[$row["id"]][] = $row["component"];
90 }
91
92 $ilGlobalCache->set('listeners', $this->listener);
93 }
static getInstance(?string $component)
$res
Definition: ltiservices.php:69

References $db, $ilDB, $res, ilGlobalCache\COMP_EVENTS, and ilGlobalCache\getInstance().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raise()

ilAppEventHandler::raise ( string  $a_component,
string  $a_event,
array  $a_parameter = [] 
)

Raise an event.

The event is passed to all interested listeners.

Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

Definition at line 102 of file class.ilAppEventHandler.php.

106 : void {
107 $this->logger->debug(sprintf(
108 "Received event '%s' from component '%s'.",
109 $a_event,
110 $a_component
111 ));
112
113 $parameter_formatter = static function ($value) use (&$parameter_formatter) {
114 if (is_object($value)) {
115 return get_class($value);
116 }
117
118 if (is_array($value)) {
119 return array_map(
120 $parameter_formatter,
121 $value
122 );
123 }
124
125 return $value;
126 };
127
128 $this->logger->debug('Event data: ' . var_export(array_map(
129 $parameter_formatter,
130 $a_parameter
131 ), true));
132
133 $this->logger->debug("Started event propagation for event listeners ...");
134
135 if (is_array($this->listener[$a_component] ?? null)) {
136 foreach ($this->listener[$a_component] as $listener) {
137 // Allow listeners like Services/WebServices/ECS
138 $last_slash = strripos($listener, '/');
139 $comp = substr($listener, 0, $last_slash);
140
141 // any kind of plugins with events in their plugin.xml
142 if ($comp == 'Plugins') {
143 $name = substr($listener, $last_slash + 1);
144
145
146 foreach ($this->component_repository->getPlugins() as $pl) {
147 if ($pl->getName() !== $name || !$pl->isActive()) {
148 continue;
149 }
150 $plugin = $this->component_factory->getPlugin($pl->getId());
151 $plugin->handleEvent($a_component, $a_event, $a_parameter);
152 }
153 } else {
154 $class = 'il' . substr($listener, $last_slash + 1) . 'AppEventListener';
155 $file = "./" . $listener . "/classes/class." . $class . ".php";
156 // if file exists, call listener
157 if (is_file($file)) {
158 include_once($file);
159 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
160 }
161 }
162 }
163 }
164
165 $this->logger->debug("Finished event listener handling, started event propagation for event hook plugins ...");
166
167 // get all event hook plugins and forward the event to them
168 foreach ($this->component_factory->getActivePluginsInSlot("evhk") as $plugin) {
169 $plugin->handleEvent($a_component, $a_event, $a_parameter);
170 }
171 }
if($format !==null) $name
Definition: metadata.php:247

References $listener, $name, XapiProxy\$plugin, and ILIAS\Repository\logger().

Referenced by ilObjOrgUnit\assignUsersToEmployeeRole(), ilObjOrgUnit\assignUsersToSuperiorRole(), ilObjOrgUnit\assignUserToLocalRole(), ilObjOrgUnit\deassignUserFromEmployeeRole(), ilObjOrgUnit\deassignUserFromLocalRole(), ilObjOrgUnit\deassignUserFromSuperiorRole(), ilObjOrgUnit\delete(), and ilAuthFrontend\handleAuthenticationSuccess().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $component_factory

ilComponentFactory ilAppEventHandler::$component_factory
protected

Definition at line 57 of file class.ilAppEventHandler.php.

◆ $component_repository

ilComponentRepository ilAppEventHandler::$component_repository
protected

Definition at line 56 of file class.ilAppEventHandler.php.

◆ $db

ilDBInterface ilAppEventHandler::$db
protected

Definition at line 53 of file class.ilAppEventHandler.php.

Referenced by initListeners().

◆ $listener

array ilAppEventHandler::$listener
protected

Definition at line 54 of file class.ilAppEventHandler.php.

Referenced by raise().

◆ $logger

ilLogger ilAppEventHandler::$logger
protected

Definition at line 55 of file class.ilAppEventHandler.php.


The documentation for this class was generated from the following file: