2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.memcached.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 TplAppMemcached
12 *
13 * This class provides methods to generate menu items and actions for managing Memcached within the Bearsampp application.
14 * It includes functionalities for enabling/disabling Memcached, switching versions, changing ports, and managing services.
15 */
17{
18 // Constants for menu and action identifiers
19 const MENU = 'memcached';
20 const MENU_VERSIONS = 'memcachedVersions';
21 const MENU_SERVICE = 'memcachedService';
22
23 const ACTION_ENABLE = 'enableMemcached';
24 const ACTION_SWITCH_VERSION = 'switchMemcachedVersion';
25 const ACTION_CHANGE_PORT = 'changeMemcachedPort';
26 const ACTION_INSTALL_SERVICE = 'installMemcachedService';
27 const ACTION_REMOVE_SERVICE = 'removeMemcachedService';
28
29 /**
30 * Generates the menu item for enabling/disabling Memcached.
31 *
32 * This method creates a menu item for enabling or disabling Memcached and defines the actions to be taken
33 * when the menu item is selected. It uses the global language object to retrieve the localized string for Memcached.
34 *
35 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
36 * @global object $bearsamppBins Provides access to system binaries and their configurations.
37 *
38 * @return array The generated menu item for enabling/disabling Memcached.
39 */
40 public static function process()
41 {
43
44 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MEMCACHED), self::MENU, get_called_class(), $bearsamppBins->getMemcached()->isEnable());
45 }
46
47 /**
48 * Generates the menu items and actions for managing Memcached.
49 *
50 * This method creates menu items for downloading Memcached, enabling/disabling it, switching versions, managing services,
51 * updating the environment PATH, and viewing logs. It uses the global language object to retrieve localized strings.
52 *
53 * @global object $bearsamppRoot Provides access to the root path of the application.
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 menu items and actions for managing Memcached.
58 */
59 public static function getMenuMemcached()
60 {
62 $resultItems = $resultActions = '';
63
64 $isEnabled = $bearsamppBins->getMemcached()->isEnable();
65
66 // Download
68 Util::getWebsiteUrl('module/memcached', '#releases'),
69 false,
71 ) . PHP_EOL;
72
73 // Enable
74 $tplEnable = TplApp::getActionMulti(
75 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
76 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
77 false, get_called_class()
78 );
79 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
80 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
81
82 if ($isEnabled) {
83 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
84
85 // Versions
86 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
87 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
88 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
89
90 // Service
91 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
92 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
93 $resultActions .= $tplService[TplApp::SECTION_CONTENT];
94
95 // Update environment PATH
96 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
97
98 // Log
99 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMemcached()->getLog()) . PHP_EOL;
100 }
101
102 return $resultItems . PHP_EOL . $resultActions;
103 }
104
105 /**
106 * Generates the menu items and actions for switching Memcached versions.
107 *
108 * This method creates menu items for each available Memcached version and defines the actions to be taken
109 * when a version is selected. It uses the global language object to retrieve localized strings.
110 *
111 * @global object $bearsamppBins Provides access to system binaries and their configurations.
112 *
113 * @return string The generated menu items and actions for switching Memcached versions.
114 */
115 public static function getMenuMemcachedVersions()
116 {
117 global $bearsamppBins;
118 $items = '';
119 $actions = '';
120
121 foreach ($bearsamppBins->getMemcached()->getVersionList() as $version) {
122 $tplSwitchMemcachedVersion = TplApp::getActionMulti(
123 self::ACTION_SWITCH_VERSION, array($version),
124 array($version, $version == $bearsamppBins->getMemcached()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
125 false, get_called_class()
126 );
127
128 // Item
129 $items .= $tplSwitchMemcachedVersion[TplApp::SECTION_CALL] . PHP_EOL;
130
131 // Action
132 $actions .= PHP_EOL . $tplSwitchMemcachedVersion[TplApp::SECTION_CONTENT];
133 }
134
135 return $items . $actions;
136 }
137
138 /**
139 * Generates the action to enable or disable Memcached.
140 *
141 * This method creates the action string for enabling or disabling Memcached. It includes commands to reload
142 * the application after the action is performed.
143 *
144 * @global object $bearsamppBins Provides access to system binaries and their configurations.
145 *
146 * @param int $enable The value indicating whether to enable or disable Memcached.
147 * @return string The generated action string for enabling or disabling Memcached.
148 */
149 public static function getActionEnableMemcached($enable)
150 {
151 global $bearsamppBins;
152
153 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMemcached()->getName(), $enable)) . PHP_EOL .
155 }
156
157 /**
158 * Generates the action to switch Memcached versions.
159 *
160 * This method creates the action string for switching Memcached versions. It includes commands to reload
161 * the application after the action is performed.
162 *
163 * @global object $bearsamppBins Provides access to system binaries and their configurations.
164 *
165 * @param string $version The version to switch to.
166 * @return string The generated action string for switching Memcached versions.
167 */
168 public static function getActionSwitchMemcachedVersion($version)
169 {
170 global $bearsamppBins;
171
172 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMemcached()->getName(), $version)) . PHP_EOL .
174 }
175
176 /**
177 * Generates the menu items and actions for managing Memcached services.
178 *
179 * This method creates menu items for starting, stopping, and restarting the Memcached service, as well as
180 * checking and changing the port, and installing or removing the service. It uses the global language object
181 * to retrieve localized strings.
182 *
183 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
184 * @global object $bearsamppBins Provides access to system binaries and their configurations.
185 *
186 * @return string The generated menu items and actions for managing Memcached services.
187 */
188 public static function getMenuMemcachedService()
189 {
191
192 $tplChangePort = TplApp::getActionMulti(
193 self::ACTION_CHANGE_PORT, null,
195 false, get_called_class()
196 );
197
198 $isInstalled = $bearsamppBins->getMemcached()->getService()->isInstalled();
199
200 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
201 TplAestan::getItemActionServiceStop($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
202 TplAestan::getItemActionServiceRestart($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
203 TplAestan::getItemSeparator() . PHP_EOL .
205 Action::CHECK_PORT, array($bearsamppBins->getMemcached()->getName(), $bearsamppBins->getMemcached()->getPort()),
206 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMemcached()->getPort()), TplAestan::GLYPH_LIGHT)
207 ) . PHP_EOL .
208 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
209
210 if (!$isInstalled) {
211 $tplInstallService = TplApp::getActionMulti(
212 self::ACTION_INSTALL_SERVICE, null,
214 $isInstalled, get_called_class()
215 );
216
217 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
218 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
219 } else {
220 $tplRemoveService = TplApp::getActionMulti(
221 self::ACTION_REMOVE_SERVICE, null,
223 !$isInstalled, get_called_class()
224 );
225
226 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
227 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
228 }
229
230 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
231
232 return $result;
233 }
234
235 /**
236 * Generates the action to change the Memcached port.
237 *
238 * This method creates the action string for changing the Memcached port. It includes commands to reload
239 * the application after the action is performed.
240 *
241 * @global object $bearsamppBins Provides access to system binaries and their configurations.
242 *
243 * @return string The generated action string for changing the Memcached port.
244 */
245 public static function getActionChangeMemcachedPort()
246 {
247 global $bearsamppBins;
248
249 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMemcached()->getName())) . PHP_EOL .
251 }
252
253 /**
254 * Generates the action to install the Memcached service.
255 *
256 * This method creates the action string for installing the Memcached service. It includes commands to reload
257 * the application after the action is performed.
258 *
259 * @return string The generated action string for installing the Memcached service.
260 */
266
267 /**
268 * Generates the action to remove the Memcached service.
269 *
270 * This method creates the action string for removing the Memcached service. It includes commands to reload
271 * the application after the action is performed.
272 *
273 * @return string The generated action string for removing the Memcached service.
274 */
280}
$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 MEMCACHED
const MENU_INSTALL_SERVICE
const MENU_UPDATE_ENV_PATH
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)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionEnableMemcached($enable)
static getActionSwitchMemcachedVersion($version)
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)