Skip to content

Commit

Permalink
Refactor action classes with strict types and improved error handling
Browse files Browse the repository at this point in the history
The changes include:
- Added strict type declarations for properties and method parameters
- Made class constants public where appropriate
- Improved type safety with explicit type hints
- Enhanced error handling and null checks
- Reorganized code structure for better readability
- Added proper return type declarations
- Improved documentation blocks with more detailed descriptions
- Standardized code formatting and spacing
  • Loading branch information
N6REJ committed Dec 21, 2024
1 parent 29dcdb5 commit 997eade
Show file tree
Hide file tree
Showing 39 changed files with 1,543 additions and 1,337 deletions.
74 changes: 57 additions & 17 deletions core/classes/actions/class.action.about.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,35 @@
*/
class ActionAbout
{
private $wbWindow;
private $wbImage;
private $wbLinkHomepage;
private $wbLinkDonate;
private $wbLinkGithub;
private $wbBtnOk;
/**
* @var object The main window object created by WinBinder.
*/
private object $wbWindow;

/**
* @var object The image displayed in the "About" window.
*/
private object $wbImage;

/**
* @var object The hyperlink to the homepage.
*/
private object $wbLinkHomepage;

/**
* @var object The hyperlink to the donation page.
*/
private object $wbLinkDonate;

/**
* @var object The hyperlink to the GitHub page.
*/
private object $wbLinkGithub;

/**
* @var object The OK button to close the "About" window.
*/
private object $wbBtnOk;

const GAUGE_SAVE = 2;

Expand All @@ -28,28 +51,45 @@ class ActionAbout
*
* @param array $args Arguments passed to the constructor.
*/
public function __construct($args)
public function __construct(array $args)
{
global $bearsamppCore, $bearsamppLang, $bearsamppWinbinder;

$bearsamppWinbinder->reset();
$this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::ABOUT_TITLE), 500, 250, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
$this->wbWindow = $bearsamppWinbinder->createAppWindow(
$bearsamppLang->getValue(Lang::ABOUT_TITLE), 500, 250, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP
);

$aboutText = sprintf($bearsamppLang->getValue(Lang::ABOUT_TEXT), APP_TITLE . ' ' . $bearsamppCore->getAppVersion(), date('Y'), APP_AUTHOR_NAME);
$aboutText = sprintf(
$bearsamppLang->getValue(Lang::ABOUT_TEXT),
APP_TITLE . ' ' . $bearsamppCore->getAppVersion(),
date('Y'),
APP_AUTHOR_NAME
);
$bearsamppWinbinder->createLabel($this->wbWindow, $aboutText, 80, 20, 470, 120);

$bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::WEBSITE) . ' :', 80, 105, 470, 15);
$this->wbLinkHomepage = $bearsamppWinbinder->createHyperLink($this->wbWindow, Util::getWebsiteUrlNoUtm(), 180, 105, 300, 15, WBC_LINES);
$this->wbLinkHomepage = $bearsamppWinbinder->createHyperLink(
$this->wbWindow, Util::getWebsiteUrlNoUtm(), 180, 105, 300, 15, WBC_LINES
);

$bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::DONATE) . ' :', 80, 125, 470, 15);
$this->wbLinkDonate = $bearsamppWinbinder->createHyperLink($this->wbWindow, Util::getWebsiteUrlNoUtm('donate'), 180, 125, 300, 15, WBC_LINES | WBC_RIGHT);
$this->wbLinkDonate = $bearsamppWinbinder->createHyperLink(
$this->wbWindow, Util::getWebsiteUrlNoUtm('donate'), 180, 125, 300, 15, WBC_LINES | WBC_RIGHT
);

$bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::GITHUB) . ' :', 80, 145, 470, 15);
$this->wbLinkGithub = $bearsamppWinbinder->createHyperLink($this->wbWindow, Util::getGithubUserUrl(), 180, 145, 300, 15, WBC_LINES | WBC_RIGHT);
$this->wbLinkGithub = $bearsamppWinbinder->createHyperLink(
$this->wbWindow, Util::getGithubUserUrl(), 180, 145, 300, 15, WBC_LINES | WBC_RIGHT
);

$this->wbBtnOk = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_OK), 390, 180);
$this->wbBtnOk = $bearsamppWinbinder->createButton(
$this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_OK), 390, 180
);

$this->wbImage = $bearsamppWinbinder->drawImage($this->wbWindow, $bearsamppCore->getResourcesPath() . '/homepage/img/about.bmp');
$this->wbImage = $bearsamppWinbinder->drawImage(
$this->wbWindow, $bearsamppCore->getResourcesPath() . '/homepage/img/about.bmp'
);

$bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
$bearsamppWinbinder->mainLoop();
Expand All @@ -59,13 +99,13 @@ public function __construct($args)
/**
* Processes window events and handles user interactions.
*
* @param int $window The window identifier.
* @param object $window The window object.
* @param int $id The control identifier.
* @param int $ctrl The control object.
* @param object $ctrl The control object.
* @param mixed $param1 Additional parameter 1.
* @param mixed $param2 Additional parameter 2.
*/
public function processWindow($window, $id, $ctrl, $param1, $param2)
public function processWindow(object $window, int $id, object $ctrl, mixed $param1, mixed $param2): void
{
global $bearsamppConfig, $bearsamppWinbinder;

Expand Down
136 changes: 101 additions & 35 deletions core/classes/actions/class.action.addAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,55 @@
*/
class ActionAddAlias
{
private $wbWindow;
private $wbLabelName;
private $wbInputName;
private $wbLabelDest;
private $wbInputDest;
private $wbBtnDest;
private $wbLabelExp;
private $wbProgressBar;
private $wbBtnSave;
private $wbBtnCancel;
/**
* @var object The main window object created by WinBinder.
*/
private object $wbWindow;

/**
* @var object The label for the alias name input field.
*/
private object $wbLabelName;

/**
* @var object The input field for the alias name.
*/
private object $wbInputName;

/**
* @var object The label for the destination path input field.
*/
private object $wbLabelDest;

/**
* @var object The input field for the destination path.
*/
private object $wbInputDest;

/**
* @var object The button to browse for the destination path.
*/
private object $wbBtnDest;

/**
* @var object The label for the explanation text.
*/
private object $wbLabelExp;

/**
* @var object The progress bar to show the progress of adding the alias.
*/
private object $wbProgressBar;

/**
* @var object The save button to confirm the alias creation.
*/
private object $wbBtnSave;

/**
* @var object The cancel button to abort the alias creation process.
*/
private object $wbBtnCancel;

const GAUGE_SAVE = 2;

Expand All @@ -32,29 +71,49 @@ class ActionAddAlias
*
* @param array $args Arguments passed to the constructor.
*/
public function __construct($args)
public function __construct(array $args)
{
global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;

$initName = 'test';
$initDest = 'C:\\';
$apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
$apachePortUri = $bearsamppBins->getApache()->getPort() !== 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';

$bearsamppWinbinder->reset();
$this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);

$this->wbLabelName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT);
$this->wbInputName = $bearsamppWinbinder->createInputText($this->wbWindow, $initName, 105, 13, 150, null);

$this->wbLabelDest = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
$this->wbInputDest = $bearsamppWinbinder->createInputText($this->wbWindow, $initDest, 105, 43, 190, null, null, WBC_READONLY);
$this->wbBtnDest = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);

$this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $initName, $initDest), 15, 80, 470, 50);

$this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 275);
$this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 132);
$this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 132);
$this->wbWindow = $bearsamppWinbinder->createAppWindow(
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP
);

$this->wbLabelName = $bearsamppWinbinder->createLabel(
$this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT
);
$this->wbInputName = $bearsamppWinbinder->createInputText(
$this->wbWindow, $initName, 105, 13, 150, null
);

