Skip to content

Commit

Permalink
Merge pull request #32 from tanhongit/main
Browse files Browse the repository at this point in the history
Add namespace for view function in the laravel package
  • Loading branch information
tanhongit authored Nov 11, 2023
2 parents 8ff36e7 + dd66e0e commit 0e00e75
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
21 changes: 21 additions & 0 deletions common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions config/tg-notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ parameters:
level: 8
paths:
- src
- config
tmpDir: build/phpstan
checkMissingIterableValueType: false
4 changes: 2 additions & 2 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
),
Expand Down Expand Up @@ -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),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Trait/BotSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
Expand All @@ -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()]
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function sendSettingEventMessage(
|| !$callback
) {
$this->editMessageText(
view(
tgn_view(
$view ?? config('telegram-git-notifier.view.tools.custom_event'),
compact('platform')
),
Expand Down Expand Up @@ -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')
),
Expand Down

0 comments on commit 0e00e75

Please sign in to comment.