diff --git a/common/helpers.php b/common/helpers.php index b2067b9..cd1ee99 100755 --- a/common/helpers.php +++ b/common/helpers.php @@ -140,3 +140,24 @@ function view(string $partialPath, array $data = []): null|string } } } + +if (!function_exists('tgn_view')) { + /** + * Get view template + * + * @param string $partialPath + * @param array $data + * + * @return null|string + */ + function tgn_view(string $partialPath, array $data = []): null|string + { + if (class_exists('Illuminate\Foundation\Application')) { + $partialPath = config('telegram-git-notifier.view.namespace') . '::' . $partialPath; + } + + $content = view($partialPath, $data); + + return $content ?: null; + } +} diff --git a/config/tg-notifier.php b/config/tg-notifier.php index b762afd..8c64192 100644 --- a/config/tg-notifier.php +++ b/config/tg-notifier.php @@ -52,6 +52,8 @@ /** Set the path to the view file */ 'view' => [ + 'namespace' => ($_ENV['TGN_VIEW_NAMESPACE'] ?? 'tg-notifier'), + 'path' => $_ENV['TGN_VIEW_PATH'] ?? 'resources/views', diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2e837cd..5bba7cc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,5 +2,6 @@ parameters: level: 8 paths: - src + - config tmpDir: build/phpstan checkMissingIterableValueType: false diff --git a/src/Structures/Notification.php b/src/Structures/Notification.php index 6ab09d8..56b10ac 100644 --- a/src/Structures/Notification.php +++ b/src/Structures/Notification.php @@ -20,7 +20,7 @@ public function accessDenied( ): void { $this->telegram->sendMessage([ 'chat_id' => $this->chatBotId, - 'text' => view( + 'text' => tgn_view( $viewTemplate ?? config('telegram-git-notifier.view.globals.access_denied'), ['chatId' => $chatId] ), @@ -65,7 +65,7 @@ private function setMessage(string $typeEvent): void ? "events.{$this->event->platform}.{$event}.default" : "events.{$this->event->platform}.{$event}.{$action}"; - $viewResult = view($viewTemplate, [ + $viewResult = tgn_view($viewTemplate, [ 'payload' => $this->payload, 'event' => tgn_convert_event_name($typeEvent), ]); diff --git a/src/Trait/BotSettingTrait.php b/src/Trait/BotSettingTrait.php index c52941e..49393bb 100644 --- a/src/Trait/BotSettingTrait.php +++ b/src/Trait/BotSettingTrait.php @@ -24,7 +24,7 @@ public function setMyCommands( 'commands' => json_encode($menuCommand), ]); $this->sendMessage( - view( + tgn_view( $view ?? config('telegram-git-notifier.view.tools.set_menu_cmd') ) @@ -34,7 +34,7 @@ public function setMyCommands( public function settingHandle(?string $view = null): void { $this->sendMessage( - view($view ?? config('telegram-git-notifier.view.tools.settings')), + tgn_view($view ?? config('telegram-git-notifier.view.tools.settings')), ['reply_markup' => $this->settingMarkup()] ); } diff --git a/src/Trait/EventSettingTrait.php b/src/Trait/EventSettingTrait.php index 3519d7c..37dbf58 100644 --- a/src/Trait/EventSettingTrait.php +++ b/src/Trait/EventSettingTrait.php @@ -143,7 +143,7 @@ public function sendSettingEventMessage( || !$callback ) { $this->editMessageText( - view( + tgn_view( $view ?? config('telegram-git-notifier.view.tools.custom_event'), compact('platform') ), @@ -181,7 +181,7 @@ public function handleEventWithActions( $event ); $this->editMessageText( - view( + tgn_view( $view ?? config('telegram-git-notifier.view.tools.custom_event_action'), compact('event', 'platform') ),