Skip to content

Commit 0e00e75

Browse files
authored
Merge pull request #32 from tanhongit/main
Add namespace for view function in the laravel package
2 parents 8ff36e7 + dd66e0e commit 0e00e75

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

common/helpers.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,24 @@ function view(string $partialPath, array $data = []): null|string
140140
}
141141
}
142142
}
143+
144+
if (!function_exists('tgn_view')) {
145+
/**
146+
* Get view template
147+
*
148+
* @param string $partialPath
149+
* @param array $data
150+
*
151+
* @return null|string
152+
*/
153+
function tgn_view(string $partialPath, array $data = []): null|string
154+
{
155+
if (class_exists('Illuminate\Foundation\Application')) {
156+
$partialPath = config('telegram-git-notifier.view.namespace') . '::' . $partialPath;
157+
}
158+
159+
$content = view($partialPath, $data);
160+
161+
return $content ?: null;
162+
}
163+
}

config/tg-notifier.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
/** Set the path to the view file */
5454
'view' => [
55+
'namespace' => ($_ENV['TGN_VIEW_NAMESPACE'] ?? 'tg-notifier'),
56+
5557
'path' => $_ENV['TGN_VIEW_PATH'] ??
5658
'resources/views',
5759

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ parameters:
22
level: 8
33
paths:
44
- src
5+
- config
56
tmpDir: build/phpstan
67
checkMissingIterableValueType: false

src/Structures/Notification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function accessDenied(
2020
): void {
2121
$this->telegram->sendMessage([
2222
'chat_id' => $this->chatBotId,
23-
'text' => view(
23+
'text' => tgn_view(
2424
$viewTemplate ?? config('telegram-git-notifier.view.globals.access_denied'),
2525
['chatId' => $chatId]
2626
),
@@ -65,7 +65,7 @@ private function setMessage(string $typeEvent): void
6565
? "events.{$this->event->platform}.{$event}.default"
6666
: "events.{$this->event->platform}.{$event}.{$action}";
6767

68-
$viewResult = view($viewTemplate, [
68+
$viewResult = tgn_view($viewTemplate, [
6969
'payload' => $this->payload,
7070
'event' => tgn_convert_event_name($typeEvent),
7171
]);

src/Trait/BotSettingTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function setMyCommands(
2424
'commands' => json_encode($menuCommand),
2525
]);
2626
$this->sendMessage(
27-
view(
27+
tgn_view(
2828
$view ??
2929
config('telegram-git-notifier.view.tools.set_menu_cmd')
3030
)
@@ -34,7 +34,7 @@ public function setMyCommands(
3434
public function settingHandle(?string $view = null): void
3535
{
3636
$this->sendMessage(
37-
view($view ?? config('telegram-git-notifier.view.tools.settings')),
37+
tgn_view($view ?? config('telegram-git-notifier.view.tools.settings')),
3838
['reply_markup' => $this->settingMarkup()]
3939
);
4040
}

src/Trait/EventSettingTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function sendSettingEventMessage(
143143
|| !$callback
144144
) {
145145
$this->editMessageText(
146-
view(
146+
tgn_view(
147147
$view ?? config('telegram-git-notifier.view.tools.custom_event'),
148148
compact('platform')
149149
),
@@ -181,7 +181,7 @@ public function handleEventWithActions(
181181
$event
182182
);
183183
$this->editMessageText(
184-
view(
184+
tgn_view(
185185
$view ?? config('telegram-git-notifier.view.tools.custom_event_action'),
186186
compact('event', 'platform')
187187
),

0 commit comments

Comments
 (0)