Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ActionAddVhost Class Reference
Inheritance diagram for ActionAddVhost:

Protected Member Functions

 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)
Protected Member Functions inherited from ActionDialogBase
 createButtons ($bearsamppWinbinder)
 getGaugeDelete ()
 getGaugeSave ()
 handleDelete ($window)
 handleSave ($window)
 initializeDialog ($args)
 isEditMode ()

Private Attributes

 $wbBtnDocRoot
 $wbInputDocRoot
 $wbInputServerName
 $wbLabelDocRoot
 $wbLabelExp
 $wbLabelServerName

Additional Inherited Members

Public Member Functions inherited from ActionDialogBase
 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)
Data Fields inherited from ActionDialogBase
const GAUGE_DELETE = 2
const GAUGE_SAVE = 2
Protected Attributes inherited from ActionDialogBase
 $initValue
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnSave
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionAddVhost Handles the creation of a new virtual host (vhost) in the Bearsampp application.

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

Member Function Documentation

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
protected

Create form fields specific to the dialog This method should create all input fields, labels, and buttons

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 41 of file class.action.addVhost.php.

42 {
44
45 $initServerName = 'test.local';
46 $initDocumentRoot = Util::formatWindowsPath($bearsamppRoot->getWwwPath()) . '\\' . $initServerName;
47
48 $this->wbLabelServerName = $bearsamppWinbinder->createLabel(
49 $this->wbWindow,
51 15, 15, 85, null, WBC_RIGHT
52 );
53 $this->wbInputServerName = $bearsamppWinbinder->createInputText(
54 $this->wbWindow,
55 $initServerName,
56 105, 13, 150, null
57 );
58
59 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel(
60 $this->wbWindow,
62 15, 45, 85, null, WBC_RIGHT
63 );
64 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText(
65 $this->wbWindow,
66 $initDocumentRoot,
67 105, 43, 190, null, null, WBC_READONLY
68 );
69 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton(
70 $this->wbWindow,
72 300, 43, 110
73 );
74
75 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
76 $this->wbWindow,
77 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $initServerName, $initDocumentRoot),
78 15, 80, 470, 50
79 );
80 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
const VHOST_DOCUMENT_ROOT_LABEL
static formatWindowsPath($path)

References $bearsamppLang, $bearsamppRoot, Lang\BUTTON_BROWSE, Util\formatWindowsPath(), Lang\VHOST_DOCUMENT_ROOT_LABEL, Lang\VHOST_EXP_LABEL, and Lang\VHOST_SERVER_NAME_LABEL.

◆ deleteItem()

deleteItem ( )
protected

Delete the item

Returns
bool True on success, false on failure

Reimplemented from ActionDialogBase.

Definition at line 135 of file class.action.addVhost.php.

136 {
137 // Not used in add mode
138 return false;
139 }

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get delete confirmation message

Returns
string The confirmation message

Reimplemented from ActionDialogBase.

Definition at line 158 of file class.action.addVhost.php.

159 {
160 // Not used in add mode
161 return '';
162 }

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title

Returns
string The delete dialog title

Reimplemented from ActionDialogBase.

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

36 {
37 // Not used in add mode
38 return '';
39 }

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get error message after delete failure

Returns
string The error message

Reimplemented from ActionDialogBase.

Definition at line 170 of file class.action.addVhost.php.

171 {
172 // Not used in add mode
173 return '';
174 }

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get success message after delete

Returns
string The success message

Reimplemented from ActionDialogBase.

Definition at line 164 of file class.action.addVhost.php.

165 {
166 // Not used in add mode
167 return '';
168 }

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for messages

Returns
string The dialog title

Reimplemented from ActionDialogBase.

Definition at line 29 of file class.action.addVhost.php.

30 {
31 global $bearsamppLang;
32 return $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE);
33 }
const ADD_VHOST_TITLE

References $bearsamppLang, and Lang\ADD_VHOST_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
array Associative array of form values

Reimplemented from ActionDialogBase.

Definition at line 82 of file class.action.addVhost.php.

83 {
84 return [
85 'serverName' => $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]),
86 'documentRoot' => $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ])
87 ];
88 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get error message after save failure

Returns
string The error message

Reimplemented from ActionDialogBase.

Definition at line 152 of file class.action.addVhost.php.

153 {
154 global $bearsamppLang;
156 }
const VHOST_CREATED_ERROR

References $bearsamppLang, and Lang\VHOST_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get success message after save

Parameters
array$valuesThe form values
Returns
string The success message

Reimplemented from ActionDialogBase.

Definition at line 141 of file class.action.addVhost.php.

142 {
143 global $bearsamppLang;
144 return sprintf(
146 $values['serverName'],
147 $values['serverName'],
148 $values['documentRoot']
149 );
150 }
const VHOST_CREATED

References $bearsamppLang, and Lang\VHOST_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title

Returns
string The window title

Reimplemented from ActionDialogBase.

