Bearsampp 2025.8.29
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
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
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
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
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
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
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
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
266
280}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const SWITCH_VERSION
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
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
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)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)