Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.action.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
13class Action
14{
15 // Constants for different actions
16 const ABOUT = 'about';
17 const ADD_ALIAS = 'addAlias';
18 const ADD_VHOST = 'addVhost';
19 const CHANGE_BROWSER = 'changeBrowser';
20 const CHANGE_DB_ROOT_PWD = 'changeDbRootPwd';
21 const CHANGE_PORT = 'changePort';
22 const CHECK_PORT = 'checkPort';
23 const CHECK_VERSION = 'checkVersion';
24 const CLEAR_FOLDERS = 'clearFolders';
25 const DEBUG_APACHE = 'debugApache';
26 const DEBUG_MARIADB = 'debugMariadb';
27 const DEBUG_MYSQL = 'debugMysql';
28 const DEBUG_POSTGRESQL = 'debugPostgresql';
29 const EDIT_ALIAS = 'editAlias';
30 const EDIT_VHOST = 'editVhost';
31 const ENABLE = 'enable';
32 const EXEC = 'exec';
33 const GEN_SSL_CERTIFICATE = 'genSslCertificate';
34 const LAUNCH_STARTUP = 'launchStartup';
35 const MANUAL_RESTART = 'manualRestart';
36 const LOADING = 'loading';
37 const QUIT = 'quit';
38 const REBUILD_INI = 'rebuildIni';
39 const REFRESH_REPOS = 'refreshRepos';
40 const REFRESH_REPOS_STARTUP = 'refreshReposStartup';
41 const RELOAD = 'reload';
42 const RESTART = 'restart';
43 const SERVICE = 'service';
44 const STARTUP = 'startup';
45 const SWITCH_APACHE_MODULE = 'switchApacheModule';
46 const SWITCH_LANG = 'switchLang';
47 const SWITCH_LOGS_VERBOSE = 'switchLogsVerbose';
48 const SWITCH_PHP_EXTENSION = 'switchPhpExtension';
49 const SWITCH_PHP_PARAM = 'switchPhpParam';
50 const SWITCH_ONLINE = 'switchOnline';
51 const SWITCH_VERSION = 'switchVersion';
52
53 const EXT = 'ext';
54
58 private $current;
59
64 public function __construct()
65 {
66 // Initialization code can be added here if needed
67 }
68
78 public function process()
79 {
80 if ($this->exists()) {
81 $action = Util::cleanArgv(1);
82 $actionClass = 'Action' . ucfirst($action);
83
84 $args = array();
85 foreach ($_SERVER['argv'] as $key => $arg) {
86 if ($key > 1) {
87 $args[] = $action == self::EXT ? $arg : base64_decode($arg);
88 }
89 }
90
91 $this->current = null;
92 if (class_exists($actionClass)) {
93 Util::logDebug('Start ' . $actionClass);
94 $this->current = new $actionClass($args);
95 }
96 }
97 }
98
110 public function call($actionName, $actionArgs = null)
111 {
112 $actionClass = 'Action' . ucfirst($actionName);
113 if (class_exists($actionClass)) {
114 Util::logDebug('Start ' . $actionClass);
115 new $actionClass($actionArgs);
116 }
117 }
118
127 public function exists()
128 {
129 return isset($_SERVER['argv'])
130 && isset($_SERVER['argv'][1])
131 && !empty($_SERVER['argv'][1]);
132 }
133}
const ADD_ALIAS
const DEBUG_APACHE
const QUIT
const SWITCH_VERSION
const EDIT_VHOST
const MANUAL_RESTART
const DEBUG_MARIADB
const SWITCH_LOGS_VERBOSE
const CHANGE_DB_ROOT_PWD
const DEBUG_MYSQL
const SERVICE
const REBUILD_INI
const CHECK_VERSION
const CHANGE_PORT
const LOADING
call($actionName, $actionArgs=null)
const LAUNCH_STARTUP
const RELOAD
const ABOUT
const EDIT_ALIAS
const SWITCH_PHP_EXTENSION
const EXEC
const STARTUP
const ADD_VHOST
const RESTART
const REFRESH_REPOS
const REFRESH_REPOS_STARTUP
const DEBUG_POSTGRESQL
const SWITCH_PHP_PARAM
const GEN_SSL_CERTIFICATE
const CHECK_PORT
const CHANGE_BROWSER
const CLEAR_FOLDERS
const EXT
const SWITCH_ONLINE
const SWITCH_LANG
const SWITCH_APACHE_MODULE
const ENABLE
static cleanArgv($name, $type='text')
static logDebug($data, $file=null)