Bearsampp 2026.3.26
API documentation
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 RESTART_ALL_SERVICES = 'restartAllServices';
44 const SERVICE = 'service';
45 const START_ALL_SERVICES = 'startAllServices';
46 const STARTUP = 'startup';
47 const STOP_ALL_SERVICES = 'stopAllServices';
48 const SWITCH_APACHE_MODULE = 'switchApacheModule';
49 const SWITCH_LANG = 'switchLang';
50 const SWITCH_LOGS_VERBOSE = 'switchLogsVerbose';
51 const SWITCH_PHP_EXTENSION = 'switchPhpExtension';
52 const SWITCH_PHP_PARAM = 'switchPhpParam';
53 const SWITCH_ONLINE = 'switchOnline';
54 const SWITCH_VERSION = 'switchVersion';
55
56 const EXT = 'ext';
57
61 private $current;
62
67 public function __construct()
68 {
69 // Initialization code can be added here if needed
70 }
71
81 public function process()
82 {
83 if ($this->exists()) {
84 $action = Util::cleanArgv(1);
85 $actionClass = 'Action' . ucfirst($action);
86
87 $args = array();
88 foreach ($_SERVER['argv'] as $key => $arg) {
89 if ($key > 1) {
90 $args[] = $action == self::EXT ? $arg : base64_decode($arg);
91 }
92 }
93
94 $this->current = null;
95 if (class_exists($actionClass)) {
96 Util::logDebug('Start ' . $actionClass);
97 $this->current = new $actionClass($args);
98 }
99 }
100 }
101
113 public function call($actionName, $actionArgs = null)
114 {
115 $actionClass = 'Action' . ucfirst($actionName);
116 if (class_exists($actionClass)) {
117 Util::logDebug('Start ' . $actionClass);
118 new $actionClass($actionArgs);
119 }
120 }
121
130 public function exists()
131 {
132 return isset($_SERVER['argv'])
133 && isset($_SERVER['argv'][1])
134 && !empty($_SERVER['argv'][1]);
135 }
136}
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 STOP_ALL_SERVICES
const START_ALL_SERVICES
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 RESTART_ALL_SERVICES
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)