3 namespace BookStack\Theming;
5 use BookStack\Auth\Access\SocialAuthService;
6 use Symfony\Component\Console\Command\Command;
10 protected $listeners = [];
15 protected $commands = [];
18 * Listen to a given custom theme event,
19 * setting up the action to be ran when the event occurs.
21 public function listen(string $event, callable $action)
23 if (!isset($this->listeners[$event])) {
24 $this->listeners[$event] = [];
27 $this->listeners[$event][] = $action;
31 * Dispatch the given event name.
32 * Runs any registered listeners for that event name,
33 * passing all additional variables to the listener action.
35 * If a callback returns a non-null value, this method will
36 * stop and return that value itself.
40 public function dispatch(string $event, ...$args)
42 foreach ($this->listeners[$event] ?? [] as $action) {
43 $result = call_user_func_array($action, $args);
44 if (!is_null($result)) {
53 * Register a new custom artisan command to be available.
55 public function registerCommand(Command $command)
57 $this->commands[] = $command;
61 * Get the custom commands that have been registered.
63 public function getRegisteredCommands(): array
65 return $this->commands;
69 * Read any actions from the set theme path if the 'functions.php' file exists.
71 public function readThemeActions()
73 $themeActionsFile = theme_path('functions.php');
74 if ($themeActionsFile && file_exists($themeActionsFile)) {
75 require $themeActionsFile;
80 * @see SocialAuthService::addSocialDriver
82 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
84 $socialAuthService = app()->make(SocialAuthService::class);
85 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);