Bearsampp 2025.8.29
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
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
38 public function __construct($id, $type) {
39 Util::logInitClass($this);
40 $this->reload($id, $type);
41 }
42
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
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
113 public function getExe() {
114 return $this->exe;
115 }
116
122 public function getLaunchExe() {
123 return $this->launchExe;
124 }
125
131 public function getConf() {
132 return $this->conf;
133 }
134
140 public function getRows() {
141 return $this->rows;
142 }
143
149 public function getCols() {
150 return $this->cols;
151 }
152
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
172 public function getTabTitleDefault() {
173 global $bearsamppLang;
174 return $bearsamppLang->getValue(Lang::CONSOLE);
175 }
176
182 public function getTabTitlePowershell() {
183 return 'PowerShell';
184 }
185
191 public function getTabTitlePear() {
193 return $bearsamppLang->getValue(Lang::PEAR) . ' ' . $bearsamppBins->getPhp()->getPearVersion(true);
194 }
195
201 public function getTabTitleMysql() {
203 return $bearsamppLang->getValue(Lang::MYSQL) . ' ' . $bearsamppBins->getMysql()->getVersion();
204 }
205
211 public function getTabTitleMariadb() {
213 return $bearsamppLang->getValue(Lang::MARIADB) . ' ' . $bearsamppBins->getMariadb()->getVersion();
214 }
215
221 public function getTabTitlePostgresql() {
223 return $bearsamppLang->getValue(Lang::POSTGRESQL) . ' ' . $bearsamppBins->getPostgresql()->getVersion();
224 }
225
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
246 public function getTabTitleNodejs() {
248 return $bearsamppLang->getValue(Lang::NODEJS) . ' ' . $bearsamppBins->getNodejs()->getVersion();
249 }
250
256 public function getTabTitleComposer() {
257 global $bearsamppLang, $bearsamppTools;
258 return $bearsamppLang->getValue(Lang::COMPOSER) . ' ' . $bearsamppTools->getComposer()->getVersion();
259 }
260
266 public function getTabTitlePython() {
267 global $bearsamppLang, $bearsamppTools;
268 return $bearsamppLang->getValue(Lang::PYTHON) . ' ' . $bearsamppTools->getPython()->getVersion();
269 }
270
276 public function getTabTitleRuby() {
277 global $bearsamppLang, $bearsamppTools;
278 return $bearsamppLang->getValue(Lang::RUBY) . ' ' . $bearsamppTools->getRuby()->getVersion();
279 }
280
286 public function getTabTitlePerl() {
287 global $bearsamppLang, $bearsamppTools;
288 return $bearsamppLang->getValue(Lang::PERL) . ' ' . $bearsamppTools->getPerl()->getVersion();
289 }
290
296 public function getTabTitleGhostscript() {
297 global $bearsamppLang, $bearsamppTools;
298 return $bearsamppLang->getValue(Lang::GHOSTSCRIPT) . ' ' . $bearsamppTools->getGhostscript()->getVersion();
299 }
300
306 public function getTabTitleNgrok() {
307 global $bearsamppLang, $bearsamppTools;
308 return $bearsamppLang->getValue(Lang::NGROK) . ' ' . $bearsamppTools->getNgrok()->getVersion();
309 }
310}
$result
global $bearsamppBins
global $bearsamppLang
const COMPOSER
const MARIADB
const NODEJS
const GHOSTSCRIPT
const RUBY
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const CONSOLE
const NGROK
const POSTGRESQL
const PEAR
const GIT
const ERROR_INVALID_PARAMETER
const MYSQL
const PERL
const PYTHON
const ERROR_FILE_NOT_FOUND
const CONSOLEZ
getTabTitleGit($repoPath=null)
reload($id=null, $type=null)
__construct($id, $type)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
static logReloadClass($classInstance)
static formatWindowsPath($path)
global $bearsamppConfig
Definition homepage.php:27