Definition at line 23 of file class.action.addVhost.php.

24 {
25 global $bearsamppLang;
26 return $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE);
27 }

References $bearsamppLang, and Lang\ADD_VHOST_TITLE.

◆ handleCustomEvent()

handleCustomEvent ( $window,
$id,
$ctrl,
$param1,
$param2 )
protected

Handle custom events (can be overridden by child classes)

Parameters
resource$windowThe window resource
int$idThe control ID
resource$ctrlThe control resource
mixed$param1Additional parameter 1
mixed$param2Additional parameter 2
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 182 of file class.action.addVhost.php.

183 {
184 global $bearsamppLang, $bearsamppWinbinder;
185
186 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
187 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
188
189 // Handle server name input change
190 if ($id == $this->wbInputServerName[WinBinder::CTRL_ID]) {
191 $bearsamppWinbinder->setText(
192 $this->wbLabelExp[WinBinder::CTRL_OBJ],
193 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
194 );
195 $bearsamppWinbinder->setEnabled(
196 $this->wbBtnSave[WinBinder::CTRL_OBJ],
197 !empty($serverName)
198 );
199 }
200
201 // Handle browse button
202 if ($id == $this->wbBtnDocRoot[WinBinder::CTRL_ID]) {
203 $documentRoot = $bearsamppWinbinder->sysDlgPath(
204 $window,
206 $documentRoot
207 );
208 if ($documentRoot && is_dir($documentRoot)) {
209 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
210 $bearsamppWinbinder->setText(
211 $this->wbLabelExp[WinBinder::CTRL_OBJ],
212 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
213 );
214 }
215 }
216 }
const VHOST_DOC_ROOT_PATH

References $bearsamppLang, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Lang\VHOST_DOC_ROOT_PATH, and Lang\VHOST_EXP_LABEL.

◆ itemExists()

itemExists ( $values)
protected

Check if the item already exists (for add/edit operations)

Parameters
array$valuesThe form values
Returns
bool True if exists, false otherwise

Reimplemented from ActionDialogBase.

Definition at line 104 of file class.action.addVhost.php.

105 {
106 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
107
108 if (is_file($bearsamppRoot->getVhostsPath() . '/' . $values['serverName'] . '.conf')) {
109 $bearsamppWinbinder->messageBoxError(
110 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $values['serverName']),
111 $this->getDialogTitle()
112 );
113 return true;
114 }
115
116 return false;
117 }
const VHOST_ALREADY_EXISTS

References $bearsamppLang, $bearsamppRoot, and Lang\VHOST_ALREADY_EXISTS.

◆ restartService()

restartService ( )
protected

Restart the service after save/delete

Returns
void

Reimplemented from ActionDialogBase.

Definition at line 176 of file class.action.addVhost.php.

177 {
178 global $bearsamppBins;
179 $bearsamppBins->getApache()->getService()->restart();
180 }
global $bearsamppBins

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the item (create or update)

Parameters
array$valuesThe form values
Returns
bool True on success, false on failure

Reimplemented from ActionDialogBase.

Definition at line 119 of file class.action.addVhost.php.

120 {
121 global $bearsamppRoot, $bearsamppBins, $bearsamppOpenSsl;
122
123 // Create SSL certificate
124 if (!$bearsamppOpenSsl->createCrt($values['serverName'])) {
125 return false;
126 }
127
128 // Create vhost configuration file
129 return file_put_contents(
130 $bearsamppRoot->getVhostsPath() . '/' . $values['serverName'] . '.conf',
131 $bearsamppBins->getApache()->getVhostContent($values['serverName'], $values['documentRoot'])
132 ) !== false;
133 }

References $bearsamppBins, and $bearsamppRoot.

◆ validateInput()

validateInput ( $values)
protected

Validate the form input

Parameters
array$valuesThe form values
Returns
array ['valid' => bool, 'error' => string|null]

Reimplemented from ActionDialogBase.

Definition at line 90 of file class.action.addVhost.php.

91 {
92 global $bearsamppLang;
93
94 if (!Util::isValidDomainName($values['serverName'])) {
95 return [
96 'valid' => false,
97 'error' => sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $values['serverName'])
98 ];
99 }
100
101 return ['valid' => true];
102 }
const VHOST_NOT_VALID_DOMAIN
static isValidDomainName($domainName)

References $bearsamppLang, Util\isValidDomainName(), and Lang\VHOST_NOT_VALID_DOMAIN.

Field Documentation

◆ $wbBtnDocRoot

$wbBtnDocRoot
private

Definition at line 20 of file class.action.addVhost.php.

◆ $wbInputDocRoot

$wbInputDocRoot
private

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

◆ $wbInputServerName

$wbInputServerName
private

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

◆ $wbLabelDocRoot

$wbLabelDocRoot
private

Definition at line 18 of file class.action.addVhost.php.

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelServerName

$wbLabelServerName
private

Definition at line 16 of file class.action.addVhost.php.


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