2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.services.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
10/**
11 * Class TplAppServices
12 *
13 * This class provides methods to generate menu items and actions for managing multiple services
14 * within the Bearsampp application. It includes functionalities for starting, stopping, and restarting
15 * all services at once.
16 */
18{
19 // Constants for action identifiers
20 const ACTION_START = 'startServices';
21 const ACTION_STOP = 'stopServices';
22 const ACTION_RESTART = 'restartServices';
23
24 /**
25 * Generates the main services menu with options to start, stop, and restart all services.
26 *
27 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
28 *
29 * @return array An array containing the generated menu items and actions for services.
30 */
31 public static function process()
32 {
33 global $bearsamppLang;
34
35 $tplStart = TplApp::getActionMulti(
36 self::ACTION_START, null,
38 false, get_called_class()
39 );
40
41 $tplStop = TplApp::getActionMulti(
42 self::ACTION_STOP, null,
44 false, get_called_class()
45 );
46
47 $tplRestart = TplApp::getActionMulti(
48 self::ACTION_RESTART, null,
50 false, get_called_class()
51 );
52
53 // Items
54 $items = $tplStart[TplApp::SECTION_CALL] . PHP_EOL .
55 $tplStop[TplApp::SECTION_CALL] . PHP_EOL .
56 $tplRestart[TplApp::SECTION_CALL] . PHP_EOL;
57
58 // Actions
59 $actions = PHP_EOL . $tplStart[TplApp::SECTION_CONTENT] .
60 PHP_EOL . $tplStop[TplApp::SECTION_CONTENT] .
61 PHP_EOL . $tplRestart[TplApp::SECTION_CONTENT];
62
63 return array($items, $actions);
64 }
65
66 /**
67 * Generates the actions to start all services.
68 *
69 * @global object $bearsamppBins Provides access to system binaries and their configurations.
70 *
71 * @return string The generated actions to start all services.
72 */
73 public static function getActionStartServices()
74 {
75 global $bearsamppBins;
76 $actions = '';
77
78 foreach ($bearsamppBins->getServices() as $sName => $service) {
79 $actions .= TplService::getActionStart($service->getName()) . PHP_EOL;
80 }
81
82 return $actions;
83 }
84
85 /**
86 * Generates the actions to stop all services.
87 *
88 * @global object $bearsamppBins Provides access to system binaries and their configurations.
89 *
90 * @return string The generated actions to stop all services.
91 */
92 public static function getActionStopServices()
93 {
94 global $bearsamppBins;
95 $actions = '';
96
97 foreach ($bearsamppBins->getServices() as $sName => $service) {
98 $actions .= TplService::getActionStop($service->getName()) . PHP_EOL;
99 }
100
101 return $actions;
102 }
103
104 /**
105 * Generates the actions to restart all services by stopping and then starting them.
106 *
107 * @return string The generated actions to restart all services.
108 */
109 public static function getActionRestartServices()
110 {
112 }
113}
global $bearsamppBins
global $bearsamppLang
const MENU_START_SERVICES
const MENU_RESTART_SERVICES
const MENU_STOP_SERVICES
const GLYPH_SERVICES_START
const GLYPH_SERVICES_STOP
const GLYPH_SERVICES_RESTART
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
const SECTION_CONTENT
static getActionStart($sName)
static getActionStop($sName)