Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.action.debugBase.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
19abstract class ActionDebugBase
20{
27 abstract protected function getServiceLangConstant();
28
36 abstract protected function getBinInstance($bearsamppBins);
37
47 abstract protected function getCommandMapping();
48
56 protected function hasContentKey()
57 {
58 return true;
59 }
60
75 public function __construct($args)
76 {
77 global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppWinbinder;
78
79 if (isset($args[0]) && !empty($args[0])) {
80 $editor = false;
81 $msgBoxError = false;
82
83 // Build base caption
84 $serviceLangConstant = $this->getServiceLangConstant();
85 $caption = $bearsamppLang->getValue(Lang::DEBUG) . ' ' .
86 $bearsamppLang->getValue(constant('Lang::' . $serviceLangConstant)) . ' - ';
87
88 // Get command mapping and determine caption suffix and editor flag
89 $commandMapping = $this->getCommandMapping();
90 $command = $args[0];
91
92 if (isset($commandMapping[$command])) {
93 $config = $commandMapping[$command];
94 $caption .= $bearsamppLang->getValue($config['lang']);
95 if (isset($config['editor']) && $config['editor']) {
96 $editor = true;
97 }
98 }
99 $caption .= ' (' . $command . ')';
100
101 // Execute the command and get output
102 $bin = $this->getBinInstance($bearsamppBins);
103 $debugOutput = $bin->getCmdLineOutput($command);
104
105 // Handle syntax check results (if applicable)
106 if ($this->isSyntaxCheckCommand($command)) {
107 if ($this->hasContentKey()) {
108 $msgBoxError = !$debugOutput['syntaxOk'];
109 $debugOutput['content'] = $debugOutput['syntaxOk'] ? 'Syntax OK !' : $debugOutput['content'];
110 }
111 }
112
113 // Extract content based on service type
114 $content = $this->hasContentKey() && is_array($debugOutput) ? $debugOutput['content'] : $debugOutput;
115
116 // Display the output
117 if ($editor) {
118 Util::openFileContent($caption, $content);
119 } else {
120 if ($msgBoxError) {
121 $bearsamppWinbinder->messageBoxError($content, $caption);
122 } else {
123 $bearsamppWinbinder->messageBoxInfo($content, $caption);
124 }
125 }
126 }
127 }
128
136 protected function isSyntaxCheckCommand($command)
137 {
138 $commandMapping = $this->getCommandMapping();
139 if (isset($commandMapping[$command])) {
140 return isset($commandMapping[$command]['syntaxCheck']) && $commandMapping[$command]['syntaxCheck'];
141 }
142 return false;
143 }
144}
global $bearsamppBins
global $bearsamppLang
getBinInstance($bearsamppBins)
const DEBUG
static openFileContent($caption, $content)