3 namespace BookStack\Theming;
5 use BookStack\Auth\Access\SocialAuthService;
6 use Illuminate\Contracts\Console\Kernel;
7 use Symfony\Component\Console\Command\Command;
11 protected $listeners = [];
14 * Listen to a given custom theme event,
15 * setting up the action to be ran when the event occurs.
17 public function listen(string $event, callable $action)
19 if (!isset($this->listeners[$event])) {
20 $this->listeners[$event] = [];
23 $this->listeners[$event][] = $action;
27 * Dispatch the given event name.
28 * Runs any registered listeners for that event name,
29 * passing all additional variables to the listener action.
31 * If a callback returns a non-null value, this method will
32 * stop and return that value itself.
36 public function dispatch(string $event, ...$args)
38 foreach ($this->listeners[$event] ?? [] as $action) {
39 $result = call_user_func_array($action, $args);
40 if (!is_null($result)) {
49 * Register a new custom artisan command to be available.
51 public function registerCommand(Command $command)
53 /** @var \Illuminate\Foundation\Console\Kernel $consoleKernel */
54 $consoleKernel = app()->make(Kernel::class);
55 $consoleKernel->registerCommand($command);
59 * Read any actions from the set theme path if the 'functions.php' file exists.
61 public function readThemeActions()
63 $themeActionsFile = theme_path('functions.php');
64 if ($themeActionsFile && file_exists($themeActionsFile)) {
65 require $themeActionsFile;
70 * @see SocialAuthService::addSocialDriver
72 public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null)
74 $socialAuthService = app()->make(SocialAuthService::class);
75 $socialAuthService->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);