$this->wbLabelDest = $bearsamppWinbinder->createLabel(
$this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT
);
$this->wbInputDest = $bearsamppWinbinder->createInputText(
$this->wbWindow, $initDest, 105, 43, 190, null, null, WBC_READONLY
);
$this->wbBtnDest = $bearsamppWinbinder->createButton(
$this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110
);

$this->wbLabelExp = $bearsamppWinbinder->createLabel(
$this->wbWindow, sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $initName, $initDest), 15, 80, 470, 50
);

$this->wbProgressBar = $bearsamppWinbinder->createProgressBar(
$this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 275
);
$this->wbBtnSave = $bearsamppWinbinder->createButton(
$this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 132
);
$this->wbBtnCancel = $bearsamppWinbinder->createButton(
$this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 132
);

$bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
$bearsamppWinbinder->mainLoop();
Expand All @@ -64,17 +123,17 @@ public function __construct($args)
/**
* Processes window events and handles user interactions.
*
* @param resource $window The window resource.
* @param object $window The window object.
* @param int $id The control ID.
* @param resource $ctrl The control resource.
* @param object $ctrl The control object.
* @param mixed $param1 Additional parameter 1.
* @param mixed $param2 Additional parameter 2.
*/
public function processWindow($window, $id, $ctrl, $param1, $param2)
public function processWindow(object $window, int $id, object $ctrl, mixed $param1, mixed $param2): void
{
global $bearsamppRoot, $bearsamppBins, $bearsamppLang, $bearsamppWinbinder;

$apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
$apachePortUri = $bearsamppBins->getApache()->getPort() !== 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
$aliasName = $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
$aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);

Expand All @@ -84,7 +143,7 @@ public function processWindow($window, $id, $ctrl, $param1, $param2)
$this->wbLabelExp[WinBinder::CTRL_OBJ],
sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest)
);
$bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($aliasName) ? false : true);
$bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], !empty($aliasName));
break;
case $this->wbBtnDest[WinBinder::CTRL_ID]:
$aliasDest = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::ALIAS_DEST_PATH), $aliasDest);
Expand All @@ -103,18 +162,21 @@ public function processWindow($window, $id, $ctrl, $param1, $param2)
if (!ctype_alnum($aliasName)) {
$bearsamppWinbinder->messageBoxError(
sprintf($bearsamppLang->getValue(Lang::ALIAS_NOT_VALID_ALPHA), $aliasName),
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE));
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE)
);
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
break;
}

if (is_file($bearsamppRoot->getAliasPath() . '/' . $aliasName . '.conf')) {
$bearsamppWinbinder->messageBoxError(
sprintf($bearsamppLang->getValue(Lang::ALIAS_ALREADY_EXISTS), $aliasName),
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE));
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE)
);
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
break;
}

if (file_put_contents($bearsamppRoot->getAliasPath() . '/' . $aliasName . '.conf', $bearsamppBins->getApache()->getAliasContent($aliasName, $aliasDest)) !== false) {
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);

Expand All @@ -123,10 +185,14 @@ public function processWindow($window, $id, $ctrl, $param1, $param2)

$bearsamppWinbinder->messageBoxInfo(
sprintf($bearsamppLang->getValue(Lang::ALIAS_CREATED), $aliasName, $apachePortUri, $aliasName, $aliasDest),
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE));
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE)
);
$bearsamppWinbinder->destroyWindow($window);
} else {
$bearsamppWinbinder->messageBoxError($bearsamppLang->getValue(Lang::ALIAS_CREATED_ERROR), $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE));
$bearsamppWinbinder->messageBoxError(
$bearsamppLang->getValue(Lang::ALIAS_CREATED_ERROR),
$bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE)
);
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
}
break;
Expand Down
Loading

0 comments on commit 997eade

Please sign in to comment.