Bearsampp
2026.7.11
Toggle main menu visibility
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
16
class
ToolPowerShell
extends
Module
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
Log::initClass
($this);
40
$this->
reload
(
$id
,
$type
);
41
}
42
49
public
function
reload
(
$id
=
null
,
$type
=
null
) {
50
global
$bearsamppConfig
,
$bearsamppLang
;
51
Log::reloadClass
($this);
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
Log::info
($this->name .
' is not enabled!'
);
67
return
;
68
}
69
if
(!is_dir($this->currentPath)) {
70
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->currentPath));
71
}
72
if
(!is_dir($this->symlinkPath)) {
73
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->symlinkPath));
74
return
;
75
}
76
if
(!is_file($this->bearsamppConf)) {
77
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_CONF_NOT_FOUND
), $this->name .
' '
. $this->version, $this->bearsamppConf));
78
}
79
if
(!is_file($this->exe)) {
80
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_EXE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->exe));
81
}
82
if
(!is_file($this->launchExe)) {
83
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_EXE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->launchExe));
84
}
85
if
(!is_file($this->conf)) {
86
Log::error
(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
Log::error
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_INVALID_PARAMETER
), self::LOCAL_CFG_ROWS, $this->rows));
90
}
91
if
(!is_numeric($this->cols) || $this->cols <= 0) {
92
Log::error
(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 /c "'
.
Path::formatWindowsPath
($this->launchExe) .
'"'
;
162
}
else
{
163
return
'cmd /c ""'
.
Path::formatWindowsPath
($this->
getLaunchExe
()) .
'" & '
.
Path::formatWindowsPath
($args) .
'"'
;
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
() {
191
global
$bearsamppLang
,
$bearsamppBins
;
192
return
$bearsamppLang
->getValue(
Lang::PEAR
) .
' '
.
$bearsamppBins
->getPhp()->getPearVersion(
true
);
193
}
194
200
public
function
getTabTitleMysql
() {
201
global
$bearsamppLang
,
$bearsamppBins
;
202
return
$bearsamppLang
->getValue(
Lang::MYSQL
) .
' '
.
$bearsamppBins
->getMysql()->getVersion();
203
}
204
210
public
function
getTabTitleMariadb
() {
211
global
$bearsamppLang
,
$bearsamppBins
;
212
return
$bearsamppLang
->getValue(
Lang::MARIADB
) .
' '
.
$bearsamppBins
->getMariadb()->getVersion();
213
}
214
220
public
function
getTabTitlePostgresql
() {
221
global
$bearsamppLang
,
$bearsamppBins
;
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
() {
246
global
$bearsamppLang
,
$bearsamppBins
;
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
}
310
$result
$result
Definition
ajax.apache.php:19
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
Lang\COMPOSER
const COMPOSER
Definition
class.lang.php:143
Lang\MARIADB
const MARIADB
Definition
class.lang.php:131
Lang\NODEJS
const NODEJS
Definition
class.lang.php:133
Lang\GHOSTSCRIPT
const GHOSTSCRIPT
Definition
class.lang.php:145
Lang\RUBY
const RUBY
Definition
class.lang.php:150
Lang\ERROR_EXE_NOT_FOUND
const ERROR_EXE_NOT_FOUND
Definition
class.lang.php:154
Lang\ERROR_CONF_NOT_FOUND
const ERROR_CONF_NOT_FOUND
Definition
class.lang.php:153
Lang\NGROK
const NGROK
Definition
class.lang.php:147
Lang\POSTGRESQL
const POSTGRESQL
Definition
class.lang.php:134
Lang\POWERSHELL
const POWERSHELL
Definition
class.lang.php:144
Lang\PEAR
const PEAR
Definition
class.lang.php:128
Lang\GIT
const GIT
Definition
class.lang.php:146
Lang\ERROR_INVALID_PARAMETER
const ERROR_INVALID_PARAMETER
Definition
class.lang.php:156
Lang\MYSQL
const MYSQL
Definition
class.lang.php:132
Lang\PERL
const PERL
Definition
class.lang.php:148
Lang\PYTHON
const PYTHON
Definition
class.lang.php:149
Lang\ERROR_FILE_NOT_FOUND
const ERROR_FILE_NOT_FOUND
Definition
class.lang.php:155
Log\info
static info($data, $file=null)
Definition
class.log.php:627
Log\reloadClass
static reloadClass($classInstance)
Definition
class.log.php:670
Log\error
static error($data, $file=null)
Definition
class.log.php:650
Log\initClass
static initClass($classInstance)
Definition
class.log.php:660
Module
Definition
class.module.php:15
Module\$version
$version
Definition
class.module.php:24
Module\$type
$type
Definition
class.module.php:20
Module\$id
$id
Definition
class.module.php:21
Path\formatWindowsPath
static formatWindowsPath($path)
Definition
class.path.php:118
ToolPowerShell
Definition
class.tool.powershell.php:17
ToolPowerShell\getTabTitlePerl
getTabTitlePerl()
Definition
class.tool.powershell.php:285
ToolPowerShell\getExe
getExe()
Definition
class.tool.powershell.php:113
ToolPowerShell\getTabTitleRuby
getTabTitleRuby()
Definition
class.tool.powershell.php:275
ToolPowerShell\LOCAL_CFG_EXE
const LOCAL_CFG_EXE
Definition
class.tool.powershell.php:20
ToolPowerShell\getTabTitleNodejs
getTabTitleNodejs()
Definition
class.tool.powershell.php:245
ToolPowerShell\getTabTitleGit
getTabTitleGit($repoPath=null)
Definition
class.tool.powershell.php:231
ToolPowerShell\getTabTitleComposer
getTabTitleComposer()
Definition
class.tool.powershell.php:255
ToolPowerShell\getTabTitlePowershell
getTabTitlePowershell()
Definition
class.tool.powershell.php:181
ToolPowerShell\getTabTitleDefault
getTabTitleDefault()
Definition
class.tool.powershell.php:172
ToolPowerShell\setVersion
setVersion($version)
Definition
class.tool.powershell.php:101
ToolPowerShell\getTabTitlePostgresql
getTabTitlePostgresql()
Definition
class.tool.powershell.php:220
ToolPowerShell\getTabTitleMariadb
getTabTitleMariadb()
Definition
class.tool.powershell.php:210
ToolPowerShell\LOCAL_CFG_CONF
const LOCAL_CFG_CONF
Definition
class.tool.powershell.php:21
ToolPowerShell\getTabTitlePear
getTabTitlePear()
Definition
class.tool.powershell.php:190
ToolPowerShell\$cols
$cols
Definition
class.tool.powershell.php:30
ToolPowerShell\LOCAL_CFG_COLS
const LOCAL_CFG_COLS
Definition
class.tool.powershell.php:24
ToolPowerShell\getConf
getConf()
Definition
class.tool.powershell.php:131
ToolPowerShell\LOCAL_CFG_ROWS
const LOCAL_CFG_ROWS
Definition
class.tool.powershell.php:23
ToolPowerShell\getTabTitlePython
getTabTitlePython()
Definition
class.tool.powershell.php:265
ToolPowerShell\reload
reload($id=null, $type=null)
Definition
class.tool.powershell.php:49
ToolPowerShell\$rows
$rows
Definition
class.tool.powershell.php:29
ToolPowerShell\ROOT_CFG_VERSION
const ROOT_CFG_VERSION
Definition
class.tool.powershell.php:18
ToolPowerShell\__construct
__construct($id, $type)
Definition
class.tool.powershell.php:38
ToolPowerShell\$exe
$exe
Definition
class.tool.powershell.php:26
ToolPowerShell\getRows
getRows()
Definition
class.tool.powershell.php:140
ToolPowerShell\getTabTitleGhostscript
getTabTitleGhostscript()
Definition
class.tool.powershell.php:295
ToolPowerShell\getTabTitleNgrok
getTabTitleNgrok()
Definition
class.tool.powershell.php:305
ToolPowerShell\$launchExe
$launchExe
Definition
class.tool.powershell.php:27
ToolPowerShell\$conf
$conf
Definition
class.tool.powershell.php:28
ToolPowerShell\getShell
getShell($args=null)
Definition
class.tool.powershell.php:159
ToolPowerShell\getTabTitleMysql
getTabTitleMysql()
Definition
class.tool.powershell.php:200
ToolPowerShell\getLaunchExe
getLaunchExe()
Definition
class.tool.powershell.php:122
ToolPowerShell\LOCAL_CFG_LAUNCH_EXE
const LOCAL_CFG_LAUNCH_EXE
Definition
class.tool.powershell.php:22
ToolPowerShell\getCols
getCols()
Definition
class.tool.powershell.php:149
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:41
sandbox
core
classes
tools
class.tool.powershell.php
Generated by
1.17.0