ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCtrlSubject Class Reference
+ Collaboration diagram for ilCtrlSubject:

Public Member Functions

 __construct ()
 
 attach (ilCtrlObserver $observer, ilCtrlEvent $event)
 
 detach (ilCtrlObserver $observer, ilCtrlEvent $event=ilCtrlEvent::ALL)
 
 notify (ilCtrlEvent $event, ?string $data)
 

Protected Member Functions

 initObserverGroup (string $group)
 

Protected Attributes

array $observer_groups = []
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s
Thibeau Fuhrer thibe.nosp@m.au@s.nosp@m.r.sol.nosp@m.utio.nosp@m.ns @noinspection AutoloadingIssuesInspection

Definition at line 26 of file class.ilCtrlSubject.php.

Constructor & Destructor Documentation

◆ __construct()

ilCtrlSubject::__construct ( )

Definition at line 33 of file class.ilCtrlSubject.php.

34 {
35 $this->initObserverGroup((ilCtrlEvent::ALL)->value);
36 }
initObserverGroup(string $group)
@ ALL
event string being used if

References ALL, and initObserverGroup().

+ Here is the call graph for this function:

Member Function Documentation

◆ attach()

ilCtrlSubject::attach ( ilCtrlObserver  $observer,
ilCtrlEvent  $event 
)

Definition at line 38 of file class.ilCtrlSubject.php.

38 : void
39 {
40 $this->initObserverGroup($event->value);
41
42 $this->observer_groups[$event->value][] = $observer;
43 }

References initObserverGroup().

+ Here is the call graph for this function:

◆ detach()

ilCtrlSubject::detach ( ilCtrlObserver  $observer,
ilCtrlEvent  $event = ilCtrlEvent::ALL 
)

Definition at line 45 of file class.ilCtrlSubject.php.

45 : void
46 {
47 $this->initObserverGroup($event->value);
48
49 foreach ($this->observer_groups[$event->value] as $index => $attached_observer) {
50 if ($attached_observer->getId() === $observer->getId()) {
51 unset($this->observer_groups[$event->value][$index]);
52 }
53 }
54 }
getId()
Unique identifier of the implementing event-listener.

References ilCtrlObserver\getId(), and initObserverGroup().

+ Here is the call graph for this function:

◆ initObserverGroup()

ilCtrlSubject::initObserverGroup ( string  $group)
protected

Definition at line 70 of file class.ilCtrlSubject.php.

70 : void
71 {
72 if (!isset($this->observer_groups[$group])) {
73 $this->observer_groups[$group] = [];
74 }
75 }

Referenced by __construct(), attach(), detach(), and notify().

+ Here is the caller graph for this function:

◆ notify()

ilCtrlSubject::notify ( ilCtrlEvent  $event,
?string  $data 
)

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

56 : void
57 {
58 $this->initObserverGroup($event->value);
59
60 $observers = array_merge(
61 $this->observer_groups[(ilCtrlEvent::ALL)->value],
62 $this->observer_groups[$event->value],
63 );
64
65 foreach ($observers as $interessted_observer) {
66 $interessted_observer->update($event, $data);
67 }
68 }

References $data, ALL, and initObserverGroup().

+ Here is the call graph for this function:

Field Documentation

◆ $observer_groups

array ilCtrlSubject::$observer_groups = []
protected

Definition at line 31 of file class.ilCtrlSubject.php.


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