Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.php.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
18{
19 const MENU = 'php';
20 const MENU_VERSIONS = 'phpVersions';
21 const MENU_SETTINGS = 'phpSettings';
22 const MENU_EXTENSIONS = 'phpExtensions';
23
24 const ACTION_ENABLE = 'enablePhp';
25 const ACTION_SWITCH_VERSION = 'switchPhpVersion';
26 const ACTION_SWITCH_SETTING = 'switchPhpSetting';
27 const ACTION_SWITCH_EXTENSION = 'switchPhpExtension';
28
37 public static function process()
38 {
40
41 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::PHP), self::MENU, get_called_class(), $bearsamppBins->getPhp()->isEnable());
42 }
43
52 public static function getMenuPhp()
53 {
55 $resultItems = $resultActions = '';
56
57 $isEnabled = $bearsamppBins->getPhp()->isEnable();
58
59 // Download
60 $resultItems .= TplAestan::getItemLink(
62 HttpClient::getWebsiteUrl('module/php', '#releases'),
63 false,
65 ) . PHP_EOL;
66
67 // Enable
68 $tplEnable = TplApp::getActionMulti(
69 self::ACTION_ENABLE,
70 array($isEnabled ? Config::DISABLED : Config::ENABLED),
71 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
72 false,
73 get_called_class()
74 );
75 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
76 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
77
78 if ($isEnabled) {
79 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
80
81 // Versions
82 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
83 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
84 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
85
86 // Settings
87 $tplSettings = TplApp::getMenu($bearsamppLang->getValue(Lang::SETTINGS), self::MENU_SETTINGS, get_called_class());
88 $resultItems .= $tplSettings[TplApp::SECTION_CALL] . PHP_EOL;
89 $resultActions .= $tplSettings[TplApp::SECTION_CONTENT] . PHP_EOL;
90
91 // Extensions
92 $tplExtensions = TplApp::getMenu($bearsamppLang->getValue(Lang::EXTENSIONS), self::MENU_EXTENSIONS, get_called_class());
93 $resultItems .= $tplExtensions[TplApp::SECTION_CALL] . PHP_EOL;
94 $resultActions .= $tplExtensions[TplApp::SECTION_CONTENT];
95
96 // Conf
97 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getPhp()->getConf()), $bearsamppBins->getPhp()->getConf()) . PHP_EOL;
98
99 // Errors log
100 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getPhp()->getErrorLog()) . PHP_EOL;
101 }
102
103 return $resultItems . PHP_EOL . $resultActions;
104 }
105
113 public static function getMenuPhpVersions()
114 {
115 global $bearsamppBins;
116 $items = '';
117 $actions = '';
118
119 foreach ($bearsamppBins->getPhp()->getVersionList() as $version) {
120 $glyph = '';
121 $apachePhpModule = $bearsamppBins->getPhp()->getApacheModule($bearsamppBins->getApache()->getVersion(), $version);
122 if ($apachePhpModule === false) {
124 } elseif ($version == $bearsamppBins->getPhp()->getVersion()) {
125 $glyph = TplAestan::GLYPH_CHECK;
126 }
127
128 $tplSwitchPhpVersion = TplApp::getActionMulti(
129 self::ACTION_SWITCH_VERSION,
130 array($version),
131 array($version, $glyph),
132 false,
133 get_called_class()
134 );
135
136 // Item
137 $items .= $tplSwitchPhpVersion[TplApp::SECTION_CALL] . PHP_EOL;
138
139 // Action
140 $actions .= PHP_EOL . $tplSwitchPhpVersion[TplApp::SECTION_CONTENT];
141 }
142
143 return $items . $actions;
144 }
145
155 public static function getActionEnablePhp($enable)
156 {
157 global $bearsamppBins;
158
159 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getPhp()->getName(), $enable)) . PHP_EOL .
161 }
162
172 public static function getActionSwitchPhpVersion($version)
173 {
174 global $bearsamppBins;
175
176 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getPhp()->getName(), $version)) . PHP_EOL .
178 }
179
187 public static function getMenuPhpSettings()
188 {
189 global $bearsamppBins;
190
191 $menuItems = '';
192 $menuActions = '';
193 foreach ($bearsamppBins->getPhp()->getSettings() as $key => $value) {
194 if (is_array($value)) {
195 $menuItems .= 'Type: submenu; ' .
196 'Caption: "' . $key . '"; ' .
197 'SubMenu: MenuPhpSetting-' . md5($key) . '; ' .
198 'Glyph: ' . TplAestan::GLYPH_FOLDER_CLOSE . PHP_EOL;
199 } else {
200 $glyph = '';
201 $settingEnabled = $bearsamppBins->getPhp()->isSettingActive($value);
202 if (!$bearsamppBins->getPhp()->isSettingExists($value)) {
204 } elseif ($settingEnabled) {
205 $glyph = TplAestan::GLYPH_CHECK;
206 }
207 $tplSwitchPhpSetting = TplApp::getActionMulti(
208 self::ACTION_SWITCH_SETTING,
209 array($value, $settingEnabled),
210 array($key, $glyph),
211 false,
212 get_called_class()
213 );
214
215 $menuItems .= $tplSwitchPhpSetting[TplApp::SECTION_CALL] . PHP_EOL;
216 $menuActions .= $tplSwitchPhpSetting[TplApp::SECTION_CONTENT];
217 }
218 }
219
220 $submenusItems = '';
221 $submenusActions = '';
222 $submenuKeys = self::getSubmenuPhpSettings();
223 foreach ($submenuKeys as $submenuKey) {
224 $submenusItems .= PHP_EOL . '[MenuPhpSetting-' . md5($submenuKey) . ']' .
225 PHP_EOL . self::getSubmenuPhpSettings($submenuKey);
226
227 $submenusActions .= self::getSubmenuPhpSettings($submenuKey, array(), array(), false);
228 }
229
230 return $menuItems . $submenusItems . PHP_EOL . $menuActions . $submenusActions;
231 }
232
245 private static function getSubmenuPhpSettings($passThr = array(), $result = array(), $settings = array(), $sectionCall = true)
246 {
247 global $bearsamppBins;
248 $settings = empty($settings) ? $bearsamppBins->getPhp()->getSettings() : $settings;
249
250 foreach ($settings as $key => $value) {
251 if (is_array($value)) {
252 if (is_array($passThr)) {
253 array_push($result, $key);
254 $result = self::getSubmenuPhpSettings($passThr, $result, $value);
255 } else {
256 $result = is_array($result) ? '' : $result;
257 if ($key == $passThr) {
258 foreach ($value as $key2 => $value2) {
259 if (is_array($value2) && $sectionCall) {
260 $result .= 'Type: submenu; ' .
261 'Caption: "' . $key2 . '"; ' .
262 'SubMenu: MenuPhpSetting-' . md5($key2) . '; ' .
263 'Glyph: ' . TplAestan::GLYPH_FOLDER_CLOSE . PHP_EOL;
264 } elseif (!is_array($value2)) {
265 $glyph = '';
266 $settingEnabled = $bearsamppBins->getPhp()->isSettingActive($value2);
267 if (!$bearsamppBins->getPhp()->isSettingExists($value2)) {
269 } elseif ($settingEnabled) {
270 $glyph = TplAestan::GLYPH_CHECK;
271 }
272 $tplSwitchPhpSetting = TplApp::getActionMulti(
273 self::ACTION_SWITCH_SETTING,
274 array($value2, $settingEnabled),
275 array($key2, $glyph),
276 false,
277 get_called_class()
278 );
279
280 if ($sectionCall) {
281 $result .= $tplSwitchPhpSetting[TplApp::SECTION_CALL] . PHP_EOL;
282 } else {
283 $result .= $tplSwitchPhpSetting[TplApp::SECTION_CONTENT] . PHP_EOL;
284 }
285 }
286 }
287 } else {
288 $result .= self::getSubmenuPhpSettings($passThr, null, $value, $sectionCall);
289 }
290 }
291 }
292 }
293
294 return $result;
295 }
296
305 public static function getActionSwitchPhpSetting($setting, $enabled)
306 {
308
309 return TplApp::getActionRun(Action::SWITCH_PHP_PARAM, array($setting, $switch)) . PHP_EOL .
312 }
313
321 public static function getMenuPhpExtensions()
322 {
323 global $bearsamppBins;
324 $items = '';
325 $actions = '';
326
327 foreach ($bearsamppBins->getPhp()->getExtensions() as $extension => $switch) {
328 $tplSwitchPhpExtension = TplApp::getActionMulti(
329 self::ACTION_SWITCH_EXTENSION,
330 array($extension, $switch),
331 array($extension, ($switch == ActionSwitchPhpExtension::SWITCH_ON ? TplAestan::GLYPH_CHECK : '')),
332 false,
333 get_called_class()
334 );
335
336 // Item
337 $items .= $tplSwitchPhpExtension[TplApp::SECTION_CALL] . PHP_EOL;
338
339 // Action
340 $actions .= PHP_EOL . $tplSwitchPhpExtension[TplApp::SECTION_CONTENT];
341 }
342
343 return $items . $actions;
344 }
345
354 public static function getActionSwitchPhpExtension($extension, $switch)
355 {
357
358 return TplApp::getActionRun(Action::SWITCH_PHP_EXTENSION, array($extension, $switch)) . PHP_EOL .
361 }
362}
363
$result
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION
const SWITCH_PHP_EXTENSION
const SWITCH_PHP_PARAM
const ENABLE
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MENU_ENABLE
const DOWNLOAD_MORE
const PHP
const MENU_ERROR_LOGS
const SETTINGS
const EXTENSIONS
const VERSIONS
const GLYPH_FOLDER_CLOSE
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemSeparator()
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 getMenuPhpSettings()
const ACTION_SWITCH_EXTENSION
static getMenuPhpExtensions()
static getActionSwitchPhpVersion($version)
static getMenuPhpVersions()
static getActionSwitchPhpSetting($setting, $enabled)
const ACTION_SWITCH_SETTING
static getMenuPhp()
const ACTION_SWITCH_VERSION
static getSubmenuPhpSettings($passThr=array(), $result=array(), $settings=array(), $sectionCall=true)
static getActionSwitchPhpExtension($extension, $switch)
static getActionEnablePhp($enable)
static getActionRestart($sName)