3 namespace BookStack\Theming;
5 use BookStack\Auth\Access\SocialAuthService;
9 protected $listeners = [];
12 * Listen to a given custom theme event,
13 * setting up the action to be ran when the event occurs.
15 public function listen(string $event, callable $action)
17 if (!isset($this->listeners[$event])) {
18 $this->listeners[$event] = [];
21 $this->listeners[$event][] = $action;
25 * Dispatch the given event name.
26 * Runs any registered listeners for that event name,
27 * passing all additional variables to the listener action.
29 * If a callback returns a non-null value, this method will
30 * stop and return that value itself.
34 public function dispatch(string $event, ...$args)
36 foreach ($this->listeners[$event] ?? [] as $action) {
37 $result = call_user_func_array($action, $args);
38 if (!is_null($result)) {
47 * Read any actions from the set theme path if the 'functions.php' file exists.
49 public function readThemeActions()
51 $themeActionsFile = theme_path('functions.php');
52 if ($themeActionsFile && file_exists($themeActionsFile)) {
53 require $themeActionsFile;
58 * @see SocialAuthService::addSocialDriver
60 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
62 $socialAuthService = app()->make(SocialAuthService::class);
63 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);