1 <?php namespace BookStack\Theming;
5 protected $listeners = [];
8 * Listen to a given custom theme event,
9 * setting up the action to be ran when the event occurs.
11 public function listen(string $event, callable $action)
13 if (!isset($this->listeners[$event])) {
14 $this->listeners[$event] = [];
17 $this->listeners[$event][] = $action;
21 * Dispatch the given event name.
22 * Runs any registered listeners for that event name,
23 * passing all additional variables to the listener action.
25 * If a callback returns a non-null value, this method will
26 * stop and return that value itself.
29 public function dispatch(string $event, ...$args)
31 foreach ($this->listeners[$event] ?? [] as $action) {
32 $result = call_user_func_array($action, $args);
33 if (!is_null($result)) {
41 * Read any actions from the set theme path if the 'functions.php' file exists.
43 public function readThemeActions()
45 $themeActionsFile = theme_path('functions.php');
46 if (file_exists($themeActionsFile)) {
47 require $themeActionsFile;