Bearsampp
2026.7.11
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-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
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
}
48
elseif ( $sName ==
BinMemcached::SERVICE_NAME
) {
49
$bin =
$bearsamppBins
->getMemcached();
50
$port
= $bin->getPort();
51
}
52
elseif ( $sName ==
BinApache::SERVICE_NAME
) {
53
$bin =
$bearsamppBins
->getApache();
54
$port
= $bin->getPort();
55
$syntaxCheckCmd =
BinApache::CMD_SYNTAX_CHECK
;
56
}
57
elseif ( $sName ==
BinMysql::SERVICE_NAME
) {
58
$bin =
$bearsamppBins
->getMysql();
59
$port
= $bin->getPort();
60
$syntaxCheckCmd =
BinMysql::CMD_SYNTAX_CHECK
;
61
}
62
elseif ( $sName ==
BinMariadb::SERVICE_NAME
) {
63
$bin =
$bearsamppBins
->getMariadb();
64
$port
= $bin->getPort();
65
$syntaxCheckCmd =
BinMariadb::CMD_SYNTAX_CHECK
;
66
}
67
elseif ( $sName ==
BinPostgresql::SERVICE_NAME
) {
68
$bin =
$bearsamppBins
->getPostgresql();
69
$port
= $bin->getPort();
70
}
71
elseif ( $sName ==
BinXlight::SERVICE_NAME
) {
72
$bin =
$bearsamppBins
->getXlight();
73
$port
= $bin->getPort();
74
}
75
76
$name = $bin->getName();
77
$service = $bin->getService();
78
79
if
( !empty( $service ) && $service instanceof
Win32Service
) {
80
if
( $args[1] == self::CREATE ) {
81
$this->
create
( $service );
82
}
83
elseif ( $args[1] == self::START ) {
84
$this->
start
( $bin, $syntaxCheckCmd );
85
}
86
elseif ( $args[1] == self::STOP ) {
87
$this->
stop
( $service );
88
}
89
elseif ( $args[1] == self::RESTART ) {
90
$this->
restart
( $bin, $syntaxCheckCmd );
91
}
92
elseif ( $args[1] == self::INSTALL ) {
93
if
( !empty(
$port
) ) {
94
$this->
install
( $bin,
$port
, $syntaxCheckCmd );
95
}
96
}
97
elseif ( $args[1] == self::REMOVE ) {
98
$this->
remove
( $service, $name );
99
}
100
}
101
}
102
103
Util::stopLoading
();
104
}
105
111
private
function
create
($service)
112
{
113
$service->create();
114
}
115
122
private
function
start
($bin, $syntaxCheckCmd)
123
{
124
// Update loading screen to show which service is starting
125
Util::updateLoadingText
(
'Starting '
. $bin->getName() .
'...'
);
126
127
Util::startService
( $bin, $syntaxCheckCmd,
true
);
128
}
129
135
private
function
stop
($service)
136
{
137
// Update loading screen to show which service is stopping
138
Util::updateLoadingText
(
'Stopping '
. $service->getName() .
'...'
);
139
140
$service->stop();
141
}
142
149
private
function
restart
($bin, $syntaxCheckCmd)
150
{
151
// Update loading screen to show service is restarting
152
Util::updateLoadingText
(
'Restarting '
. $bin->getName() .
'...'
);
153
154
if
( $bin->getService()->stop() ) {
155
$this->
start
( $bin, $syntaxCheckCmd );
156
}
157
}
158
166
private
function
install
($bin,
$port
, $syntaxCheckCmd)
167
{
168
Util::installService
( $bin,
$port
, $syntaxCheckCmd,
true
);
169
}
170
177
private
function
remove
($service, $name)
178
{
179
Util::removeService
( $service, $name );
180
}
181
}
182
$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:122
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:149
ActionService\INSTALL
const INSTALL
Definition
class.action.service.php:21
ActionService\stop
stop($service)
Definition
class.action.service.php:135
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:166
ActionService\create
create($service)
Definition
class.action.service.php:111
BinApache\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.apache.php:19
BinApache\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.apache.php:37
BinMailpit\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mailpit.php:19
BinMariadb\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mariadb.php:18
BinMariadb\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.mariadb.php:33
BinMemcached\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.memcached.php:18
BinMysql\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.mysql.php:18
BinMysql\CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
Definition
class.bin.mysql.php:33
BinPostgresql\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.postgresql.php:18
BinXlight\SERVICE_NAME
const SERVICE_NAME
Definition
class.bin.xlight.php:19
Util\installService
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
Definition
class.util.php:1248
Util\removeService
static removeService($service, $name)
Definition
class.util.php:1331
Util\startLoading
static startLoading()
Definition
class.util.php:530
Util\stopLoading
static stopLoading()
Definition
class.util.php:550
Util\startService
static startService($bin, $syntaxCheckCmd, $showWindow=false)
Definition
class.util.php:1365
Util\updateLoadingText
static updateLoadingText($text)
Definition
class.util.php:571
Win32Service
Definition
class.win32service.php:18
sandbox
core
classes
actions
class.action.service.php
Generated by
1.17.0