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