ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Triggerer.php
Go to the documentation of this file.
1 <?php
3 
5 
16 trait Triggerer
17 {
18 
22  private $triggered_signals = array();
23 
31  protected function appendTriggeredSignal(Component\Signal $signal, $event)
32  {
33  $clone = clone $this;
34  if (!isset($clone->triggered_signals[$event])) {
35  $clone->triggered_signals[$event] = array();
36  }
37  $clone->triggered_signals[$event][] = new TriggeredSignal($signal, $event);
38  return $clone;
39  }
40 
48  protected function withTriggeredSignal(Component\Signal $signal, $event)
49  {
50  $clone = clone $this;
51  $clone->setTriggeredSignal($signal, $event);
52  return $clone;
53  }
54 
65  protected function setTriggeredSignal(Component\Signal $signal, $event)
66  {
67  $this->triggered_signals[$event] = array();
68  $this->triggered_signals[$event][] = new TriggeredSignal($signal, $event);
69  }
70 
74  public function getTriggeredSignals()
75  {
76  return $this->flattenArray($this->triggered_signals);
77  }
78 
85  public function getTriggeredSignalsFor($event)
86  {
87  if (!isset($this->triggered_signals[$event])) {
88  return [];
89  }
90  return array_map(
91  function ($ts) {
92  return $ts->getSignal();
93  },
94  $this->triggered_signals[$event]
95  );
96  }
97 
101  public function withResetTriggeredSignals()
102  {
103  $clone = clone $this;
104  $clone->triggered_signals = array();
105  return $clone;
106  }
107 
114  private function flattenArray(array $array)
115  {
116  $flatten = array();
117  array_walk_recursive($array, function ($a) use (&$flatten) {
118  $flatten[] = $a;
119  });
120  return $flatten;
121  }
122 }
getTriggeredSignalsFor($event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:85
setTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any othe signals registered on the same event.
Definition: Triggerer.php:65
flattenArray(array $array)
Flatten a multidimensional array to a single dimension.
Definition: Triggerer.php:114
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:48