3 namespace BookStack\Theming;
5 use BookStack\Auth\Access\SocialAuthService;
6 use Illuminate\Console\Application;
7 use Illuminate\Console\Application as Artisan;
8 use Illuminate\Contracts\Console\Kernel;
9 use Symfony\Component\Console\Command\Command;
13 protected $listeners = [];
16 * Listen to a given custom theme event,
17 * setting up the action to be ran when the event occurs.
19 public function listen(string $event, callable $action)
21 if (!isset($this->listeners[$event])) {
22 $this->listeners[$event] = [];
25 $this->listeners[$event][] = $action;
29 * Dispatch the given event name.
30 * Runs any registered listeners for that event name,
31 * passing all additional variables to the listener action.
33 * If a callback returns a non-null value, this method will
34 * stop and return that value itself.
38 public function dispatch(string $event, ...$args)
40 foreach ($this->listeners[$event] ?? [] as $action) {
41 $result = call_user_func_array($action, $args);
42 if (!is_null($result)) {
51 * Register a new custom artisan command to be available.
53 public function registerCommand(Command $command)
55 Artisan::starting(function(Application $application) use ($command) {
56 $application->addCommands([$command]);
61 * Read any actions from the set theme path if the 'functions.php' file exists.
63 public function readThemeActions()
65 $themeActionsFile = theme_path('functions.php');
66 if ($themeActionsFile && file_exists($themeActionsFile)) {
67 require $themeActionsFile;
72 * @see SocialAuthService::addSocialDriver
74 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
76 $socialAuthService = app()->make(SocialAuthService::class);
77 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);