Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tool.powershell.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
17{
21 const ROOT_CFG_VERSION = 'powershellVersion';
22
26 const LOCAL_CFG_EXE = 'powershellExe';
30 const LOCAL_CFG_CONF = 'powershellConf';
34 const LOCAL_CFG_LAUNCH_EXE = 'powershellLaunchExe';
38 const LOCAL_CFG_ROWS = 'powershellRows';
42 const LOCAL_CFG_COLS = 'powershellCols';
43
47 private $exe;
51 private $launchExe;
55 private $conf;
59 private $rows;
63 private $cols;
64
71 public function __construct($id, $type)
72 {
73 Log::initClass($this);
74 $this->reload($id, $type);
75 }
76
83 public function reload($id = null, $type = null)
84 {
86 Log::reloadClass($this);
87
88 $this->name = $bearsamppLang->getValue(Lang::POWERSHELL);
89 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
90 parent::reload($id, $type);
91
92 if ($this->bearsamppConfRaw !== false) {
93 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
94 $this->launchExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_LAUNCH_EXE];
95 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
96 $this->rows = intval($this->bearsamppConfRaw[self::LOCAL_CFG_ROWS]);
97 $this->cols = intval($this->bearsamppConfRaw[self::LOCAL_CFG_COLS]);
98 }
99
100 if (!$this->enable) {
101 Log::info($this->name . ' is not enabled!');
102
103 return;
104 }
105 if (!is_dir($this->currentPath)) {
106 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
107 }
108 if (!is_dir($this->symlinkPath)) {
109 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
110
111 return;
112 }
113 if (!is_file($this->bearsamppConf)) {
114 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
115 }
116 if (!is_file($this->exe)) {
117 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
118 }
119 if (!is_file($this->launchExe)) {
120 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->launchExe));
121 }
122 if (!is_file($this->conf)) {
123 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
124 }
125 if (!is_numeric($this->rows) || $this->rows <= 0) {
126 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_ROWS, $this->rows));
127 }
128 if (!is_numeric($this->cols) || $this->cols <= 0) {
129 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_COLS, $this->cols));
130 }
131 }
132
138 public function setVersion($version)
139 {
140 global $bearsamppConfig;
141 $this->version = $version;
142 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
143 $this->reload();
144 }
145
151 public function getExe()
152 {
153 return $this->exe;
154 }
155
161 public function getLaunchExe()
162 {
163 return $this->launchExe;
164 }
165
171 public function getConf()
172 {
173 return $this->conf;
174 }
175
181 public function getRows()
182 {
183 return $this->rows;
184 }
185
191 public function getCols()
192 {
193 return $this->cols;
194 }
195
203 public function getShell($args = null)
204 {
205 if (empty($args)) {
206 return 'cmd /c &quot;' . Path::formatWindowsPath($this->launchExe) . '&quot;';
207 } else {
208 return 'cmd /c &quot;&quot;' . Path::formatWindowsPath($this->getLaunchExe()) . '&quot; &amp; ' . Path::formatWindowsPath($args) . '&quot;';
209 }
210 }
211
217 public function getTabTitleDefault()
218 {
219 return 'Bearsampp PowerShell Console';
220 }
221
227 public function getTabTitlePowershell()
228 {
229 return 'PowerShell';
230 }
231
237 public function getTabTitlePear()
238 {
240
241 return $bearsamppLang->getValue(Lang::PEAR) . ' ' . $bearsamppBins->getPhp()->getPearVersion(true);
242 }
243
249 public function getTabTitleMysql()
250 {
252
253 return $bearsamppLang->getValue(Lang::MYSQL) . ' ' . $bearsamppBins->getMysql()->getVersion();
254 }
255
261 public function getTabTitleMariadb()
262 {
264
265 return $bearsamppLang->getValue(Lang::MARIADB) . ' ' . $bearsamppBins->getMariadb()->getVersion();
266 }
267
273 public function getTabTitlePostgresql()
274 {
276
277 return $bearsamppLang->getValue(Lang::POSTGRESQL) . ' ' . $bearsamppBins->getPostgresql()->getVersion();
278 }
279
287 public function getTabTitleGit($repoPath = null)
288 {
289 global $bearsamppLang, $bearsamppTools;
290 $result = $bearsamppLang->getValue(Lang::GIT) . ' ' . $bearsamppTools->getGit()->getVersion();
291 if ($repoPath != null) {
292 $result .= ' - ' . basename($repoPath);
293 }
294
295 return $result;
296 }
297
303 public function getTabTitleNodejs()
304 {
306
307 return $bearsamppLang->getValue(Lang::NODEJS) . ' ' . $bearsamppBins->getNodejs()->getVersion();
308 }
309
315 public function getTabTitleComposer()
316 {
317 global $bearsamppLang, $bearsamppTools;
318
319 return $bearsamppLang->getValue(Lang::COMPOSER) . ' ' . $bearsamppTools->getComposer()->getVersion();
320 }
321
327 public function getTabTitlePython()
328 {
329 global $bearsamppLang, $bearsamppTools;
330
331 return $bearsamppLang->getValue(Lang::PYTHON) . ' ' . $bearsamppTools->getPython()->getVersion();
332 }
333
339 public function getTabTitleRuby()
340 {
341 global $bearsamppLang, $bearsamppTools;
342
343 return $bearsamppLang->getValue(Lang::RUBY) . ' ' . $bearsamppTools->getRuby()->getVersion();
344 }
345
351 public function getTabTitlePerl()
352 {
353 global $bearsamppLang, $bearsamppTools;
354
355 return $bearsamppLang->getValue(Lang::PERL) . ' ' . $bearsamppTools->getPerl()->getVersion();
356 }
357
363 public function getTabTitleGhostscript()
364 {
365 global $bearsamppLang, $bearsamppTools;
366
367 return $bearsamppLang->getValue(Lang::GHOSTSCRIPT) . ' ' . $bearsamppTools->getGhostscript()->getVersion();
368 }
369
375 public function getTabTitleNgrok()
376 {
377 global $bearsamppLang, $bearsamppTools;
378
379 return $bearsamppLang->getValue(Lang::NGROK) . ' ' . $bearsamppTools->getNgrok()->getVersion();
380 }
381}
382
$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 NGROK
const POSTGRESQL
const POWERSHELL
const PEAR
const GIT
const ERROR_INVALID_PARAMETER
const MYSQL
const PERL
const PYTHON
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static reloadClass($classInstance)
static error($data, $file=null)
static initClass($classInstance)
static formatWindowsPath($path)
getTabTitleGit($repoPath=null)
reload($id=null, $type=null)
global $bearsamppConfig
Definition homepage.php:46