2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.php.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
11{
12 const MENU = 'php';
13 const MENU_VERSIONS = 'phpVersions';
14 const MENU_SETTINGS = 'phpSettings';
15 const MENU_EXTENSIONS = 'phpExtensions';
16
17 const ACTION_ENABLE = 'enablePhp';
18 const ACTION_SWITCH_VERSION = 'switchPhpVersion';
19 const ACTION_SWITCH_SETTING = 'switchPhpSetting';
20 const ACTION_SWITCH_EXTENSION = 'switchPhpExtension';
21
22 /**
23 * Processes the PHP menu and returns the menu items and actions.
24 *
25 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
26 * @global object $bearsamppBins Provides access to system binaries and their configurations.
27 *
28 * @return array The generated menu items and actions for the PHP menu.
29 */
30 public static function process()
31 {
33
34 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::PHP), self::MENU, get_called_class(), $bearsamppBins->getPhp()->isEnable());
35 }
36
37 /**
38 * Generates the PHP menu items and actions.
39 *
40 * @global object $bearsamppBins Provides access to system binaries and their configurations.
41 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
42 *
43 * @return string The generated PHP menu items and actions.
44 */
45 public static function getMenuPhp()
46 {
48 $resultItems = $resultActions = '';
49
50 $isEnabled = $bearsamppBins->getPhp()->isEnable();
51
52 // Download
54 Util::getWebsiteUrl('module/php', '#releases'),
55 false,
57 ) . PHP_EOL;
58
59 // Enable
60 $tplEnable = TplApp::getActionMulti(
61 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
62 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
63 false, get_called_class()
64 );
65 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
66 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
67
68 if ($isEnabled) {
69 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
70
71 // Versions
72 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
73 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
74 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
75
76 // Settings
77 $tplSettings = TplApp::getMenu($bearsamppLang->getValue(Lang::SETTINGS), self::MENU_SETTINGS, get_called_class());
78 $resultItems .= $tplSettings[TplApp::SECTION_CALL] . PHP_EOL;
79 $resultActions .= $tplSettings[TplApp::SECTION_CONTENT] . PHP_EOL;
80
81 // Extensions
82 $tplExtensions = TplApp::getMenu($bearsamppLang->getValue(Lang::EXTENSIONS), self::MENU_EXTENSIONS, get_called_class());
83 $resultItems .= $tplExtensions[TplApp::SECTION_CALL] . PHP_EOL;
84 $resultActions .= $tplExtensions[TplApp::SECTION_CONTENT];
85
86 // Conf
87 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getPhp()->getConf()), $bearsamppBins->getPhp()->getConf()) . PHP_EOL;
88
89 // Errors log
90 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getPhp()->getErrorLog()) . PHP_EOL;
91 }
92
93 return $resultItems . PHP_EOL . $resultActions;
94 }
95
96 /**
97 * Generates the PHP versions menu items and actions.
98 *
99 * @global object $bearsamppBins Provides access to system binaries and their configurations.
100 *
101 * @return string The generated PHP versions menu items and actions.
102 */
103 public static function getMenuPhpVersions()
104 {
105 global $bearsamppBins;
106 $items = '';
107 $actions = '';
108
109 foreach ($bearsamppBins->getPhp()->getVersionList() as $version) {
110 $glyph = '';
111 $apachePhpModule = $bearsamppBins->getPhp()->getApacheModule($bearsamppBins->getApache()->getVersion(), $version);
112 if ($apachePhpModule === false) {
114 } elseif ($version == $bearsamppBins->getPhp()->getVersion()) {
115 $glyph = TplAestan::GLYPH_CHECK;
116 }
117
118 $tplSwitchPhpVersion = TplApp::getActionMulti(
119 self::ACTION_SWITCH_VERSION, array($version),
120 array($version, $glyph),
121 false, get_called_class()
122 );
123
124 // Item
125 $items .= $tplSwitchPhpVersion[TplApp::SECTION_CALL] . PHP_EOL;
126
127 // Action
128 $actions .= PHP_EOL . $tplSwitchPhpVersion[TplApp::SECTION_CONTENT];
129 }
130
131 return $items . $actions;
132 }
133
134 /**
135 * Generates the action to enable or disable PHP.
136 *
137 * @global object $bearsamppBins Provides access to system binaries and their configurations.
138 *
139 * @param int $enable The enable flag (1 to enable, 0 to disable).
140 *
141 * @return string The generated action string to enable or disable PHP.
142 */
143 public static function getActionEnablePhp($enable)
144 {
145 global $bearsamppBins;
146
147 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getPhp()->getName(), $enable)) . PHP_EOL .
149 }
150
151 /**
152 * Generates the action to switch the PHP version.
153 *
154 * @global object $bearsamppBins Provides access to system binaries and their configurations.
155 *
156 * @param string $version The PHP version to switch to.
157 *
158 * @return string The generated action string to switch the PHP version.
159 */
160 public static function getActionSwitchPhpVersion($version)
161 {
162 global $bearsamppBins;
163
164 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getPhp()->getName(), $version)) . PHP_EOL .
166 }
167
168 /**
169 * Generates the PHP settings menu items and actions.
170 *
171 * @global object $bearsamppBins Provides access to system binaries and their configurations.
172 *
173 * @return string The generated PHP settings menu items and actions.
174 */
175 public static function getMenuPhpSettings()
176 {
177 global $bearsamppBins;
178
179 $menuItems = '';
180 $menuActions = '';
181 foreach ($bearsamppBins->getPhp()->getSettings() as $key => $value) {
182 if (is_array($value)) {
183 $menuItems .= 'Type: submenu; ' .
184 'Caption: "' . $key . '"; ' .
185 'SubMenu: MenuPhpSetting-' . md5($key) . '; ' .
186 'Glyph: ' . TplAestan::GLYPH_FOLDER_CLOSE . PHP_EOL;
187 } else {
188 $glyph = '';
189 $settingEnabled = $bearsamppBins->getPhp()->isSettingActive($value);
190 if (!$bearsamppBins->getPhp()->isSettingExists($value)) {
192 } elseif ($settingEnabled) {
193 $glyph = TplAestan::GLYPH_CHECK;
194 }
195 $tplSwitchPhpSetting = TplApp::getActionMulti(
196 self::ACTION_SWITCH_SETTING, array($value, $settingEnabled),
197 array($key, $glyph),
198 false, get_called_class()
199 );
200
201 $menuItems .= $tplSwitchPhpSetting[TplApp::SECTION_CALL] . PHP_EOL;
202 $menuActions .= $tplSwitchPhpSetting[TplApp::SECTION_CONTENT];
203 }
204 }
205
206 $submenusItems = '';
207 $submenusActions = '';
208 $submenuKeys = self::getSubmenuPhpSettings();
209 foreach ($submenuKeys as $submenuKey) {
210 $submenusItems .= PHP_EOL . '[MenuPhpSetting-' . md5($submenuKey) . ']' .
211 PHP_EOL . self::getSubmenuPhpSettings($submenuKey);
212
213 $submenusActions .= self::getSubmenuPhpSettings($submenuKey, array(), array(), false);
214 }
215
216 return $menuItems . $submenusItems . PHP_EOL . $menuActions . $submenusActions;
217 }
218
219 /**
220 * Generates the submenu items and actions for PHP settings.
221 *
222 * @global object $bearsamppBins Provides access to system binaries and their configurations.
223 *
224 * @param array $passThr The pass-through array for nested settings.
225 * @param array $result The result array to store submenu items.
226 * @param array $settings The settings array to process.
227 * @param bool $sectionCall Whether to generate section calls or content.
228 *
229 * @return string The generated submenu items and actions for PHP settings.
230 */
231 private static function getSubmenuPhpSettings($passThr = array(), $result = array(), $settings = array(), $sectionCall = true)
232 {
233 global $bearsamppBins;
234 $settings = empty($settings) ? $bearsamppBins->getPhp()->getSettings() : $settings;
235
236 foreach ($settings as $key => $value) {
237 if (is_array($value)) {
238 if (is_array($passThr)) {
239 array_push($result, $key);
240 $result = self::getSubmenuPhpSettings($passThr, $result, $value);
241 } else {
242 $result = is_array($result) ? '' : $result;
243 if ($key == $passThr) {
244 foreach ($value as $key2 => $value2) {
245 if (is_array($value2) && $sectionCall) {
246 $result .= 'Type: submenu; ' .
247 'Caption: "' . $key2 . '"; ' .
248 'SubMenu: MenuPhpSetting-' . md5($key2) . '; ' .
249 'Glyph: ' . TplAestan::GLYPH_FOLDER_CLOSE . PHP_EOL;
250 } elseif (!is_array($value2)) {
251 $glyph = '';
252 $settingEnabled = $bearsamppBins->getPhp()->isSettingActive($value2);
253 if (!$bearsamppBins->getPhp()->isSettingExists($value2)) {
255 } elseif ($settingEnabled) {
256 $glyph = TplAestan::GLYPH_CHECK;
257 }
258 $tplSwitchPhpSetting = TplApp::getActionMulti(
259 self::ACTION_SWITCH_SETTING, array($value2, $settingEnabled),
260 array($key2, $glyph),
261 false, get_called_class()
262 );
263
264 if ($sectionCall) {
265 $result .= $tplSwitchPhpSetting[TplApp::SECTION_CALL] . PHP_EOL;
266 } else {
267 $result .= $tplSwitchPhpSetting[TplApp::SECTION_CONTENT] . PHP_EOL;
268 }
269 }
270 }
271 } else {
272 $result .= self::getSubmenuPhpSettings($passThr, null, $value, $sectionCall);
273 }
274 }
275 }
276 }
277
278 return $result;
279 }
280
281 /**
282 * Generates the action to switch a PHP setting.
283 *
284 * @param string $setting The PHP setting to switch.
285 * @param bool $enabled The current state of the setting (true if enabled, false otherwise).
286 *
287 * @return string The generated action string to switch the PHP setting.
288 */
289 public static function getActionSwitchPhpSetting($setting, $enabled)
290 {
292 return TplApp::getActionRun(Action::SWITCH_PHP_PARAM, array($setting, $switch)) . PHP_EOL .
295 }
296
297 /**
298 * Generates the PHP extensions menu items and actions.
299 *
300 * @global object $bearsamppBins Provides access to system binaries and their configurations.
301 *
302 * @return string The generated PHP extensions menu items and actions.
303 */
304 public static function getMenuPhpExtensions()
305 {
306 global $bearsamppBins;
307 $items = '';
308 $actions = '';
309
310 foreach ($bearsamppBins->getPhp()->getExtensions() as $extension => $switch) {
311 $tplSwitchPhpExtension = TplApp::getActionMulti(
312 self::ACTION_SWITCH_EXTENSION, array($extension, $switch),
313 array($extension, ($switch == ActionSwitchPhpExtension::SWITCH_ON ? TplAestan::GLYPH_CHECK : '')),
314 false, get_called_class()
315 );
316
317 // Item
318 $items .= $tplSwitchPhpExtension[TplApp::SECTION_CALL] . PHP_EOL;
319
320 // Action
321 $actions .= PHP_EOL . $tplSwitchPhpExtension[TplApp::SECTION_CONTENT];
322 }
323
324 return $items . $actions;
325 }
326
327 /**
328 * Generates the action to switch a PHP extension.
329 *
330 * @param string $extension The PHP extension to switch.
331 * @param string $switch The current state of the extension (on or off).
332 *
333 * @return string The generated action string to switch the PHP extension.
334 */
335 public static function getActionSwitchPhpExtension($extension, $switch)
336 {
338 return TplApp::getActionRun(Action::SWITCH_PHP_EXTENSION, array($extension, $switch)) . PHP_EOL .
341 }
342}
$result
global $bearsamppBins
global $bearsamppLang
const SWITCH_PHP_PARAM
const ENABLE
const SWITCH_VERSION
const SWITCH_PHP_EXTENSION
const DISABLED
const ENABLED
const MENU_ERROR_LOGS
const VERSIONS
const MENU_ENABLE
const DOWNLOAD_MORE
const EXTENSIONS
const PHP
const SETTINGS
const GLYPH_FOLDER_CLOSE
static getItemSeparator()
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getMenuPhpExtensions()
static getMenuPhpSettings()
static getMenuPhp()
static getSubmenuPhpSettings($passThr=array(), $result=array(), $settings=array(), $sectionCall=true)
static getActionSwitchPhpSetting($setting, $enabled)
const ACTION_SWITCH_VERSION
const ACTION_SWITCH_SETTING
static getActionSwitchPhpVersion($version)
static getActionEnablePhp($enable)
static getMenuPhpVersions()
const ACTION_SWITCH_EXTENSION
static getActionSwitchPhpExtension($extension, $switch)
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 getActionRestart($sName)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)