1 <?php namespace BookStack\Theming;
3 use BookStack\Auth\Access\SocialAuthService;
7 protected $listeners = [];
10 * Listen to a given custom theme event,
11 * setting up the action to be ran when the event occurs.
13 public function listen(string $event, callable $action)
15 if (!isset($this->listeners[$event])) {
16 $this->listeners[$event] = [];
19 $this->listeners[$event][] = $action;
23 * Dispatch the given event name.
24 * Runs any registered listeners for that event name,
25 * passing all additional variables to the listener action.
27 * If a callback returns a non-null value, this method will
28 * stop and return that value itself.
31 public function dispatch(string $event, ...$args)
33 foreach ($this->listeners[$event] ?? [] as $action) {
34 $result = call_user_func_array($action, $args);
35 if (!is_null($result)) {
43 * Read any actions from the set theme path if the 'functions.php' file exists.
45 public function readThemeActions()
47 $themeActionsFile = theme_path('functions.php');
48 if (file_exists($themeActionsFile)) {
49 require $themeActionsFile;
54 * @see SocialAuthService::addSocialDriver
56 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
58 $socialAuthService = app()->make(SocialAuthService::class);
59 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);