Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.tool.powershell.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
17{
18 const ROOT_CFG_VERSION = 'powershellVersion';
19
20 const LOCAL_CFG_EXE = 'powershellExe';
21 const LOCAL_CFG_CONF = 'powershellConf';
22 const LOCAL_CFG_LAUNCH_EXE = 'powershellLaunchExe';
23 const LOCAL_CFG_ROWS = 'powershellRows';
24 const LOCAL_CFG_COLS = 'powershellCols';
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::POWERSHELL);
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 return 'Bearsampp Powershell Console';
174 }
175
181 public function getTabTitlePowershell() {
182 return 'PowerShell';
183 }
184
190 public function getTabTitlePear() {
192 return $bearsamppLang->getValue(Lang::PEAR) . ' ' . $bearsamppBins->getPhp()->getPearVersion(true);
193 }
194
200 public function getTabTitleMysql() {
202 return $bearsamppLang->getValue(Lang::MYSQL) . ' ' . $bearsamppBins->getMysql()->getVersion();
203 }
204
210 public function getTabTitleMariadb() {
212 return $bearsamppLang->getValue(Lang::MARIADB) . ' ' . $bearsamppBins->getMariadb()->getVersion();
213 }
214
220 public function getTabTitlePostgresql() {
222 return $bearsamppLang->getValue(Lang::POSTGRESQL) . ' ' . $bearsamppBins->getPostgresql()->getVersion();
223 }
224
231 public function getTabTitleGit($repoPath = null) {
232 global $bearsamppLang, $bearsamppTools;
233 $result = $bearsamppLang->getValue(Lang::GIT) . ' ' . $bearsamppTools->getGit()->getVersion();
234 if ($repoPath != null) {
235 $result .= ' - ' . basename($repoPath);
236 }
237 return $result;
238 }
239
245 public function getTabTitleNodejs() {
247 return $bearsamppLang->getValue(Lang::NODEJS) . ' ' . $bearsamppBins->getNodejs()->getVersion();
248 }
249
255 public function getTabTitleComposer() {
256 global $bearsamppLang, $bearsamppTools;
257 return $bearsamppLang->getValue(Lang::COMPOSER) . ' ' . $bearsamppTools->getComposer()->getVersion();
258 }
259
265 public function getTabTitlePython() {
266 global $bearsamppLang, $bearsamppTools;
267 return $bearsamppLang->getValue(Lang::PYTHON) . ' ' . $bearsamppTools->getPython()->getVersion();
268 }
269
275 public function getTabTitleRuby() {
276 global $bearsamppLang, $bearsamppTools;
277 return $bearsamppLang->getValue(Lang::RUBY) . ' ' . $bearsamppTools->getRuby()->getVersion();
278 }
279
285 public function getTabTitlePerl() {
286 global $bearsamppLang, $bearsamppTools;
287 return $bearsamppLang->getValue(Lang::PERL) . ' ' . $bearsamppTools->getPerl()->getVersion();
288 }
289
295 public function getTabTitleGhostscript() {
296 global $bearsamppLang, $bearsamppTools;
297 return $bearsamppLang->getValue(Lang::GHOSTSCRIPT) . ' ' . $bearsamppTools->getGhostscript()->getVersion();
298 }
299
305 public function getTabTitleNgrok() {
306 global $bearsamppLang, $bearsamppTools;
307 return $bearsamppLang->getValue(Lang::NGROK) . ' ' . $bearsamppTools->getNgrok()->getVersion();
308 }
309}
$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
getTabTitleGit($repoPath=null)
reload($id=null, $type=null)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
static logReloadClass($classInstance)
static formatWindowsPath($path)
global $bearsamppConfig
Definition homepage.php:41