ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAppEventHandler Class Reference

Global event handler. More...

+ Collaboration diagram for ilAppEventHandler:

Public Member Functions

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

Protected Member Functions

 initListeners ()
 

Protected Attributes

array $listener = []
 
ilLogger $logger
 
ilComponentRepository $component_repository
 
ilComponentFactory $component_factory
 

Private Attributes

ilArtifactEventHandlingData $event_handling_data
 

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("components/ILIAS/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["components/ILIAS/User"] = array("components/ILIAS/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. ./components/ILIAS/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 ( ?ilLogger  $logger = null)

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

60 {
61 global $DIC;
62
63 $this->event_handling_data = new ilArtifactEventHandlingData();
64 $this->component_repository = $DIC["component.repository"];
65 $this->component_factory = $DIC["component.factory"];
66 $this->initListeners();
67
68 $this->logger = $logger ?? \ilLoggerFactory::getLogger('evnt');
69 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:26

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 {
73 $listener_events = $this->event_handling_data->getEventsByType("listen");
74 foreach ($listener_events as $event_key => $event_value) {
75 $this->listener[$event_value["type_specification"]][] = $event_value["component"];
76 }
77 }

Referenced by __construct().

+ 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. "components/ILIAS/Forum" or "components/ILIAS/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

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

90 : void {
91 $this->logger->debug(sprintf(
92 "Received event '%s' from component '%s'.",
93 $a_event,
94 $a_component
95 ));
96
97 $parameter_formatter = static function ($value) use (&$parameter_formatter) {
98 if (is_object($value)) {
99 return get_class($value);
100 }
101
102 if (is_array($value)) {
103 return array_map(
104 $parameter_formatter,
105 $value
106 );
107 }
108
109 return $value;
110 };
111
112 $this->logger->debug('Event data: ' . var_export(array_map(
113 $parameter_formatter,
114 $a_parameter
115 ), true));
116
117 $this->logger->debug("Started event propagation for event listeners ...");
118
119 if (is_array($this->listener[$a_component] ?? null)) {
120 foreach ($this->listener[$a_component] as $listener) {
121 // Allow listeners like Services/WebServices/ECS
122 $last_slash = strripos($listener, '/');
123 $comp = substr($listener, 0, $last_slash);
124 // any kind of plugins with events in their plugin.xml
125 if ($comp == 'Plugins') {
126 $name = substr($listener, $last_slash + 1);
127
128
129 foreach ($this->component_repository->getPlugins() as $pl) {
130 if ($pl->getName() !== $name || !$pl->isActive()) {
131 continue;
132 }
133 $plugin = $this->component_factory->getPlugin($pl->getId());
134 $plugin->handleEvent($a_component, $a_event, $a_parameter);
135 }
136 } else {
137 $class = 'il' . substr($listener, $last_slash + 1) . 'AppEventListener';
138
139 if (class_exists($class)) {
140 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
141 }
142 }
143 }
144 }
145
146 $this->logger->debug("Finished event listener handling, started event propagation for event hook plugins ...");
147
148 // get all event hook plugins and forward the event to them
149 foreach ($this->component_factory->getActivePluginsInSlot("evhk") as $plugin) {
150 $plugin->handleEvent($a_component, $a_event, $a_parameter);
151 }
152 }

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

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

+ 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 56 of file class.ilAppEventHandler.php.

◆ $component_repository

ilComponentRepository ilAppEventHandler::$component_repository
protected

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

◆ $event_handling_data

ilArtifactEventHandlingData ilAppEventHandler::$event_handling_data
private

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

◆ $listener

array ilAppEventHandler::$listener = []
protected

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

Referenced by raise().

◆ $logger

ilLogger ilAppEventHandler::$logger
protected

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


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