Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.service.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
14
class
ActionService
15
{
16
const
CREATE
=
'create'
;
17
const
START
=
'start'
;
18
const
STOP
=
'stop'
;
19
const
RESTART
=
'restart'
;
20
21
const
INSTALL
=
'install'
;
22
const
REMOVE
=
'remove'
;
23
30
public
function
__construct
($args)
31
{
32
global
$bearsamppBins
;
33
Util::startLoading
();
34
35
// Reload bins
36
$bearsamppBins
->reload();
37
38
if
(isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
39
$sName = $args[0];
40
$bin =
null
;
41
$port
= 0;
42
$syntaxCheckCmd =
null
;
43
44
if
($sName ==
BinMailpit::SERVICE_NAME
) {
45
$bin =
$bearsamppBins
->getMailpit();
46
$port
= $bin->getSmtpPort();
47
} elseif ($sName ==
BinMemcached::SERVICE_NAME
) {
48
$bin =
$bearsamppBins
->getMemcached();
49
$port
= $bin->getPort();
50
} elseif ($sName ==
BinApache::SERVICE_NAME
) {
51
$bin =
$bearsamppBins
->getApache();
52
$port
= $bin->getPort();
53
$syntaxCheckCmd =
BinApache::CMD_SYNTAX_CHECK
;
54
} elseif ($sName ==
BinMysql::SERVICE_NAME
) {
55
$bin =
$bearsamppBins
->getMysql();
56
$port
= $bin->getPort();
57
$syntaxCheckCmd =
BinMysql::CMD_SYNTAX_CHECK
;
58
} elseif ($sName ==
BinMariadb::SERVICE_NAME
) {
59
$bin =
$bearsamppBins
->getMariadb();
60
$port
= $bin->getPort();
61
$syntaxCheckCmd =
BinMariadb::CMD_SYNTAX_CHECK
;
62
} elseif ($sName ==
BinPostgresql::SERVICE_NAME
) {
63
$bin =
$bearsamppBins
->getPostgresql();
64
$port
= $bin->getPort();
65
} elseif ($sName ==
BinXlight::SERVICE_NAME
) {
66
$bin =
$bearsamppBins
->getXlight();
67
$port
= $bin->getPort();
68
}
69
70
$name = $bin->getName();
71
$service = $bin->getService();
72
73
if
(!empty($service) && $service instanceof
Win32Service
) {
74
if
($args[1] == self::CREATE) {
75
$this->
create
($service);
76
} elseif ($args[1] == self::START) {
77
$this->
start
($bin, $syntaxCheckCmd);
78
} elseif ($args[1] == self::STOP) {
79
$this->
stop
($service);
80
} elseif ($args[1] == self::RESTART) {
81
$this->
restart
($bin, $syntaxCheckCmd);
82
} elseif ($args[1] == self::INSTALL) {
83
if
(!empty(
$port
)) {
84
$this->
install
($bin,
$port
, $syntaxCheckCmd);
85
}
86
} elseif ($args[1] == self::REMOVE) {
87
$this->
remove
($service, $name);
88
}
89
}
90
}
91
92
Util::stopLoading
();
93
}
94
100
private
function
create
($service)
101
{
102
$service->create();
103
}
104
111
private
function
start
($bin, $syntaxCheckCmd)
112
{
113
// Update loading screen to show which service is starting
114
Util::updateLoadingText
(
'Starting '
. $bin->getName() .
'...'
);
115
116
ServiceHelper::startService
($bin, $syntaxCheckCmd,
true
);
117
}
118
124
private
function
stop
($service)
125
{
126
// Update loading screen to show which service is stopping
127
Util::updateLoadingText
(
'Stopping '
. $service->getName() .
'...'
);
128
129
$service->stop();
130
}
131
138
private
function
restart
($bin, $syntaxCheckCmd)
139
{
140
// Update loading screen to show service is restarting
141
Util::updateLoadingText
(
'Restarting '
. $bin->getName() .
'...'
);
142
143
if
($bin->getService()->stop()) {
144
$this->
start
($bin, $syntaxCheckCmd);
145
}
146
}
147
155
private
function
install
($bin,
$port
, $syntaxCheckCmd)
156
{
157
ServiceHelper::installService
($bin,
$port
, $syntaxCheckCmd,
true
);
158
}
159
166
private
function
remove
($service, $name)
167
{
168
ServiceHelper::removeService
($service, $name);
169
}
170
}
171
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$port
$port
Definition
ajax.apache.php:34
ActionService
Definition
class.action.service.php:15
ActionService\REMOVE
const REMOVE
Definition
class.action.service.php:22
ActionService\start
start($bin, $syntaxCheckCmd)
Definition
class.action.service.php:111
ActionService\STOP
const STOP
Definition
class.action.service.php:18
ActionService\__construct
__construct($args)
Definition
class.action.service.php:30
ActionService\restart
restart($bin, $syntaxCheckCmd)
Definition
class.action.service.php:138
ActionService\INSTALL
const INSTALL
Definition
class.action.service.php:21
ActionService\stop
stop($service)
Definition
class.action.service.php:124
ActionService\START
const START
Definition
class.action.service.php:17
ActionService\RESTART
const RESTART
Definition
class.action.service.php:19
ActionService\CREATE
const CREATE
Definition
class.action.service.php:16
ActionService\install
install($bin, $port, $syntaxCheckCmd)
Definition
class.action.service.php:155
ActionService\create
create($service)
Definition
class.action.service.php:100
BinApache\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.apache.php:22
BinApache\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.apache.php:85
BinMailpit\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mailpit.php:22
BinMariadb\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mariadb.php:21
BinMariadb\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.mariadb.php:72
BinMemcached\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.memcached.php:21
BinMysql\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mysql.php:21
BinMysql\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.mysql.php:72
BinPostgresql\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.postgresql.php:21
BinXlight\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.xlight.php:22
ServiceHelper\installService
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
Definition
class.servicehelper.php:227
ServiceHelper\removeService
static removeService($service, $name)
Definition
class.servicehelper.php:310
ServiceHelper\startService
static startService($bin, $syntaxCheckCmd=null, $showWindow=false)
Definition
class.servicehelper.php:139
Util\startLoading
static startLoading()
Definition
class.util.php:540
Util\stopLoading
static stopLoading()
Definition
class.util.php:562
Util\updateLoadingText
static updateLoadingText($text)
Definition
class.util.php:585
Win32Service
Definition
class.win32service.php:18
sandbox
core
classes
actions
class.action.service.php
Generated by
1.17.0