Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.memcached.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 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
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
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
59 public static function getMenuMemcached()
60 {
62 $resultItems = $resultActions = '';
63
64 $isEnabled = $bearsamppBins->getMemcached()->isEnable();
65
66 // Download
67 $resultItems .= TplAestan::getItemLink(
69 HttpClient::getWebsiteUrl('module/memcached', '#releases'),
70 false,
72 ) . PHP_EOL;
73
74 // Enable
75 $tplEnable = TplApp::getActionMulti(
76 self::ACTION_ENABLE,
77 array($isEnabled ? Config::DISABLED : Config::ENABLED),
78 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
79 false,
80 get_called_class()
81 );
82 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
83 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
84
85 if ($isEnabled) {
86 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
87
88 // Versions
89 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
90 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
91 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
92
93 // Service
94 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
95 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
96 $resultActions .= $tplService[TplApp::SECTION_CONTENT];
97
98 // Update environment PATH
99 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), Path::getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
100
101 // Log
102 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMemcached()->getLog()) . PHP_EOL;
103 }
104
105 return $resultItems . PHP_EOL . $resultActions;
106 }
107
118 public static function getMenuMemcachedVersions()
119 {
120 global $bearsamppBins;
121 $items = '';
122 $actions = '';
123
124 foreach ($bearsamppBins->getMemcached()->getVersionList() as $version) {
125 $tplSwitchMemcachedVersion = TplApp::getActionMulti(
126 self::ACTION_SWITCH_VERSION,
127 array($version),
128 array($version, $version == $bearsamppBins->getMemcached()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
129 false,
130 get_called_class()
131 );
132
133 // Item
134 $items .= $tplSwitchMemcachedVersion[TplApp::SECTION_CALL] . PHP_EOL;
135
136 // Action
137 $actions .= PHP_EOL . $tplSwitchMemcachedVersion[TplApp::SECTION_CONTENT];
138 }
139
140 return $items . $actions;
141 }
142
155 public static function getActionEnableMemcached($enable)
156 {
157 global $bearsamppBins;
158
159 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMemcached()->getName(), $enable)) . PHP_EOL .
161 }
162
175 public static function getActionSwitchMemcachedVersion($version)
176 {
177 global $bearsamppBins;
178
179 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMemcached()->getName(), $version)) . PHP_EOL .
181 }
182
195 public static function getMenuMemcachedService()
196 {
198
199 $tplChangePort = TplApp::getActionMulti(
200 self::ACTION_CHANGE_PORT,
201 null,
203 false,
204 get_called_class()
205 );
206
207 $isInstalled = $bearsamppBins->getMemcached()->getService()->isInstalled();
208
209 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
210 TplAestan::getItemActionServiceStop($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
211 TplAestan::getItemActionServiceRestart($bearsamppBins->getMemcached()->getService()->getName()) . PHP_EOL .
212 TplAestan::getItemSeparator() . PHP_EOL .
215 array($bearsamppBins->getMemcached()->getName(), $bearsamppBins->getMemcached()->getPort()),
216 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMemcached()->getPort()), TplAestan::GLYPH_LIGHT)
217 ) . PHP_EOL .
218 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
219
220 if (!$isInstalled) {
221 $tplInstallService = TplApp::getActionMulti(
222 self::ACTION_INSTALL_SERVICE,
223 null,
225 $isInstalled,
226 get_called_class()
227 );
228
229 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
230 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
231 } else {
232 $tplRemoveService = TplApp::getActionMulti(
233 self::ACTION_REMOVE_SERVICE,
234 null,
236 !$isInstalled,
237 get_called_class()
238 );
239
240 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
241 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
242 }
243
244 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
245
246 return $result;
247 }
248
259 public static function getActionChangeMemcachedPort()
260 {
261 global $bearsamppBins;
262
263 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMemcached()->getName())) . PHP_EOL .
265 }
266
280
294}
295
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const SWITCH_VERSION
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MENU_ENABLE
const SERVICE
const DOWNLOAD_MORE
const MENU_CHANGE_PORT
const MENU_INSTALL_SERVICE
const MEMCACHED
const MENU_UPDATE_ENV_PATH
const MENU_LOGS
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const VERSIONS
static getRootPath($aetrayPath=false)
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
const GLYPH_SERVICE_INSTALL
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemActionServiceStart($service)
static getItemSeparator()
static getItemActionServiceRestart($service)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
static getMenu($caption, $menu, $class)
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
const SECTION_CALL
const SECTION_CONTENT
static getMenuEnable($caption, $menu, $class, $enabled=true)
static getActionEnableMemcached($enable)
static getActionSwitchMemcachedVersion($version)