Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ActionChangePort Class Reference

Public Member Functions

 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)

Private Attributes

 $bin
 $cntProcessActions
 $currentPort
 $wbBtnCancel
 $wbBtnFinish
 $wbInputPort
 $wbLabelCurrent
 $wbLabelPort
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionChangePort Handles the process of changing the port for various services in the Bearsampp application.

Definition at line 14 of file class.action.changePort.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

ActionChangePort constructor. Initializes the port change process for the specified service.

Parameters
array$argsThe arguments passed to the constructor, where the first element specifies the service name.

Definition at line 47 of file class.action.changePort.php.

48 {
49 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
50
51 if (isset($args[0]) && !empty($args[0])) {
52 $bin = $bearsamppBins->getBinByName($args[0]);
53 if ($bin !== null) {
54 $this->bin = $bin;
55 // Mailpit exposes an SMTP port separately; all other services use getPort()
56 $this->currentPort = ($args[0] == $bearsamppBins->getMailpit()->getName())
57 ? $bin->getSmtpPort()
58 : $bin->getPort();
59 } else {
60 $this->bin = $bearsamppBins->getApache();
61 $this->currentPort = $bearsamppBins->getApache()->getPort();
62 }
63 $this->cntProcessActions = 3;
64
65 $bearsamppWinbinder->reset();
66 $this->wbWindow = $bearsamppWinbinder->createAppWindow(
67 sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_TITLE), $args[0]),
68 380,
69 170,
70 WBC_NOTIFY,
71 WBC_KEYDOWN | WBC_KEYUP
72 );
73
74 $this->wbLabelCurrent = $bearsamppWinbinder->createLabel(
75 $this->wbWindow,
76 sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_CURRENT_LABEL), $args[0], $this->currentPort),
77 15,
78 15,
79 350
80 );
81
82 $this->wbLabelPort = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_PORT_NEW_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
83 $this->wbInputPort = $bearsamppWinbinder->createInputText($this->wbWindow, $this->currentPort, 105, 43, 50, null, 5, WBC_NUMBER);
84
85 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, $this->cntProcessActions + 1, 15, 107, 170);
86 $this->wbBtnFinish = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_FINISH), 190, 102);
87 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 277, 102);
88
89 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
90 $bearsamppWinbinder->setFocus($this->wbInputPort[WinBinder::CTRL_OBJ]);
91 $bearsamppWinbinder->mainLoop();
92 $bearsamppWinbinder->reset();
93 }
94 }
global $bearsamppBins
global $bearsamppLang
const BUTTON_CANCEL
const CHANGE_PORT_CURRENT_LABEL
const CHANGE_PORT_TITLE
const CHANGE_PORT_NEW_LABEL
const BUTTON_FINISH

References $bearsamppBins, $bearsamppLang, $bin, Lang\BUTTON_CANCEL, Lang\BUTTON_FINISH, Lang\CHANGE_PORT_CURRENT_LABEL, Lang\CHANGE_PORT_NEW_LABEL, Lang\CHANGE_PORT_TITLE, and WinBinder\CTRL_OBJ.

Member Function Documentation

◆ processWindow()

processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes window events and handles user interactions.

Parameters
mixed$windowThe window object.
int$idThe control ID.
mixed$ctrlThe control object.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.

Definition at line 105 of file class.action.changePort.php.

106 {
107 global $bearsamppLang, $bearsamppWinbinder;
108 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_TITLE), $this->bin);
109 $port = $bearsamppWinbinder->getText($this->wbInputPort[WinBinder::CTRL_OBJ]);
110
111 switch ($id) {
112 case $this->wbInputPort[WinBinder::CTRL_ID]:
113 $bearsamppWinbinder->setEnabled($this->wbBtnFinish[WinBinder::CTRL_OBJ], empty($port) ? false : true);
114 break;
115 case $this->wbBtnFinish[WinBinder::CTRL_ID]:
116 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
117 if ($port == $this->currentPort) {
118 $bearsamppWinbinder->messageBoxWarning($bearsamppLang->getValue(Lang::CHANGE_PORT_SAME_ERROR), $boxTitle);
119 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
120 break;
121 }
122 $changePort = $this->bin->changePort($port, true, $this->wbProgressBar);
123 if ($changePort === true) {
124 Util::updateLoadingText('Restarting ' . $this->bin->getName() . '...');
125 $this->bin->getService()->restart();
126
127 // Rebuild tray/menu links (including localhost URL) with the new port values.
128 $menuContent = TplApp::process();
129 if ($menuContent !== false) {
130 file_put_contents(Path::getIniFilePath(), Util::utf8ToCp1252($menuContent));
131 }
132
133 $bearsamppWinbinder->messageBoxInfo(
134 sprintf($bearsamppLang->getValue(Lang::PORT_CHANGED), $this->bin, $port),
135 $boxTitle
136 );
137 $bearsamppWinbinder->destroyWindow($window);
138 } else {
139 $bearsamppWinbinder->messageBoxError(
140 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port, $changePort),
141 $boxTitle
142 );
143 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
144 }
145 break;
146 case IDCLOSE:
147 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
148 $bearsamppWinbinder->destroyWindow($window);
149 break;
150 }
151 }
$port
const CHANGE_PORT_SAME_ERROR
const PORT_CHANGED
const PORT_NOT_USED_BY
static getIniFilePath($aetrayPath=false)
static process()
static utf8ToCp1252($data)
static updateLoadingText($text)

References $bearsamppLang, $port, Lang\CHANGE_PORT_SAME_ERROR, Lang\CHANGE_PORT_TITLE, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Path\getIniFilePath(), Lang\PORT_CHANGED, Lang\PORT_NOT_USED_BY, TplApp\process(), Util\updateLoadingText(), and Util\utf8ToCp1252().

Here is the call graph for this function:

Field Documentation

◆ $bin

$bin
private

Definition at line 17 of file class.action.changePort.php.

Referenced by __construct().

◆ $cntProcessActions

$cntProcessActions
private

Definition at line 21 of file class.action.changePort.php.

◆ $currentPort

$currentPort
private

Definition at line 19 of file class.action.changePort.php.

◆ $wbBtnCancel

$wbBtnCancel
private

Definition at line 39 of file class.action.changePort.php.

◆ $wbBtnFinish

$wbBtnFinish
private

Definition at line 37 of file class.action.changePort.php.

◆ $wbInputPort

$wbInputPort
private

Definition at line 32 of file class.action.changePort.php.

◆ $wbLabelCurrent

$wbLabelCurrent
private

Definition at line 27 of file class.action.changePort.php.

◆ $wbLabelPort

$wbLabelPort
private

Definition at line 30 of file class.action.changePort.php.

◆ $wbProgressBar

$wbProgressBar
private

Definition at line 35 of file class.action.changePort.php.

◆ $wbWindow

$wbWindow
private

Definition at line 24 of file class.action.changePort.php.


The documentation for this class was generated from the following file: