2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.mailhog.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class TplAppMailhog
12 *
13 * This class provides methods to generate menus and actions for managing Mailhog within the Bearsampp application.
14 * It includes functionalities for enabling/disabling Mailhog, switching versions, changing ports, and managing the service.
15 */
17{
18 const MENU = 'mailhog';
19 const MENU_VERSIONS = 'mailhogVersions';
20 const MENU_SERVICE = 'mailhogService';
21
22 const ACTION_ENABLE = 'enableMailhog';
23 const ACTION_SWITCH_VERSION = 'switchMailhogVersion';
24 const ACTION_CHANGE_PORT = 'changeMailhogPort';
25 const ACTION_INSTALL_SERVICE = 'installMailhogService';
26 const ACTION_REMOVE_SERVICE = 'removeMailhogService';
27
28 /**
29 * Processes the Mailhog menu.
30 *
31 * This method generates the menu for enabling or disabling Mailhog.
32 * It uses the global language object to retrieve the localized string for Mailhog.
33 *
34 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
35 * @global object $bearsamppBins Provides access to system binaries and their configurations.
36 *
37 * @return array The generated menu for enabling or disabling Mailhog.
38 */
39 public static function process()
40 {
42
43 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MAILHOG), self::MENU, get_called_class(), $bearsamppBins->getMailhog()->isEnable());
44 }
45
46 /**
47 * Generates the Mailhog menu.
48 *
49 * This method creates the menu items and associated actions for Mailhog, including options for downloading,
50 * enabling, switching versions, managing the service, and viewing logs.
51 *
52 * @global object $bearsamppRoot Provides access to the root path of the application.
53 * @global object $bearsamppConfig Provides access to the application configuration.
54 * @global object $bearsamppBins Provides access to system binaries and their configurations.
55 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
56 *
57 * @return string The generated Mailhog menu items and actions.
58 */
59 public static function getMenuMailhog()
60 {
62 $resultItems = $resultActions = '';
63
64 $isEnabled = $bearsamppBins->getMailhog()->isEnable();
65
66 // Download
67 $resultItems .= TplAestan::getItemLink(
69 Util::getWebsiteUrl('module/mailhog', '#releases'),
70 false,
72 ) . PHP_EOL;
73
74 // Enable
75 $tplEnable = TplApp::getActionMulti(
76 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
77 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
78 false, get_called_class()
79 );
80 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
81 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
82
83 if ($isEnabled) {
84 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
85
86 // Versions
87 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
88 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
89 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
90
91 // Service
92 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
93 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
94 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
95
96 // Web page
97 $resultItems .= TplAestan::getItemExe(
99 $bearsamppConfig->getBrowser(),
101 $bearsamppRoot->getLocalUrl() . ':' . $bearsamppBins->getMailhog()->getUiPort()
102 ) . PHP_EOL;
103
104 // Log
105 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMailhog()->getLog()) . PHP_EOL;
106 }
107
108 return $resultItems . PHP_EOL . $resultActions;
109 }
110
111 /**
112 * Generates the Mailhog versions menu.
113 *
114 * This method creates the menu items and associated actions for switching between different versions of Mailhog.
115 *
116 * @global object $bearsamppBins Provides access to system binaries and their configurations.
117 *
118 * @return string The generated Mailhog versions menu items and actions.
119 */
120 public static function getMenuMailhogVersions()
121 {
122 global $bearsamppBins;
123 $items = '';
124 $actions = '';
125
126 foreach ($bearsamppBins->getMailhog()->getVersionList() as $version) {
127 $tplSwitchMailhogVersion = TplApp::getActionMulti(
128 self::ACTION_SWITCH_VERSION, array($version),
129 array($version, $version == $bearsamppBins->getMailhog()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
130 false, get_called_class()
131 );
132
133 // Item
134 $items .= $tplSwitchMailhogVersion[TplApp::SECTION_CALL] . PHP_EOL;
135
136 // Action
137 $actions .= PHP_EOL . $tplSwitchMailhogVersion[TplApp::SECTION_CONTENT];
138 }
139
140 return $items . $actions;
141 }
142
143 /**
144 * Generates the action to enable or disable Mailhog.
145 *
146 * This method creates the action string for enabling or disabling Mailhog and includes a command to reload the application.
147 *
148 * @global object $bearsamppBins Provides access to system binaries and their configurations.
149 *
150 * @param int $enable The enable flag (1 to enable, 0 to disable).
151 * @return string The generated action string for enabling or disabling Mailhog.
152 */
153 public static function getActionEnableMailhog($enable)
154 {
155 global $bearsamppBins;
156
157 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMailhog()->getName(), $enable)) . PHP_EOL .
159 }
160
161 /**
162 * Generates the action to switch the Mailhog version.
163 *
164 * This method creates the action string for switching the Mailhog version and includes a command to reload the application.
165 *
166 * @global object $bearsamppBins Provides access to system binaries and their configurations.
167 *
168 * @param string $version The version to switch to.
169 * @return string The generated action string for switching the Mailhog version.
170 */
171 public static function getActionSwitchMailhogVersion($version)
172 {
173 global $bearsamppBins;
174
175 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMailhog()->getName(), $version)) . PHP_EOL .
177 }
178
179 /**
180 * Generates the Mailhog service menu.
181 *
182 * This method creates the menu items and associated actions for managing the Mailhog service, including starting, stopping,
183 * restarting, changing ports, and installing or removing the service.
184 *
185 * @global object $bearsamppRoot Provides access to the root path of the application.
186 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
187 * @global object $bearsamppBins Provides access to system binaries and their configurations.
188 *
189 * @return string The generated Mailhog service menu items and actions.
190 */
191 public static function getMenuMailhogService()
192 {
194
195 $tplChangePort = TplApp::getActionMulti(
196 self::ACTION_CHANGE_PORT, null,
198 false, get_called_class()
199 );
200
201 $isInstalled = $bearsamppBins->getMailhog()->getService()->isInstalled();
202
203 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMailhog()->getService()->getName()) . PHP_EOL .
204 TplAestan::getItemActionServiceStop($bearsamppBins->getMailhog()->getService()->getName()) . PHP_EOL .
205 TplAestan::getItemActionServiceRestart($bearsamppBins->getMailhog()->getService()->getName()) . PHP_EOL .
206 TplAestan::getItemSeparator() . PHP_EOL .
208 Action::CHECK_PORT, array($bearsamppBins->getMailhog()->getName(), $bearsamppBins->getMailhog()->getSmtpPort()),
209 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMailhog()->getSmtpPort()), TplAestan::GLYPH_LIGHT)
210 ) . PHP_EOL .
211 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
212 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
213
214 if (!$isInstalled) {
215 $tplInstallService = TplApp::getActionMulti(
216 self::ACTION_INSTALL_SERVICE, null,
218 $isInstalled, get_called_class()
219 );
220
221 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
222 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
223 } else {
224 $tplRemoveService = TplApp::getActionMulti(
225 self::ACTION_REMOVE_SERVICE, null,
227 !$isInstalled, get_called_class()
228 );
229
230 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
231 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
232 }
233
234 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
235
236 return $result;
237 }
238
239 /**
240 * Generates the action to change the Mailhog port.
241 *
242 * This method creates the action string for changing the Mailhog port and includes a command to reload the application.
243 *
244 * @global object $bearsamppBins Provides access to system binaries and their configurations.
245 *
246 * @return string The generated action string for changing the Mailhog port.
247 */
248 public static function getActionChangeMailhogPort()
249 {
250 global $bearsamppBins;
251
252 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMailhog()->getName())) . PHP_EOL .
254 }
255
256 /**
257 * Generates the action to install the Mailhog service.
258 *
259 * This method creates the action string for installing the Mailhog service and includes a command to reload the application.
260 *
261 * @return string The generated action string for installing the Mailhog service.
262 */
268
269 /**
270 * Generates the action to remove the Mailhog service.
271 *
272 * This method creates the action string for removing the Mailhog service and includes a command to reload the application.
273 *
274 * @return string The generated action string for removing the Mailhog service.
275 */
281}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const SWITCH_VERSION
const SERVICE
const DISABLED
const ENABLED
const MENU_LOGS
const VERSIONS
const MENU_INSTALL_SERVICE
const MENU_UPDATE_ENV_PATH
const MAILHOG
const MENU_ENABLE
const DOWNLOAD_MORE
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const SERVICE
const MENU_CHANGE_PORT
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
static getItemSeparator()
static getItemActionServiceStart($service)
static getItemActionServiceRestart($service)
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemExe($caption, $exe, $glyph, $params=null)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionInstallMailhogService()
static getActionSwitchMailhogVersion($version)
static getActionRemoveMailhogService()
static getActionChangeMailhogPort()
static getActionEnableMailhog($enable)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
static getMenuEnable($caption, $menu, $class, $enabled=true)
const SECTION_CONTENT
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getMenu($caption, $menu, $class)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
global $bearsamppConfig
Definition homepage.php:26