3 namespace BookStack\Theming;
5 use BookStack\Auth\Access\SocialAuthService;
6 use Illuminate\Console\Application;
7 use Illuminate\Console\Application as Artisan;
8 use Symfony\Component\Console\Command\Command;
12 protected $listeners = [];
15 * Listen to a given custom theme event,
16 * setting up the action to be ran when the event occurs.
18 public function listen(string $event, callable $action)
20 if (!isset($this->listeners[$event])) {
21 $this->listeners[$event] = [];
24 $this->listeners[$event][] = $action;
28 * Dispatch the given event name.
29 * Runs any registered listeners for that event name,
30 * passing all additional variables to the listener action.
32 * If a callback returns a non-null value, this method will
33 * stop and return that value itself.
37 public function dispatch(string $event, ...$args)
39 foreach ($this->listeners[$event] ?? [] as $action) {
40 $result = call_user_func_array($action, $args);
41 if (!is_null($result)) {
50 * Register a new custom artisan command to be available.
52 public function registerCommand(Command $command)
54 Artisan::starting(function (Application $application) use ($command) {
55 $application->addCommands([$command]);
60 * Read any actions from the set theme path if the 'functions.php' file exists.
62 public function readThemeActions()
64 $themeActionsFile = theme_path('functions.php');
65 if ($themeActionsFile && file_exists($themeActionsFile)) {
66 require $themeActionsFile;
71 * @see SocialAuthService::addSocialDriver
73 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
75 $socialAuthService = app()->make(SocialAuthService::class);
76 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);