2024.8.23
Loading...
Searching...
No Matches
class.tool.consolez.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 ToolConsoleZ
12 *
13 * This class represents the ConsoleZ tool in the Bearsampp application.
14 * It extends the Module class and provides functionalities specific to ConsoleZ.
15 */
16class ToolConsoleZ extends Module
17{
18 const ROOT_CFG_VERSION = 'consolezVersion';
19
20 const LOCAL_CFG_EXE = 'consolezExe';
21 const LOCAL_CFG_CONF = 'consolezConf';
22 const LOCAL_CFG_LAUNCH_EXE = 'consolezLaunchExe';
23 const LOCAL_CFG_ROWS = 'consolezRows';
24 const LOCAL_CFG_COLS = 'consolezCols';
25
26 private $exe;
27 private $launchExe;
28 private $conf;
29 private $rows;
30 private $cols;
31
32 /**
33 * Constructor for the ToolConsoleZ class.
34 *
35 * @param string $id The ID of the module.
36 * @param string $type The type of the module.
37 */
38 public function __construct($id, $type) {
39 Util::logInitClass($this);
40 $this->reload($id, $type);
41 }
42
43 /**
44 * Reloads the configuration for the ConsoleZ tool.
45 *
46 * @param string|null $id The ID of the module. If null, the current ID is used.
47 * @param string|null $type The type of the module. If null, the current type is used.
48 */
49 public function reload($id = null, $type = null) {
52
53 $this->name = $bearsamppLang->getValue(Lang::CONSOLEZ);
54 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
55 parent::reload($id, $type);
56
57 if ($this->bearsamppConfRaw !== false) {
58 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
59 $this->launchExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_LAUNCH_EXE];
60 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
61 $this->rows = intval($this->bearsamppConfRaw[self::LOCAL_CFG_ROWS]);
62 $this->cols = intval($this->bearsamppConfRaw[self::LOCAL_CFG_COLS]);
63 }
64
65 if (!$this->enable) {
66 Util::logInfo($this->name . ' is not enabled!');
67 return;
68 }
69 if (!is_dir($this->currentPath)) {
70 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
71 }
72 if (!is_dir($this->symlinkPath)) {
73 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
74 return;
75 }
76 if (!is_file($this->bearsamppConf)) {
77 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
78 }
79 if (!is_file($this->exe)) {
80 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
81 }
82 if (!is_file($this->launchExe)) {
83 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->launchExe));
84 }
85 if (!is_file($this->conf)) {
86 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
87 }
88 if (!is_numeric($this->rows) || $this->rows <= 0) {
89 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_ROWS, $this->rows));
90 }
91 if (!is_numeric($this->cols) || $this->cols <= 0) {
92 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_COLS, $this->cols));
93 }
94 }
95
96 /**
97 * Sets the version of the ConsoleZ tool.
98 *
99 * @param string $version The version to set.
100 */
101 public function setVersion($version) {
102 global $bearsamppConfig;
103 $this->version = $version;
104 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
105 $this->reload();
106 }
107
108 /**
109 * Gets the executable path for ConsoleZ.
110 *
111 * @return string The executable path.
112 */
113 public function getExe() {
114 return $this->exe;
115 }
116
117 /**
118 * Gets the launch executable path for ConsoleZ.
119 *
120 * @return string The launch executable path.
121 */
122 public function getLaunchExe() {
123 return $this->launchExe;
124 }
125
126 /**
127 * Gets the configuration file path for ConsoleZ.
128 *
129 * @return string The configuration file path.
130 */
131 public function getConf() {
132 return $this->conf;
133 }
134
135 /**
136 * Gets the number of rows for the ConsoleZ window.
137 *
138 * @return int The number of rows.
139 */
140 public function getRows() {
141 return $this->rows;
142 }
143
144 /**
145 * Gets the number of columns for the ConsoleZ window.
146 *
147 * @return int The number of columns.
148 */
149 public function getCols() {
150 return $this->cols;
151 }
152
153 /**
154 * Gets the shell command to launch ConsoleZ.
155 *
156 * @param string|null $args Additional arguments for the shell command.
157 * @return string The shell command.
158 */
159 public function getShell($args = null) {
160 if (empty($args)) {
161 return 'cmd /k &quot;' . Util::formatWindowsPath($this->launchExe) . '&quot;';
162 } else {
163 return 'cmd /k &quot;&quot;' . Util::formatWindowsPath($this->getLaunchExe()) . '&quot; &amp; ' . Util::formatWindowsPath($args) . '&quot;';
164 }
165 }
166
167 /**
168 * Gets the default tab title for ConsoleZ.
169 *
170 * @return string The default tab title.
171 */
172 public function getTabTitleDefault() {
173 global $bearsamppLang;
174 return $bearsamppLang->getValue(Lang::CONSOLE);
175 }
176
177 /**
178 * Gets the tab title for PowerShell.
179 *
180 * @return string The tab title for PowerShell.
181 */
182 public function getTabTitlePowershell() {
183 return 'PowerShell';
184 }
185
186 /**
187 * Gets the tab title for PEAR.
188 *
189 * @return string The tab title for PEAR.
190 */
191 public function getTabTitlePear() {
193 return $bearsamppLang->getValue(Lang::PEAR) . ' ' . $bearsamppBins->getPhp()->getPearVersion(true);
194 }
195
196 /**
197 * Gets the tab title for MySQL.
198 *
199 * @return string The tab title for MySQL.
200 */
201 public function getTabTitleMysql() {
203 return $bearsamppLang->getValue(Lang::MYSQL) . ' ' . $bearsamppBins->getMysql()->getVersion();
204 }
205
206 /**
207 * Gets the tab title for MariaDB.
208 *
209 * @return string The tab title for MariaDB.
210 */
211 public function getTabTitleMariadb() {
213 return $bearsamppLang->getValue(Lang::MARIADB) . ' ' . $bearsamppBins->getMariadb()->getVersion();
214 }
215
216 /**
217 * Gets the tab title for PostgreSQL.
218 *
219 * @return string The tab title for PostgreSQL.
220 */
221 public function getTabTitlePostgresql() {
223 return $bearsamppLang->getValue(Lang::POSTGRESQL) . ' ' . $bearsamppBins->getPostgresql()->getVersion();
224 }
225
226 /**
227 * Gets the tab title for Git.
228 *
229 * @param string|null $repoPath The repository path.
230 * @return string The tab title for Git.
231 */
232 public function getTabTitleGit($repoPath = null) {
233 global $bearsamppLang, $bearsamppTools;
234 $result = $bearsamppLang->getValue(Lang::GIT) . ' ' . $bearsamppTools->getGit()->getVersion();
235 if ($repoPath != null) {
236 $result .= ' - ' . basename($repoPath);
237 }
238 return $result;
239 }
240
241 /**
242 * Gets the tab title for Node.js.
243 *
244 * @return string The tab title for Node.js.
245 */
246 public function getTabTitleNodejs() {
248 return $bearsamppLang->getValue(Lang::NODEJS) . ' ' . $bearsamppBins->getNodejs()->getVersion();
249 }
250
251 /**
252 * Gets the tab title for Composer.
253 *
254 * @return string The tab title for Composer.
255 */
256 public function getTabTitleComposer() {
257 global $bearsamppLang, $bearsamppTools;
258 return $bearsamppLang->getValue(Lang::COMPOSER) . ' ' . $bearsamppTools->getComposer()->getVersion();
259 }
260
261 /**
262 * Gets the tab title for Python.
263 *
264 * @return string The tab title for Python.
265 */
266 public function getTabTitlePython() {
267 global $bearsamppLang, $bearsamppTools;
268 return $bearsamppLang->getValue(Lang::PYTHON) . ' ' . $bearsamppTools->getPython()->getVersion();
269 }
270
271 /**
272 * Gets the tab title for Ruby.
273 *
274 * @return string The tab title for Ruby.
275 */
276 public function getTabTitleRuby() {
277 global $bearsamppLang, $bearsamppTools;
278 return $bearsamppLang->getValue(Lang::RUBY) . ' ' . $bearsamppTools->getRuby()->getVersion();
279 }
280
281 /**
282 * Gets the tab title for Yarn.
283 *
284 * @return string The tab title for Yarn.
285 */
286 public function getTabTitleYarn() {
287 global $bearsamppLang, $bearsamppTools;
288 return $bearsamppLang->getValue(Lang::YARN) . ' ' . $bearsamppTools->getYarn()->getVersion();
289 }
290
291 /**
292 * Gets the tab title for Perl.
293 *
294 * @return string The tab title for Perl.
295 */
296 public function getTabTitlePerl() {
297 global $bearsamppLang, $bearsamppTools;
298 return $bearsamppLang->getValue(Lang::PERL) . ' ' . $bearsamppTools->getPerl()->getVersion();
299 }
300
301 /**
302 * Gets the tab title for Ghostscript.
303 *
304 * @return string The tab title for Ghostscript.
305 */
306 public function getTabTitleGhostscript() {
307 global $bearsamppLang, $bearsamppTools;
308 return $bearsamppLang->getValue(Lang::GHOSTSCRIPT) . ' ' . $bearsamppTools->getGhostscript()->getVersion();
309 }
310
311 /**
312 * Gets the tab title for Ngrok.
313 *
314 * @return string The tab title for Ngrok.
315 */
316 public function getTabTitleNgrok() {
317 global $bearsamppLang, $bearsamppTools;
318 return $bearsamppLang->getValue(Lang::NGROK) . ' ' . $bearsamppTools->getNgrok()->getVersion();
319 }
320}
$result
global $bearsamppBins
global $bearsamppLang
const PYTHON
const RUBY
const CONSOLEZ
const MYSQL
const ERROR_FILE_NOT_FOUND
const YARN
const NGROK
const COMPOSER
const NODEJS
const MARIADB
const PEAR
const ERROR_INVALID_PARAMETER
const GIT
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const GHOSTSCRIPT
const PERL
const POSTGRESQL
const CONSOLE
getTabTitleGit($repoPath=null)
reload($id=null, $type=null)
__construct($id, $type)
static logReloadClass($classInstance)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
static formatWindowsPath($path)
global $bearsamppConfig
Definition homepage.php:26