Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ActionEditAlias Class Reference
Inheritance diagram for ActionEditAlias:
Collaboration diagram for ActionEditAlias:

Protected Member Functions

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

Private Attributes

 $wbBtnDest
 $wbInputDest
 $wbInputName
 $wbLabelDest
 $wbLabelExp
 $wbLabelName

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 ActionEditAlias Handles the editing of Apache aliases within the Bearsampp application.

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

Member Function Documentation

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
protected

Create the form fields for the edit alias dialog.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 102 of file class.action.editAlias.php.

103 {
105
106 // Load existing alias data
107 $filePath = Path::getAliasPath() . '/' . $this->initValue . '.conf';
108 $fileContent = file_get_contents($filePath);
109 preg_match('/^Alias \/' . $this->initValue . ' "(.+)"/', $fileContent, $match);
110 $initDest = Path::formatWindowsPath($match[1]);
111 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
112
113 $this->wbLabelName = $bearsamppWinbinder->createLabel(
114 $this->wbWindow,
115 $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :',
116 15,
117 15,
118 85,
119 null,
120 WBC_RIGHT
121 );
122 $this->wbInputName = $bearsamppWinbinder->createInputText(
123 $this->wbWindow,
124 $this->initValue,
125 105,
126 13,
127 150,
128 null
129 );
130
131 $this->wbLabelDest = $bearsamppWinbinder->createLabel(
132 $this->wbWindow,
133 $bearsamppLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :',
134 15,
135 45,
136 85,
137 null,
138 WBC_RIGHT
139 );
140 $this->wbInputDest = $bearsamppWinbinder->createInputText(
141 $this->wbWindow,
142 $initDest,
143 105,
144 43,
145 190,
146 null,
147 null,
148 WBC_READONLY
149 );
150 $this->wbBtnDest = $bearsamppWinbinder->createButton(
151 $this->wbWindow,
153 300,
154 43,
155 110
156 );
157
158 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
159 $this->wbWindow,
160 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $this->initValue, $initDest),
161 15,
162 80,
163 470,
164 50
165 );
166 }
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const BUTTON_BROWSE
const ALIAS_DEST_LABEL
const ALIAS_NAME_LABEL
const ALIAS_EXP_LABEL
static getAliasPath($aetrayPath=false)
static formatWindowsPath($path)

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, Lang\ALIAS_DEST_LABEL, Lang\ALIAS_EXP_LABEL, Lang\ALIAS_NAME_LABEL, Lang\BUTTON_BROWSE, Path\formatWindowsPath(), and Path\getAliasPath().

Here is the call graph for this function:

◆ deleteItem()

deleteItem ( )
protected

Delete the alias configuration file.

Returns
bool True on success, false on failure.

Reimplemented from ActionDialogBase.

Definition at line 250 of file class.action.editAlias.php.

251 {
252 global $bearsamppRoot;
253
254 return @unlink(Path::getAliasPath() . '/' . $this->initValue . '.conf');
255 }

References $bearsamppRoot, and Path\getAliasPath().

Here is the call graph for this function:

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get the delete confirmation message.

Returns
string The localized confirmation message with the alias name.

Reimplemented from ActionDialogBase.

Definition at line 296 of file class.action.editAlias.php.

297 {
298 global $bearsamppLang;
299
300 return sprintf($bearsamppLang->getValue(Lang::DELETE_ALIAS), $this->initValue);
301 }
const DELETE_ALIAS

References $bearsamppLang, and Lang\DELETE_ALIAS.

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title.

Returns
string The localized delete dialog title.

Reimplemented from ActionDialogBase.

Definition at line 58 of file class.action.editAlias.php.

59 {
60 global $bearsamppLang;
61
63 }
const DELETE_ALIAS_TITLE

References $bearsamppLang, and Lang\DELETE_ALIAS_TITLE.

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get the error message after delete failure.

Returns
string The localized error message with the file path.

