Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.serviceHelper.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
18{
23 private static $serviceMap = null;
24
29 private static $syntaxCheckMap = null;
30
37 private static function initializeMappings($bearsamppBins)
38 {
39 if (self::$serviceMap === null) {
40 self::$serviceMap = [
48 ];
49 }
50
51 if (self::$syntaxCheckMap === null) {
52 self::$syntaxCheckMap = [
56 ];
57 }
58 }
59
67 public static function getBinFromServiceName($serviceName, $bearsamppBins)
68 {
70 return isset(self::$serviceMap[$serviceName]) ? self::$serviceMap[$serviceName] : null;
71 }
72
80 public static function getSyntaxCheckCmd($serviceName, $bearsamppBins = null)
81 {
82 if ($bearsamppBins !== null) {
84 }
85 return isset(self::$syntaxCheckMap[$serviceName]) ? self::$syntaxCheckMap[$serviceName] : null;
86 }
87
95 public static function getServiceDisplayName($bin, $service)
96 {
97 return $bin->getName() . ' ' . $bin->getVersion() . ' (' . $service->getName() . ')';
98 }
99
107 public static function processServices($bearsamppBins, callable $callback)
108 {
110
111 foreach ($bearsamppBins->getServices() as $serviceName => $service) {
112 $bin = self::getBinFromServiceName($serviceName, $bearsamppBins);
113 $syntaxCheckCmd = self::getSyntaxCheckCmd($serviceName);
114
115 if ($bin !== null) {
116 $callback($serviceName, $service, $bin, $syntaxCheckCmd);
117 }
118 }
119 }
120
129 public static function startService($bin, $syntaxCheckCmd = null, $showErrors = true)
130 {
131 return Util::startService($bin, $syntaxCheckCmd, $showErrors);
132 }
133
140 public static function stopService($service)
141 {
142 return $service->stop();
143 }
144
151 public static function restartService($service)
152 {
153 return $service->restart();
154 }
155
173
180 public static function hasSyntaxCheck($serviceName)
181 {
182 if (self::$syntaxCheckMap === null) {
183 // Initialize with dummy bins object if needed
184 self::$syntaxCheckMap = [
188 ];
189 }
190 return isset(self::$syntaxCheckMap[$serviceName]);
191 }
192
200 public static function getServicePort($serviceName, $bearsamppBins)
201 {
202 $bin = self::getBinFromServiceName($serviceName, $bearsamppBins);
203 if ($bin === null) {
204 return 0;
205 }
206
207 // Different services have different methods to get port
208 if (method_exists($bin, 'getPort')) {
209 return $bin->getPort();
210 } elseif (method_exists($bin, 'getSmtpPort')) {
211 return $bin->getSmtpPort();
212 }
213
214 return 0;
215 }
216}
global $bearsamppBins
const CMD_SYNTAX_CHECK
const SERVICE_NAME
const CMD_SYNTAX_CHECK
static getServicePort($serviceName, $bearsamppBins)
static getServiceDisplayName($bin, $service)
static hasSyntaxCheck($serviceName)
static stopService($service)
static restartService($service)
static getSyntaxCheckCmd($serviceName, $bearsamppBins=null)
static startService($bin, $syntaxCheckCmd=null, $showErrors=true)
static processServices($bearsamppBins, callable $callback)
static getBinFromServiceName($serviceName, $bearsamppBins)
static initializeMappings($bearsamppBins)
static startService($bin, $syntaxCheckCmd, $showWindow=false)