Reimplemented from ActionDialogBase.

Definition at line 320 of file class.action.editAlias.php.

321 {
323
324 return sprintf(
326 Path::getAliasPath() . '/' . $this->initValue . '.conf'
327 );
328 }
const ALIAS_REMOVE_ERROR

References $bearsamppLang, $bearsamppRoot, Lang\ALIAS_REMOVE_ERROR, and Path\getAliasPath().

Here is the call graph for this function:

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get the success message after delete.

Returns
string The localized success message with the alias name.

Reimplemented from ActionDialogBase.

Definition at line 308 of file class.action.editAlias.php.

309 {
310 global $bearsamppLang;
311
312 return sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVED), $this->initValue);
313 }
const ALIAS_REMOVED

References $bearsamppLang, and Lang\ALIAS_REMOVED.

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for message boxes.

Returns
string The localized dialog title.

Reimplemented from ActionDialogBase.

Definition at line 46 of file class.action.editAlias.php.

47 {
48 global $bearsamppLang;
49
50 return $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE);
51 }
const ADD_ALIAS_TITLE

References $bearsamppLang, and Lang\ADD_ALIAS_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values from the input controls.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
array Associative array with 'name' and 'dest' keys.

Reimplemented from ActionDialogBase.

Definition at line 175 of file class.action.editAlias.php.

176 {
177 return [
178 'name' => $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]),
179 'dest' => $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ])
180 ];
181 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get the error message after save failure.

Returns
string The localized error message.

Reimplemented from ActionDialogBase.

Definition at line 284 of file class.action.editAlias.php.

285 {
286 global $bearsamppLang;
287
289 }
const ALIAS_CREATED_ERROR

References $bearsamppLang, and Lang\ALIAS_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get the success message after saving.

Parameters
array$valuesThe form values.
Returns
string The localized success message.

Reimplemented from ActionDialogBase.

Definition at line 264 of file class.action.editAlias.php.

265 {
267
268 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
269
270 return sprintf(
272 $values['name'],
273 $apachePortUri,
274 $values['name'],
275 $values['dest']
276 );
277 }
const ALIAS_CREATED

References $bearsamppBins, $bearsamppLang, and Lang\ALIAS_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title.

Returns
string The localized window title with the alias name.

Reimplemented from ActionDialogBase.

Definition at line 34 of file class.action.editAlias.php.

35 {
36 global $bearsamppLang;
37
38 return sprintf($bearsamppLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initValue);
39 }
const EDIT_ALIAS_TITLE

References $bearsamppLang, and Lang\EDIT_ALIAS_TITLE.

◆ handleCustomEvent()

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

Handle custom window events (name input change and browse button).

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 352 of file class.action.editAlias.php.

353 {
354 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
355
356 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
357 $aliasName = $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
358 $aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);
359
360 // Handle name input change
361 if ($id == $this->wbInputName[WinBinder::CTRL_ID]) {
362 $bearsamppWinbinder->setText(
363 $this->wbLabelExp[WinBinder::CTRL_OBJ],
364 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest)
365 );
366 $bearsamppWinbinder->setEnabled(
367 $this->wbBtnSave[WinBinder::CTRL_OBJ],
368 !empty($aliasName)
369 );
370 }
371
372 // Handle browse button
373 if ($id == $this->wbBtnDest[WinBinder::CTRL_ID]) {
374 $aliasDest = $bearsamppWinbinder->sysDlgPath(
375 $window,
377 $aliasDest
378 );
379 if ($aliasDest && is_dir($aliasDest)) {
380 $bearsamppWinbinder->setText($this->wbInputDest[WinBinder::CTRL_OBJ], $aliasDest . '\\');
381 $bearsamppWinbinder->setText(
382 $this->wbLabelExp[WinBinder::CTRL_OBJ],
383 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest . '\\')
384 );
385 }
386 }
387 }
const ALIAS_DEST_PATH

References $bearsamppBins, $bearsamppLang, Lang\ALIAS_DEST_PATH, Lang\ALIAS_EXP_LABEL, WinBinder\CTRL_ID, and WinBinder\CTRL_OBJ.

◆ initializeDialog()

initializeDialog ( $args)
protected

Initialize the dialog by loading the existing alias configuration.

Parameters
array$argsCommand line arguments where $args[0] is the alias name.
Returns
bool True if initialization successful, false otherwise.

Reimplemented from ActionDialogBase.

Definition at line 72 of file class.action.editAlias.php.

73 {
74 global $bearsamppRoot;
75
76 if (!isset($args[0]) || empty($args[0])) {
77 return false;
78 }
79
80 $filePath = Path::getAliasPath() . '/' . $args[0] . '.conf';
81 if (!file_exists($filePath)) {
82 return false;
83 }
84
85 $fileContent = file_get_contents($filePath);
86 if (!preg_match('/^Alias \/' . $args[0] . ' "(.+)"/', $fileContent, $match)) {
87 return false;
88 }
89
90 $this->initValue = $args[0];
91
92 return true;
93 }

References $bearsamppRoot, and Path\getAliasPath().

Here is the call graph for this function:

◆ itemExists()

itemExists ( $values)
protected

Check if a different alias with the same name already exists.

Parameters
array$valuesThe form values.
Returns
bool True if a conflicting alias exists, false otherwise.

Reimplemented from ActionDialogBase.

Definition at line 211 of file class.action.editAlias.php.

212 {
213 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
214
215 // Only check if name changed
216 if ($values['name'] != $this->initValue && is_file(Path::getAliasPath() . '/' . $values['name'] . '.conf')) {
217 $bearsamppWinbinder->messageBoxError(
218 sprintf($bearsamppLang->getValue(Lang::ALIAS_ALREADY_EXISTS), $values['name']),
219 $this->getDialogTitle()
220 );
221
222 return true;
223 }
224
225 return false;
226 }
const ALIAS_ALREADY_EXISTS

References $bearsamppLang, $bearsamppRoot, Lang\ALIAS_ALREADY_EXISTS, and Path\getAliasPath().

Here is the call graph for this function:

◆ restartService()

restartService ( )
protected

Restart the Apache service after saving or deleting.

Returns
void

Reimplemented from ActionDialogBase.

Definition at line 335 of file class.action.editAlias.php.

336 {
337 global $bearsamppBins;
338 $bearsamppBins->getApache()->getService()->restart();
339 }

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the alias configuration file.

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

Reimplemented from ActionDialogBase.

Definition at line 235 of file class.action.editAlias.php.

236 {
238
239 return file_put_contents(
240 Path::getAliasPath() . '/' . $values['name'] . '.conf',
241 $bearsamppBins->getApache()->getAliasContent($values['name'], $values['dest'])
242 ) !== false;
243 }

References $bearsamppBins, $bearsamppRoot, and Path\getAliasPath().

Here is the call graph for this function:

◆ 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 190 of file class.action.editAlias.php.

191 {
192 global $bearsamppLang;
193
194 if (!ctype_alnum($values['name'])) {
195 return [
196 'valid' => false,
197 'error' => sprintf($bearsamppLang->getValue(Lang::ALIAS_NOT_VALID_ALPHA), $values['name'])
198 ];
199 }
200
201 return ['valid' => true];
202 }
const ALIAS_NOT_VALID_ALPHA

References $bearsamppLang, and Lang\ALIAS_NOT_VALID_ALPHA.

Field Documentation

◆ $wbBtnDest

$wbBtnDest
private

Definition at line 25 of file class.action.editAlias.php.

◆ $wbInputDest

$wbInputDest
private

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

◆ $wbInputName

$wbInputName
private

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

◆ $wbLabelDest

$wbLabelDest
private

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

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelName

$wbLabelName
private

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


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