diff --git a/core/classes/actions/class.action.about.php b/core/classes/actions/class.action.about.php index 064133c6..44aed323 100644 --- a/core/classes/actions/class.action.about.php +++ b/core/classes/actions/class.action.about.php @@ -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; @@ -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(); @@ -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; diff --git a/core/classes/actions/class.action.addAlias.php b/core/classes/actions/class.action.addAlias.php index 68986f3d..e970f82f 100644 --- a/core/classes/actions/class.action.addAlias.php +++ b/core/classes/actions/class.action.addAlias.php @@ -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; @@ -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(); @@ -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]); @@ -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); @@ -103,7 +162,8 @@ 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; } @@ -111,10 +171,12 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) 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); @@ -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; diff --git a/core/classes/actions/class.action.addVhost.php b/core/classes/actions/class.action.addVhost.php index a0e5dd3b..0ec77a04 100644 --- a/core/classes/actions/class.action.addVhost.php +++ b/core/classes/actions/class.action.addVhost.php @@ -13,16 +13,55 @@ */ class ActionAddVhost { - private $wbWindow; - private $wbLabelServerName; - private $wbInputServerName; - private $wbLabelDocRoot; - private $wbInputDocRoot; - private $wbBtnDocRoot; - 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 server name input field. + */ + private object $wbLabelServerName; + + /** + * @var object The input field for the server name. + */ + private object $wbInputServerName; + + /** + * @var object The label for the document root input field. + */ + private object $wbLabelDocRoot; + + /** + * @var object The input field for the document root. + */ + private object $wbInputDocRoot; + + /** + * @var object The button to browse for the document root. + */ + private object $wbBtnDocRoot; + + /** + * @var object The label for the explanation text. + */ + private object $wbLabelExp; + + /** + * @var object The progress bar to show the progress of adding the vhost. + */ + private object $wbProgressBar; + + /** + * @var object The save button to confirm the vhost creation. + */ + private object $wbBtnSave; + + /** + * @var object The cancel button to abort the vhost creation process. + */ + private object $wbBtnCancel; const GAUGE_SAVE = 2; @@ -32,7 +71,7 @@ class ActionAddVhost * * @param array $args Arguments passed to the constructor. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder; @@ -40,20 +79,40 @@ public function __construct($args) $initDocumentRoot = Util::formatWindowsPath($bearsamppRoot->getWwwPath()) . '\\' . $initServerName; $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::ADD_VHOST_TITLE), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP); - - $this->wbLabelServerName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT); - $this->wbInputServerName = $bearsamppWinbinder->createInputText($this->wbWindow, $initServerName, 105, 13, 150, null); - - $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT); - $this->wbInputDocRoot = $bearsamppWinbinder->createInputText($this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY); - $this->wbBtnDocRoot = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110); - - $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $initServerName, $initDocumentRoot), 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_VHOST_TITLE), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP + ); + + $this->wbLabelServerName = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT + ); + $this->wbInputServerName = $bearsamppWinbinder->createInputText( + $this->wbWindow, $initServerName, 105, 13, 150, null + ); + + $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT + ); + $this->wbInputDocRoot = $bearsamppWinbinder->createInputText( + $this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY + ); + $this->wbBtnDocRoot = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110 + ); + + $this->wbLabelExp = $bearsamppWinbinder->createLabel( + $this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $initServerName, $initDocumentRoot), 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(); @@ -63,13 +122,13 @@ 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 ID of the control that triggered the event. - * @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, $bearsamppOpenSsl, $bearsamppWinbinder; @@ -82,7 +141,7 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot) ); - $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true); + $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], !empty($serverName)); break; case $this->wbBtnDocRoot[WinBinder::CTRL_ID]: $documentRoot = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot); @@ -101,7 +160,8 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) if (!Util::isValidDomainName($serverName)) { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $serverName), - $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE)); + $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); break; } @@ -109,7 +169,8 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) if (is_file($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf')) { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName), - $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE)); + $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); break; } @@ -122,10 +183,14 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $bearsamppWinbinder->messageBoxInfo( sprintf($bearsamppLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot), - $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE)); + $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE) + ); $bearsamppWinbinder->destroyWindow($window); } else { - $bearsamppWinbinder->messageBoxError($bearsamppLang->getValue(Lang::VHOST_CREATED_ERROR), $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE)); + $bearsamppWinbinder->messageBoxError( + $bearsamppLang->getValue(Lang::VHOST_CREATED_ERROR), + $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); } break; diff --git a/core/classes/actions/class.action.changeBrowser.php b/core/classes/actions/class.action.changeBrowser.php index 7831fa58..39042e0f 100644 --- a/core/classes/actions/class.action.changeBrowser.php +++ b/core/classes/actions/class.action.changeBrowser.php @@ -16,15 +16,50 @@ */ class ActionChangeBrowser { - private $wbWindow; - private $wbLabelExp; - private $wbRadioButton; - private $wbRadioButtonOther; - private $wbInputBrowse; - private $wbBtnBrowse; - private $wbProgressBar; - private $wbBtnSave; - private $wbBtnCancel; + /** + * @var object The main window object created by WinBinder. + */ + private object $wbWindow; + + /** + * @var object The label for the explanation text. + */ + private object $wbLabelExp; + + /** + * @var array The radio buttons for selecting browsers. + */ + private array $wbRadioButton; + + /** + * @var object The radio button for selecting a custom browser. + */ + private object $wbRadioButtonOther; + + /** + * @var object The input field for browsing to a custom browser executable. + */ + private object $wbInputBrowse; + + /** + * @var object The button to open the file dialog for browsing. + */ + private object $wbBtnBrowse; + + /** + * @var object The progress bar to show the progress of saving the browser selection. + */ + private object $wbProgressBar; + + /** + * @var object The save button to confirm the browser selection. + */ + private object $wbBtnSave; + + /** + * @var object The cancel button to abort the browser selection process. + */ + private object $wbBtnCancel; const GAUGE_SAVE = 2; @@ -35,37 +70,57 @@ class ActionChangeBrowser * * @param array $args Arguments passed to the constructor. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder; $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::CHANGE_BROWSER_TITLE), 490, 350, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP); + $this->wbWindow = $bearsamppWinbinder->createAppWindow( + $bearsamppLang->getValue(Lang::CHANGE_BROWSER_TITLE), 490, 350, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP + ); - $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_EXP_LABEL), 15, 15, 470, 50); + $this->wbLabelExp = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_EXP_LABEL), 15, 15, 470, 50 + ); $currentBrowser = $bearsamppConfig->getBrowser(); - $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $currentBrowser, true, 15, 40, 470, 20, true); + $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton( + $this->wbWindow, $currentBrowser, true, 15, 40, 470, 20, true + ); $yPos = 70; $installedBrowsers = Vbs::getInstalledBrowsers(); foreach ($installedBrowsers as $installedBrowser) { - if ($installedBrowser != $currentBrowser) { - $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $installedBrowser, false, 15, $yPos, 470, 20); + if ($installedBrowser !== $currentBrowser) { + $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton( + $this->wbWindow, $installedBrowser, false, 15, $yPos, 470, 20 + ); $yPos += 30; } } - $this->wbRadioButtonOther = $bearsamppWinbinder->createRadioButton($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_OTHER_LABEL), false, 15, $yPos, 470, 15); + $this->wbRadioButtonOther = $bearsamppWinbinder->createRadioButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_OTHER_LABEL), false, 15, $yPos, 470, 15 + ); - $this->wbInputBrowse = $bearsamppWinbinder->createInputText($this->wbWindow, null, 30, $yPos + 30, 190, null, 20, WBC_READONLY); - $this->wbBtnBrowse = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 225, $yPos + 25, 110); + $this->wbInputBrowse = $bearsamppWinbinder->createInputText( + $this->wbWindow, null, 30, $yPos + 30, 190, null, 20, WBC_READONLY + ); + $this->wbBtnBrowse = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 225, $yPos + 25, 110 + ); $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false); - $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE, 15, 287, 275); - $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 282); - $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 282); - $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($currentBrowser) ? false : true); + $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( + $this->wbWindow, self::GAUGE_SAVE, 15, 287, 275 + ); + $this->wbBtnSave = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 282 + ); + $this->wbBtnCancel = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 282 + ); + $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], !empty($currentBrowser)); $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow'); $bearsamppWinbinder->mainLoop(); @@ -78,13 +133,13 @@ public function __construct($args) * Handles the logic for various controls in the window, such as enabling/disabling buttons, * opening file dialogs, and saving the selected browser. * - * @param resource $window The window resource. + * @param object $window The window object. * @param int $id The ID of the control that triggered the event. - * @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 $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder; @@ -93,28 +148,28 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) // Get value $selected = null; - if ($bearsamppWinbinder->getValue($this->wbRadioButtonOther[WinBinder::CTRL_OBJ]) == 1) { + if ($bearsamppWinbinder->getValue($this->wbRadioButtonOther[WinBinder::CTRL_OBJ]) === 1) { $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], true); $selected = $bearsamppWinbinder->getText($this->wbInputBrowse[WinBinder::CTRL_OBJ]); } else { $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false); } foreach ($this->wbRadioButton as $radioButton) { - if ($bearsamppWinbinder->getValue($radioButton[WinBinder::CTRL_OBJ]) == 1) { + if ($bearsamppWinbinder->getValue($radioButton[WinBinder::CTRL_OBJ]) === 1) { $selected = $bearsamppWinbinder->getText($radioButton[WinBinder::CTRL_OBJ]); break; } } // Enable/disable save button - $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($selected) ? false : true); + $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], !empty($selected)); switch ($id) { case $this->wbBtnBrowse[WinBinder::CTRL_ID]: $browserPath = trim($bearsamppWinbinder->sysDlgOpen( $window, $bearsamppLang->getValue(Lang::ALIAS_DEST_PATH), - array(array($bearsamppLang->getValue(Lang::EXECUTABLE), '*.exe')), + [['Executable', '*.exe']], $browserPath )); if ($browserPath && is_file($browserPath)) { diff --git a/core/classes/actions/class.action.changeDbRootPwd.php b/core/classes/actions/class.action.changeDbRootPwd.php index 3be15339..ac9168fa 100644 --- a/core/classes/actions/class.action.changeDbRootPwd.php +++ b/core/classes/actions/class.action.changeDbRootPwd.php @@ -16,62 +16,62 @@ class ActionChangeDbRootPwd /** * @var object The database binary object (MySQL, MariaDB, PostgreSQL). */ - private $bin; + private object $bin; /** * @var int The count of process actions required for the progress bar. */ - private $cntProcessActions; + private int $cntProcessActions; /** * @var object The main window object created by WinBinder. */ - private $wbWindow; + private object $wbWindow; /** * @var object The label for the current password input field. */ - private $wbLabelCurrentPwd; + private object $wbLabelCurrentPwd; /** * @var object The input field for the current password. */ - private $wbInputCurrentPwd; + private object $wbInputCurrentPwd; /** * @var object The label for the new password input field. */ - private $wbLabelNewPwd1; + private object $wbLabelNewPwd1; /** * @var object The input field for the new password. */ - private $wbInputNewPwd1; + private object $wbInputNewPwd1; /** * @var object The label for the confirmation of the new password input field. */ - private $wbLabelNewPwd2; + private object $wbLabelNewPwd2; /** * @var object The input field for the confirmation of the new password. */ - private $wbInputNewPwd2; + private object $wbInputNewPwd2; /** * @var object The progress bar to show the progress of the password change process. */ - private $wbProgressBar; + private object $wbProgressBar; /** * @var object The finish button to submit the password change. */ - private $wbBtnFinish; + private object $wbBtnFinish; /** * @var object The cancel button to abort the password change process. */ - private $wbBtnCancel; + private object $wbBtnCancel; /** * ActionChangeDbRootPwd constructor. @@ -79,36 +79,57 @@ class ActionChangeDbRootPwd * * @param array $args The arguments passed to the constructor, typically containing the database type. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; if (isset($args[0]) && !empty($args[0])) { $this->bin = $bearsamppBins->getMysql(); $this->cntProcessActions = 11; - if ($args[0] == $bearsamppBins->getMariadb()->getName()) { + if ($args[0] === $bearsamppBins->getMariadb()->getName()) { $this->bin = $bearsamppBins->getMariadb(); $this->cntProcessActions = 11; - } elseif ($args[0] == $bearsamppBins->getPostgresql()->getName()) { + } elseif ($args[0] === $bearsamppBins->getPostgresql()->getName()) { $this->bin = $bearsamppBins->getPostgresql(); $this->cntProcessActions = 10; } $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TITLE), $args[0]), 400, 290, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP); - - $this->wbLabelCurrentPwd = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_CURRENTPWD_LABEL), 15, 15, 280); - $this->wbInputCurrentPwd = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 40, 200, null, null, WBC_MASKED); - - $this->wbLabelNewPwd1 = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD1_LABEL), 15, 80, 280); - $this->wbInputNewPwd1 = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 105, 200, null, null, WBC_MASKED); - - $this->wbLabelNewPwd2 = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD2_LABEL), 15, 145, 280); - $this->wbInputNewPwd2 = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 170, 200, null, null, WBC_MASKED); - - $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, $this->cntProcessActions + 1, 15, 227, 190); - $this->wbBtnFinish = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_FINISH), 210, 222); - $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 297, 222); + $this->wbWindow = $bearsamppWinbinder->createAppWindow( + sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TITLE), $args[0]), + 400, 290, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP + ); + + $this->wbLabelCurrentPwd = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_CURRENTPWD_LABEL), 15, 15, 280 + ); + $this->wbInputCurrentPwd = $bearsamppWinbinder->createInputText( + $this->wbWindow, null, 15, 40, 200, null, null, WBC_MASKED + ); + + $this->wbLabelNewPwd1 = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD1_LABEL), 15, 80, 280 + ); + $this->wbInputNewPwd1 = $bearsamppWinbinder->createInputText( + $this->wbWindow, null, 15, 105, 200, null, null, WBC_MASKED + ); + + $this->wbLabelNewPwd2 = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD2_LABEL), 15, 145, 280 + ); + $this->wbInputNewPwd2 = $bearsamppWinbinder->createInputText( + $this->wbWindow, null, 15, 170, 200, null, null, WBC_MASKED + ); + + $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( + $this->wbWindow, $this->cntProcessActions + 1, 15, 227, 190 + ); + $this->wbBtnFinish = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_FINISH), 210, 222 + ); + $this->wbBtnCancel = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 297, 222 + ); $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow'); $bearsamppWinbinder->setFocus($this->wbInputCurrentPwd[WinBinder::CTRL_OBJ]); @@ -126,7 +147,7 @@ public function __construct($args) * @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 $bearsamppLang, $bearsamppWinbinder; $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TITLE), $this->bin); @@ -137,8 +158,10 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) switch ($id) { case $this->wbBtnFinish[WinBinder::CTRL_ID]: $bearsamppWinbinder->incrProgressBar($this->wbProgressBar); - if ($newPwd1 != $newPwd2) { - $bearsamppWinbinder->messageBoxWarning($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NOTSAME_ERROR), $boxTitle); + if ($newPwd1 !== $newPwd2) { + $bearsamppWinbinder->messageBoxWarning( + $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NOTSAME_ERROR), $boxTitle + ); $bearsamppWinbinder->setText($this->wbInputNewPwd1[WinBinder::CTRL_OBJ], ''); $bearsamppWinbinder->setText($this->wbInputNewPwd2[WinBinder::CTRL_OBJ], ''); $bearsamppWinbinder->setFocus($this->wbInputNewPwd1[WinBinder::CTRL_OBJ]); @@ -170,7 +193,8 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $bearsamppWinbinder->messageBoxInfo( $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TEXT), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->destroyWindow($window); break; case IDCLOSE: diff --git a/core/classes/actions/class.action.changePort.php b/core/classes/actions/class.action.changePort.php index 9fdae91a..31e27633 100644 --- a/core/classes/actions/class.action.changePort.php +++ b/core/classes/actions/class.action.changePort.php @@ -7,155 +7,190 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Lang; +use Bearsampp\Core\Classes\WinBinder; +use Bearsampp\Core\Classes\Bins; + /** * Class ActionChangePort * Handles the process of changing the port for various services in the Bearsampp application. */ class ActionChangePort { - private $bin; - private $currentPort; - private $cntProcessActions; - - private $wbWindow; - - private $wbLabelCurrent; + private Bins $bin; + private int $currentPort; + private int $cntProcessActions; - private $wbLabelPort; - private $wbInputPort; - - private $wbProgressBar; - private $wbBtnFinish; - private $wbBtnCancel; + private mixed $wbWindow; + private mixed $wbLabelCurrent; + private mixed $wbLabelPort; + private mixed $wbInputPort; + private mixed $wbProgressBar; + private mixed $wbBtnFinish; + private mixed $wbBtnCancel; /** * ActionChangePort constructor. * Initializes the port change process for the specified service. * - * @param array $args The arguments passed to the constructor, where the first element specifies the service name. + * @param array $args The arguments passed to the constructor, where the first element specifies the service name. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; - if ( isset( $args[0] ) && !empty( $args[0] ) ) { - $this->bin = $bearsamppBins->getApache(); - $this->currentPort = $bearsamppBins->getApache()->getPort(); - $this->cntProcessActions = 3; - if ( $args[0] == $bearsamppBins->getMysql()->getName() ) { - $this->bin = $bearsamppBins->getMysql(); - $this->currentPort = $bearsamppBins->getMysql()->getPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getMariadb()->getName() ) { - $this->bin = $bearsamppBins->getMariadb(); - $this->currentPort = $bearsamppBins->getMariadb()->getPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getPostgresql()->getName() ) { - $this->bin = $bearsamppBins->getPostgresql(); - $this->currentPort = $bearsamppBins->getPostgresql()->getPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getFilezilla()->getName() ) { - $this->bin = $bearsamppBins->getFilezilla(); - $this->currentPort = $bearsamppBins->getFilezilla()->getPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getMailhog()->getName() ) { - $this->bin = $bearsamppBins->getMailhog(); - $this->currentPort = $bearsamppBins->getMailhog()->getSmtpPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getMailpit()->getName() ) { - $this->bin = $bearsamppBins->getMailpit(); - $this->currentPort = $bearsamppBins->getMailpit()->getSmtpPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getMemcached()->getName() ) { - $this->bin = $bearsamppBins->getMemcached(); - $this->currentPort = $bearsamppBins->getMemcached()->getPort(); - $this->cntProcessActions = 3; - } elseif ($args[0] == $bearsamppBins->getXlight()->getName()) { - $this->bin = $bearsamppBins->getXlight(); - $this->currentPort = $bearsamppBins->getXlight()->getPort(); - $this->cntProcessActions = 3; - } - elseif ( $args[0] == $bearsamppBins->getXlight()->getName() ) { - $this->bin = $bearsamppBins->getXlight(); - $this->currentPort = $bearsamppBins->getXlight()->getPort(); - $this->cntProcessActions = 3; - } + if (isset($args[0]) && !empty($args[0])) { + $this->initializeBin($args[0], $bearsamppBins); $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow( sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $args[0] ), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP ); + $this->wbWindow = $bearsamppWinbinder->createAppWindow( + sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_TITLE), $args[0]), + 380, + 170, + WBC_NOTIFY, + WBC_KEYDOWN | WBC_KEYUP + ); $this->wbLabelCurrent = $bearsamppWinbinder->createLabel( $this->wbWindow, - sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_CURRENT_LABEL ), $args[0], $this->currentPort ), 15, 15, 350 + sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_CURRENT_LABEL), $args[0], $this->currentPort), + 15, + 15, + 350 ); - $this->wbLabelPort = $bearsamppWinbinder->createLabel( $this->wbWindow, $bearsamppLang->getValue( Lang::CHANGE_PORT_NEW_LABEL ) . ' :', 15, 45, 85, null, WBC_RIGHT ); - $this->wbInputPort = $bearsamppWinbinder->createInputText( $this->wbWindow, $this->currentPort, 105, 43, 50, null, 5, WBC_NUMBER ); + $this->wbLabelPort = $bearsamppWinbinder->createLabel( + $this->wbWindow, + $bearsamppLang->getValue(Lang::CHANGE_PORT_NEW_LABEL) . ' :', + 15, + 45, + 85, + null, + WBC_RIGHT + ); + $this->wbInputPort = $bearsamppWinbinder->createInputText( + $this->wbWindow, + $this->currentPort, + 105, + 43, + 50, + null, + 5, + WBC_NUMBER + ); - $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( $this->wbWindow, $this->cntProcessActions + 1, 15, 107, 170 ); - $this->wbBtnFinish = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_FINISH ), 190, 102 ); - $this->wbBtnCancel = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_CANCEL ), 277, 102 ); + $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( + $this->wbWindow, + $this->cntProcessActions + 1, + 15, + 107, + 170 + ); + $this->wbBtnFinish = $bearsamppWinbinder->createButton( + $this->wbWindow, + $bearsamppLang->getValue(Lang::BUTTON_FINISH), + 190, + 102 + ); + $this->wbBtnCancel = $bearsamppWinbinder->createButton( + $this->wbWindow, + $bearsamppLang->getValue(Lang::BUTTON_CANCEL), + 277, + 102 + ); - $bearsamppWinbinder->setHandler( $this->wbWindow, $this, 'processWindow' ); - $bearsamppWinbinder->setFocus( $this->wbInputPort[WinBinder::CTRL_OBJ] ); + $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow'); + $bearsamppWinbinder->setFocus($this->wbInputPort[WinBinder::CTRL_OBJ]); $bearsamppWinbinder->mainLoop(); $bearsamppWinbinder->reset(); } } + /** + * Initializes the bin and current port based on the service name. + * + * @param string $serviceName The name of the service. + * @param Bins $bearsamppBins The global bins object. + */ + private function initializeBin(string $serviceName, Bins $bearsamppBins): void + { + if ($serviceName === $bearsamppBins->getApache()->getName()) { + $this->bin = $bearsamppBins->getApache(); + $this->currentPort = $bearsamppBins->getApache()->getPort(); + } elseif ($serviceName === $bearsamppBins->getMysql()->getName()) { + $this->bin = $bearsamppBins->getMysql(); + $this->currentPort = $bearsamppBins->getMysql()->getPort(); + } elseif ($serviceName === $bearsamppBins->getMariadb()->getName()) { + $this->bin = $bearsamppBins->getMariadb(); + $this->currentPort = $bearsamppBins->getMariadb()->getPort(); + } elseif ($serviceName === $bearsamppBins->getPostgresql()->getName()) { + $this->bin = $bearsamppBins->getPostgresql(); + $this->currentPort = $bearsamppBins->getPostgresql()->getPort(); + } elseif ($serviceName === $bearsamppBins->getFilezilla()->getName()) { + $this->bin = $bearsamppBins->getFilezilla(); + $this->currentPort = $bearsamppBins->getFilezilla()->getPort(); + } elseif ($serviceName === $bearsamppBins->getMailhog()->getName()) { + $this->bin = $bearsamppBins->getMailhog(); + $this->currentPort = $bearsamppBins->getMailhog()->getSmtpPort(); + } elseif ($serviceName === $bearsamppBins->getMailpit()->getName()) { + $this->bin = $bearsamppBins->getMailpit(); + $this->currentPort = $bearsamppBins->getMailpit()->getSmtpPort(); + } elseif ($serviceName === $bearsamppBins->getMemcached()->getName()) { + $this->bin = $bearsamppBins->getMemcached(); + $this->currentPort = $bearsamppBins->getMemcached()->getPort(); + } elseif ($serviceName === $bearsamppBins->getXlight()->getName()) { + $this->bin = $bearsamppBins->getXlight(); + $this->currentPort = $bearsamppBins->getXlight()->getPort(); + } + $this->cntProcessActions = 3; + } + /** * Processes window events and handles user interactions. * - * @param mixed $window The window object. - * @param int $id The control ID. - * @param mixed $ctrl The control object. - * @param mixed $param1 Additional parameter 1. - * @param mixed $param2 Additional parameter 2. + * @param mixed $window The window object. + * @param int $id The control ID. + * @param mixed $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(mixed $window, int $id, mixed $ctrl, mixed $param1, mixed $param2): void { global $bearsamppLang, $bearsamppWinbinder; - $boxTitle = sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $this->bin ); - $port = $bearsamppWinbinder->getText( $this->wbInputPort[WinBinder::CTRL_OBJ] ); + $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHANGE_PORT_TITLE), $this->bin); + $port = $bearsamppWinbinder->getText($this->wbInputPort[WinBinder::CTRL_OBJ]); - switch ( $id ) { + switch ($id) { case $this->wbInputPort[WinBinder::CTRL_ID]: - $bearsamppWinbinder->setEnabled( $this->wbBtnFinish[WinBinder::CTRL_OBJ], empty( $port ) ? false : true ); + $bearsamppWinbinder->setEnabled($this->wbBtnFinish[WinBinder::CTRL_OBJ], !empty($port)); break; case $this->wbBtnFinish[WinBinder::CTRL_ID]: - $bearsamppWinbinder->incrProgressBar( $this->wbProgressBar ); - if ( $port == $this->currentPort ) { - $bearsamppWinbinder->messageBoxWarning( $bearsamppLang->getValue( Lang::CHANGE_PORT_SAME_ERROR ), $boxTitle ); - $bearsamppWinbinder->resetProgressBar( $this->wbProgressBar ); + $bearsamppWinbinder->incrProgressBar($this->wbProgressBar); + if ($port == $this->currentPort) { + $bearsamppWinbinder->messageBoxWarning($bearsamppLang->getValue(Lang::CHANGE_PORT_SAME_ERROR), $boxTitle); + $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); break; } - $changePort = $this->bin->changePort( $port, true, $this->wbProgressBar ); - if ( $changePort === true ) { + $changePort = $this->bin->changePort($port, true, $this->wbProgressBar); + if ($changePort === true) { $this->bin->getService()->restart(); $bearsamppWinbinder->messageBoxInfo( - sprintf( $bearsamppLang->getValue( Lang::PORT_CHANGED ), $this->bin, $port ), + sprintf($bearsamppLang->getValue(Lang::PORT_CHANGED), $this->bin, $port), $boxTitle ); - $bearsamppWinbinder->destroyWindow( $window ); - } - else { + $bearsamppWinbinder->destroyWindow($window); + } else { $bearsamppWinbinder->messageBoxError( - sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED_BY ), $port, $changePort ), + sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port, $changePort), $boxTitle ); - $bearsamppWinbinder->resetProgressBar( $this->wbProgressBar ); + $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); } break; case IDCLOSE: case $this->wbBtnCancel[WinBinder::CTRL_ID]: - $bearsamppWinbinder->destroyWindow( $window ); + $bearsamppWinbinder->destroyWindow($window); break; } } diff --git a/core/classes/actions/class.action.checkPort.php b/core/classes/actions/class.action.checkPort.php index 30330c36..72651aeb 100644 --- a/core/classes/actions/class.action.checkPort.php +++ b/core/classes/actions/class.action.checkPort.php @@ -7,6 +7,8 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Bins; + /** * Class ActionCheckPort * @@ -18,49 +20,41 @@ class ActionCheckPort /** * Constructor for ActionCheckPort. * - * @param array $args An array of arguments where: - * - $args[0] is the name of the service (e.g., Apache, MySQL). - * - $args[1] is the port number to check. - * - $args[2] (optional) indicates if SSL should be used. + * @param array $args An array of arguments where: + * - $args[0] is the name of the service (e.g., Apache, MySQL). + * - $args[1] is the port number to check. + * - $args[2] (optional) indicates if SSL should be used. * - * @global object $bearsamppBins Global object containing instances of various services. + * @global Bins $bearsamppBins Global object containing instances of various services. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppBins; // Check if the required arguments are provided and not empty - if ( isset( $args[0] ) && !empty( $args[0] ) && isset( $args[1] ) && !empty( $args[1] ) ) { + if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) { // Determine if SSL is to be used - $ssl = isset( $args[2] ) && !empty( $args[2] ); + $ssl = isset($args[2]) && !empty($args[2]); // Check the port for the specified service - if ( $args[0] == $bearsamppBins->getApache()->getName() ) { - $bearsamppBins->getApache()->checkPort( $args[1], $ssl, true ); - } - elseif ( $args[0] == $bearsamppBins->getMysql()->getName() ) { - $bearsamppBins->getMysql()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMariadb()->getName() ) { - $bearsamppBins->getMariadb()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getPostgresql()->getName() ) { - $bearsamppBins->getPostgresql()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getFilezilla()->getName() ) { - $bearsamppBins->getFilezilla()->checkPort( $args[1], $ssl, true ); - } - elseif ( $args[0] == $bearsamppBins->getMailhog()->getName() ) { - $bearsamppBins->getMailhog()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMailpit()->getName() ) { - $bearsamppBins->getMailpit()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMemcached()->getName() ) { - $bearsamppBins->getMemcached()->checkPort( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getXlight()->getName() ) { - $bearsamppBins->getXlight()->checkPort( $args[1], true ); + if ($args[0] === $bearsamppBins->getApache()->getName()) { + $bearsamppBins->getApache()->checkPort($args[1], $ssl, true); + } elseif ($args[0] === $bearsamppBins->getMysql()->getName()) { + $bearsamppBins->getMysql()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMariadb()->getName()) { + $bearsamppBins->getMariadb()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getPostgresql()->getName()) { + $bearsamppBins->getPostgresql()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getFilezilla()->getName()) { + $bearsamppBins->getFilezilla()->checkPort($args[1], $ssl, true); + } elseif ($args[0] === $bearsamppBins->getMailhog()->getName()) { + $bearsamppBins->getMailhog()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMailpit()->getName()) { + $bearsamppBins->getMailpit()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMemcached()->getName()) { + $bearsamppBins->getMemcached()->checkPort($args[1], true); + } elseif ($args[0] === $bearsamppBins->getXlight()->getName()) { + $bearsamppBins->getXlight()->checkPort($args[1], true); } } } diff --git a/core/classes/actions/class.action.checkVersion.php b/core/classes/actions/class.action.checkVersion.php index 531d7f90..ee1443be 100644 --- a/core/classes/actions/class.action.checkVersion.php +++ b/core/classes/actions/class.action.checkVersion.php @@ -7,6 +7,11 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Lang; +use Bearsampp\Core\Classes\WinBinder; +use Bearsampp\Core\Classes\Core; +use Bearsampp\Core\Classes\Util; + /** * Class ActionCheckVersion * @@ -18,24 +23,24 @@ */ class ActionCheckVersion { - const DISPLAY_OK = 'displayOk'; + public const DISPLAY_OK = 'displayOk'; - private $wbWindow; - private $wbImage; - private $wbLinkChangelog; - private $wbLinkFull; - private $wbBtnOk; + private mixed $wbWindow; + private mixed $wbImage; + private mixed $wbLinkChangelog; + private mixed $wbLinkFull; + private mixed $wbBtnOk; - private $currentVersion; - private $latestVersion; - private $githubLatestVersionUrl; + private string $currentVersion; + private string $latestVersion; + private string $githubLatestVersionUrl; /** * Constructor for the ActionCheckVersion class. * * @param array $args Command line arguments passed to the script. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppCore, $bearsamppLang, $bearsamppWinbinder, $appGithubHeader; @@ -46,12 +51,12 @@ public function __construct($args) // Assuming getLatestVersion now returns an array with version and URL $githubVersionData = Util::getLatestVersion(APP_GITHUB_LATEST_URL); - if ($githubVersionData != null && isset($githubVersionData['version'], $githubVersionData['html_url'])) { + if ($githubVersionData !== null && isset($githubVersionData['version'], $githubVersionData['html_url'])) { $githubLatestVersion = $githubVersionData['version']; $this->githubLatestVersionUrl = $githubVersionData['html_url']; // URL of the latest version if (version_compare($this->currentVersion, $githubLatestVersion, '<')) { $this->showVersionUpdateWindow($bearsamppLang, $bearsamppWinbinder, $bearsamppCore, $githubLatestVersion); - } elseif (!empty($args[0]) && $args[0] == self::DISPLAY_OK) { + } elseif (!empty($args[0]) && $args[0] === self::DISPLAY_OK) { $this->showVersionOkMessageBox($bearsamppLang, $bearsamppWinbinder); } } @@ -66,7 +71,7 @@ public function __construct($args) * @param Core $core Core instance for accessing application resources. * @param string $githubLatestVersion The latest version available on GitHub. */ - private function showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion) + private function showVersionUpdateWindow(Lang $lang, WinBinder $winbinder, Core $core, string $githubLatestVersion): void { $labelFullLink = $lang->getValue(Lang::DOWNLOAD) . ' ' . APP_TITLE . ' ' . $githubLatestVersion; @@ -92,7 +97,7 @@ private function showVersionUpdateWindow($lang, $winbinder, $core, $githubLatest * @param Lang $lang Language processor instance. * @param WinBinder $winbinder WinBinder instance for creating windows and controls. */ - private function showVersionOkMessageBox($lang, $winbinder) + private function showVersionOkMessageBox(Lang $lang, WinBinder $winbinder): void { Util::stopLoading(); $winbinder->messageBoxInfo( @@ -104,13 +109,13 @@ private function showVersionOkMessageBox($lang, $winbinder) /** * Processes window events and handles user interactions. * - * @param resource $window The window resource. + * @param mixed $window The window resource. * @param int $id The control ID that triggered the event. - * @param resource $ctrl The control resource. + * @param mixed $ctrl The control resource. * @param mixed $param1 Additional parameter 1. * @param mixed $param2 Additional parameter 2. */ - public function processWindow($window, $id, $ctrl, $param1, $param2) + public function processWindow(mixed $window, int $id, mixed $ctrl, mixed $param1, mixed $param2): void { global $bearsamppConfig, $bearsamppWinbinder; diff --git a/core/classes/actions/class.action.clearFolders.php b/core/classes/actions/class.action.clearFolders.php index 04557f59..0fcd377e 100644 --- a/core/classes/actions/class.action.clearFolders.php +++ b/core/classes/actions/class.action.clearFolders.php @@ -7,6 +7,8 @@ * Github: https://github.com/Bearsampp */ +use Core\Classes\Util; + /** * Handles the action of clearing specific temporary folders within the application. * @@ -24,7 +26,7 @@ class ActionClearFolders * * @param array $args Arguments that might be used for further extension of constructor functionality. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppRoot, $bearsamppCore; @@ -34,14 +36,17 @@ public function __construct($args) * Util::clearFolder is used to clear the contents of the root temporary path, excluding * certain essential items such as 'cachegrind', 'composer', 'openssl', 'mailpit', 'xlight', 'npm-cache', * 'pip', 'yarn', and '.gitignore'. This ensures that important data and configurations are not lost. - * - * @param string $bearsamppRoot->getTmpPath() The root temporary path to be cleared. - * @param array $exclusions List of folders and files to be excluded from deletion. */ - Util::clearFolder($bearsamppRoot->getTmpPath(), array('cachegrind', 'composer', 'openssl', 'mailhog', 'mailpit', 'xlight', 'npm-cache', 'pip', 'yarn', '.gitignore')); + Util::clearFolder( + $bearsamppRoot->getTmpPath(), + ['cachegrind', 'composer', 'openssl', 'mailhog', 'mailpit', 'xlight', 'npm-cache', 'pip', 'yarn', '.gitignore'] + ); // Clear logs - Util::clearFolder($bearsamppRoot->getLogsPath(), array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore') ); + Util::clearFolder( + $bearsamppRoot->getLogsPath(), + ['mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore'] + ); /** * Clears the core temporary path. @@ -49,10 +54,7 @@ public function __construct($args) * Util::clearFolder is used to clear the contents of the core temporary path, excluding * the '.gitignore' file. This ensures that the core temporary path is cleaned without * removing the '.gitignore' file which might be necessary for version control. - * - * @param string $bearsamppCore->getTmpPath() The core temporary path to be cleared. - * @param array $exclusions List of folders and files to be excluded from deletion. */ - Util::clearFolder($bearsamppCore->getTmpPath(), array('.gitignore')); + Util::clearFolder($bearsamppCore->getTmpPath(), ['.gitignore']); } } diff --git a/core/classes/actions/class.action.debugApache.php b/core/classes/actions/class.action.debugApache.php index bdca0617..cbc0d091 100644 --- a/core/classes/actions/class.action.debugApache.php +++ b/core/classes/actions/class.action.debugApache.php @@ -7,6 +7,11 @@ * Github: https://github.com/Bearsampp */ +use Core\Classes\Lang; +use Core\Classes\Bins\BinApache; +use Core\Classes\Util; +use Core\Classes\Winbinder; + /** * Class ActionDebugApache * @@ -21,7 +26,7 @@ class ActionDebugApache * * @param array $args An array of arguments specifying the type of Apache debug information to retrieve. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppWinbinder; @@ -31,22 +36,22 @@ public function __construct($args) $caption = $bearsamppLang->getValue(Lang::DEBUG) . ' ' . $bearsamppLang->getValue(Lang::APACHE) . ' - '; // Determine the type of debug information requested and set the caption accordingly - if ($args[0] == BinApache::CMD_VERSION_NUMBER) { + if ($args[0] === BinApache::CMD_VERSION_NUMBER) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_VERSION_NUMBER); - } elseif ($args[0] == BinApache::CMD_COMPILE_SETTINGS) { + } elseif ($args[0] === BinApache::CMD_COMPILE_SETTINGS) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_COMPILE_SETTINGS); - } elseif ($args[0] == BinApache::CMD_COMPILED_MODULES) { + } elseif ($args[0] === BinApache::CMD_COMPILED_MODULES) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_COMPILED_MODULES); - } elseif ($args[0] == BinApache::CMD_CONFIG_DIRECTIVES) { + } elseif ($args[0] === BinApache::CMD_CONFIG_DIRECTIVES) { $editor = true; $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_CONFIG_DIRECTIVES); - } elseif ($args[0] == BinApache::CMD_VHOSTS_SETTINGS) { + } elseif ($args[0] === BinApache::CMD_VHOSTS_SETTINGS) { $editor = true; $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_VHOSTS_SETTINGS); - } elseif ($args[0] == BinApache::CMD_LOADED_MODULES) { + } elseif ($args[0] === BinApache::CMD_LOADED_MODULES) { $editor = true; $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_LOADED_MODULES); - } elseif ($args[0] == BinApache::CMD_SYNTAX_CHECK) { + } elseif ($args[0] === BinApache::CMD_SYNTAX_CHECK) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_APACHE_SYNTAX_CHECK); } $caption .= ' (' . $args[0] . ')'; @@ -55,9 +60,9 @@ public function __construct($args) $debugOutput = $bearsamppBins->getApache()->getCmdLineOutput($args[0]); // Handle syntax check specifically - if ($args[0] == BinApache::CMD_SYNTAX_CHECK) { + if ($args[0] === BinApache::CMD_SYNTAX_CHECK) { $msgBoxError = !$debugOutput['syntaxOk']; - $debugOutput['content'] = $debugOutput['syntaxOk'] ? 'Syntax OK !' : $debugOutput['content']; + $debugOutput['content'] = $debugOutput['syntaxOk'] ? 'Syntax OK!' : $debugOutput['content']; } // Display the debug output in an editor or message box diff --git a/core/classes/actions/class.action.debugMariadb.php b/core/classes/actions/class.action.debugMariadb.php index 4d75b82a..56492e8d 100644 --- a/core/classes/actions/class.action.debugMariadb.php +++ b/core/classes/actions/class.action.debugMariadb.php @@ -7,6 +7,10 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Bins\BinMariadb; +use Bearsampp\Core\Classes\Util; +use Bearsampp\Core\Classes\Lang; + /** * Class ActionDebugMariadb * @@ -19,15 +23,15 @@ class ActionDebugMariadb /** * ActionDebugMariadb constructor. * - * @param array $args Command-line arguments specifying the debugging action to perform. - * - * This constructor initializes the debugging process for MariaDB based on the provided arguments. + * Initializes the debugging process for MariaDB based on the provided arguments. * It supports three types of debugging actions: version check, variables display, and syntax check. * The output of the debugging action is displayed either in an editor or a message box. + * + * @param array $args Command-line arguments specifying the debugging action to perform. */ - public function __construct($args) + public function __construct(array $args) { - global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppWinbinder; + global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; if (isset($args[0]) && !empty($args[0])) { $editor = false; @@ -35,12 +39,12 @@ public function __construct($args) $caption = $bearsamppLang->getValue(Lang::DEBUG) . ' ' . $bearsamppLang->getValue(Lang::MARIADB) . ' - '; // Determine the type of debugging action based on the first argument - if ($args[0] == BinMariadb::CMD_VERSION) { + if ($args[0] === BinMariadb::CMD_VERSION) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_MARIADB_VERSION); - } elseif ($args[0] == BinMariadb::CMD_VARIABLES) { + } elseif ($args[0] === BinMariadb::CMD_VARIABLES) { $editor = true; $caption .= $bearsamppLang->getValue(Lang::DEBUG_MARIADB_VARIABLES); - } elseif ($args[0] == BinMariadb::CMD_SYNTAX_CHECK) { + } elseif ($args[0] === BinMariadb::CMD_SYNTAX_CHECK) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_MARIADB_SYNTAX_CHECK); } $caption .= ' (' . $args[0] . ')'; @@ -49,7 +53,7 @@ public function __construct($args) $debugOutput = $bearsamppBins->getMariadb()->getCmdLineOutput($args[0]); // Handle syntax check results - if ($args[0] == BinMariadb::CMD_SYNTAX_CHECK) { + if ($args[0] === BinMariadb::CMD_SYNTAX_CHECK) { $msgBoxError = !$debugOutput['syntaxOk']; $debugOutput['content'] = $debugOutput['syntaxOk'] ? 'Syntax OK !' : $debugOutput['content']; } diff --git a/core/classes/actions/class.action.debugMysql.php b/core/classes/actions/class.action.debugMysql.php index 79562aeb..0cdfe384 100644 --- a/core/classes/actions/class.action.debugMysql.php +++ b/core/classes/actions/class.action.debugMysql.php @@ -7,6 +7,10 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Bins\BinMysql; +use Bearsampp\Core\Classes\Util; +use Bearsampp\Core\Classes\Lang; + /** * Class ActionDebugMysql * @@ -18,15 +22,15 @@ class ActionDebugMysql /** * Constructor for ActionDebugMysql. * - * @param array $args An array of arguments specifying the MySQL command to execute. - * - * This constructor initializes the debugging process for MySQL based on the provided arguments. + * Initializes the debugging process for MySQL based on the provided arguments. * It supports commands for retrieving the MySQL version, variables, and performing a syntax check. * The output is displayed in a message box or editor based on the command. + * + * @param array $args An array of arguments specifying the MySQL command to execute. */ - public function __construct($args) + public function __construct(array $args) { - global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppWinbinder; + global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; if (isset($args[0]) && !empty($args[0])) { $editor = false; @@ -34,12 +38,12 @@ public function __construct($args) $caption = $bearsamppLang->getValue(Lang::DEBUG) . ' ' . $bearsamppLang->getValue(Lang::MYSQL) . ' - '; // Determine the command and set the caption accordingly - if ($args[0] == BinMysql::CMD_VERSION) { + if ($args[0] === BinMysql::CMD_VERSION) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_MYSQL_VERSION); - } elseif ($args[0] == BinMysql::CMD_VARIABLES) { + } elseif ($args[0] === BinMysql::CMD_VARIABLES) { $editor = true; $caption .= $bearsamppLang->getValue(Lang::DEBUG_MYSQL_VARIABLES); - } elseif ($args[0] == BinMysql::CMD_SYNTAX_CHECK) { + } elseif ($args[0] === BinMysql::CMD_SYNTAX_CHECK) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_MYSQL_SYNTAX_CHECK); } $caption .= ' (' . $args[0] . ')'; @@ -48,7 +52,7 @@ public function __construct($args) $debugOutput = $bearsamppBins->getMysql()->getCmdLineOutput($args[0]); // Handle syntax check results - if ($args[0] == BinMysql::CMD_SYNTAX_CHECK) { + if ($args[0] === BinMysql::CMD_SYNTAX_CHECK) { $msgBoxError = !$debugOutput['syntaxOk']; $debugOutput['content'] = $debugOutput['syntaxOk'] ? 'Syntax OK !' : $debugOutput['content']; } diff --git a/core/classes/actions/class.action.debugPostgresql.php b/core/classes/actions/class.action.debugPostgresql.php index 5fbe4c80..4c2301ea 100644 --- a/core/classes/actions/class.action.debugPostgresql.php +++ b/core/classes/actions/class.action.debugPostgresql.php @@ -7,6 +7,10 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Bins\BinPostgresql; +use Bearsampp\Core\Classes\Util; +use Bearsampp\Core\Classes\Lang; + /** * Class ActionDebugPostgresql * @@ -18,25 +22,26 @@ class ActionDebugPostgresql /** * Constructor for ActionDebugPostgresql. * - * @param array $args An array of arguments where the first element is expected to be a PostgreSQL command. - * - * This constructor initializes the debugging process for PostgreSQL. It checks the provided arguments, + * Initializes the debugging process for PostgreSQL. It checks the provided arguments, * retrieves the command line output for the specified PostgreSQL command, and displays it in a message box. * + * @param array $args An array of arguments where the first element is expected to be a PostgreSQL command. + * * Global variables used: * - $bearsamppLang: Provides language-specific strings. * - $bearsamppBins: Provides access to Bearsampp binaries, including PostgreSQL. * - $bearsamppWinbinder: Handles the display of message boxes. */ - public function __construct($args) + public function __construct(array $args) { - global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppWinbinder; + global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; if (isset($args[0]) && !empty($args[0])) { $editor = false; $msgBoxError = false; $caption = $bearsamppLang->getValue(Lang::DEBUG) . ' ' . $bearsamppLang->getValue(Lang::POSTGRESQL) . ' - '; - if ($args[0] == BinPostgresql::CMD_VERSION) { + + if ($args[0] === BinPostgresql::CMD_VERSION) { $caption .= $bearsamppLang->getValue(Lang::DEBUG_POSTGRESQL_VERSION); } $caption .= ' (' . $args[0] . ')'; diff --git a/core/classes/actions/class.action.editAlias.php b/core/classes/actions/class.action.editAlias.php index 5d09edd4..6da1fc2b 100644 --- a/core/classes/actions/class.action.editAlias.php +++ b/core/classes/actions/class.action.editAlias.php @@ -7,24 +7,27 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Util; +use Bearsampp\Core\Classes\Lang; + /** * Class ActionEditAlias * Handles the editing of Apache aliases within the Bearsampp application. */ class ActionEditAlias { - private $initName; - private $wbWindow; - private $wbLabelName; - private $wbInputName; - private $wbLabelDest; - private $wbInputDest; - private $wbBtnDest; - private $wbLabelExp; - private $wbProgressBar; - private $wbBtnSave; - private $wbBtnDelete; - private $wbBtnCancel; + private string $initName; + private object $wbWindow; + private object $wbLabelName; + private object $wbInputName; + private object $wbLabelDest; + private object $wbInputDest; + private object $wbBtnDest; + private object $wbLabelExp; + private object $wbProgressBar; + private object $wbBtnSave; + private object $wbBtnDelete; + private object $wbBtnCancel; const GAUGE_SAVE = 2; const GAUGE_DELETE = 2; @@ -35,34 +38,57 @@ class ActionEditAlias * * @param array $args Command line arguments passed to the script. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppRoot, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder; if (isset($args[0]) && !empty($args[0])) { $filePath = $bearsamppRoot->getAliasPath() . '/' . $args[0] . '.conf'; $fileContent = file_get_contents($filePath); - if (preg_match('/^Alias \/' . $args[0] . ' "(.+)"/', $fileContent, $match)) { + if (preg_match('/^Alias \/' . preg_quote($args[0], '/') . ' "(.+)"/', $fileContent, $match)) { $this->initName = $args[0]; $initDest = Util::formatWindowsPath($match[1]); - $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : ''; + $apachePortUri = $bearsamppBins->getApache()->getPort() !== 80 ? ':' . $bearsamppBins->getApache()->getPort() : ''; $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initName), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP); + $this->wbWindow = $bearsamppWinbinder->createAppWindow( + sprintf($bearsamppLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initName), + 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, $this->initName, 105, 13, 150, null); + $this->wbLabelName = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT + ); + $this->wbInputName = $bearsamppWinbinder->createInputText( + $this->wbWindow, $this->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->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, $this->initName, $initDest), 15, 80, 470, 50); + $this->wbLabelExp = $bearsamppWinbinder->createLabel( + $this->wbWindow, sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $this->initName, $initDest), 15, 80, 470, 50 + ); - $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190); - $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132); - $this->wbBtnDelete = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132); - $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132); + $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( + $this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190 + ); + $this->wbBtnSave = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132 + ); + $this->wbBtnDelete = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132 + ); + $this->wbBtnCancel = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132 + ); $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow'); $bearsamppWinbinder->mainLoop(); @@ -74,17 +100,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]); @@ -94,7 +120,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); @@ -113,15 +139,17 @@ 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 ($aliasName != $this->initName && is_file($bearsamppRoot->getAliasPath() . '/' . $aliasName . '.conf')) { + if ($aliasName !== $this->initName && 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; } @@ -133,10 +161,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; @@ -146,7 +178,8 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $boxTitle = $bearsamppLang->getValue(Lang::DELETE_ALIAS_TITLE); $confirm = $bearsamppWinbinder->messageBoxYesNo( sprintf($bearsamppLang->getValue(Lang::DELETE_ALIAS), $this->initName), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->incrProgressBar($this->wbProgressBar); @@ -159,12 +192,14 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $bearsamppWinbinder->messageBoxInfo( sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVED), $this->initName), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->destroyWindow($window); } else { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVE_ERROR), $bearsamppRoot->getAliasPath() . '/' . $this->initName . '.conf'), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); } } diff --git a/core/classes/actions/class.action.editVhost.php b/core/classes/actions/class.action.editVhost.php index bdcba26c..6a6fea2c 100644 --- a/core/classes/actions/class.action.editVhost.php +++ b/core/classes/actions/class.action.editVhost.php @@ -7,24 +7,29 @@ * Github: https://github.com/Bearsampp */ +use Bearsampp\Core\Classes\Util; +use Bearsampp\Core\Classes\Lang; +use Bearsampp\Core\Classes\TplService; +use Bearsampp\Core\Classes\Bins\BinApache; + /** * Class ActionEditVhost * Handles the editing of virtual hosts within the Bearsampp application. */ class ActionEditVhost { - private $initServerName; - private $wbWindow; - private $wbLabelServerName; - private $wbInputServerName; - private $wbLabelDocRoot; - private $wbInputDocRoot; - private $wbBtnDocRoot; - private $wbLabelExp; - private $wbProgressBar; - private $wbBtnSave; - private $wbBtnDelete; - private $wbBtnCancel; + private string $initServerName; + private object $wbWindow; + private object $wbLabelServerName; + private object $wbInputServerName; + private object $wbLabelDocRoot; + private object $wbInputDocRoot; + private object $wbBtnDocRoot; + private object $wbLabelExp; + private object $wbProgressBar; + private object $wbBtnSave; + private object $wbBtnDelete; + private object $wbBtnCancel; const GAUGE_SAVE = 3; const GAUGE_DELETE = 2; @@ -35,7 +40,7 @@ class ActionEditVhost * * @param array $args Arguments passed to the constructor, typically containing the server name. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder; @@ -47,21 +52,44 @@ public function __construct($args) $initDocumentRoot = Util::formatWindowsPath(trim($matchDocumentRoot[1])); $bearsamppWinbinder->reset(); - $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP); + $this->wbWindow = $bearsamppWinbinder->createAppWindow( + sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName), + 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP + ); - $this->wbLabelServerName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT); - $this->wbInputServerName = $bearsamppWinbinder->createInputText($this->wbWindow, $this->initServerName, 105, 13, 150, null); + $this->wbLabelServerName = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT + ); + $this->wbInputServerName = $bearsamppWinbinder->createInputText( + $this->wbWindow, $this->initServerName, 105, 13, 150, null + ); - $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT); - $this->wbInputDocRoot = $bearsamppWinbinder->createInputText($this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY); - $this->wbBtnDocRoot = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110); + $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel( + $this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT + ); + $this->wbInputDocRoot = $bearsamppWinbinder->createInputText( + $this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY + ); + $this->wbBtnDocRoot = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110 + ); - $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $this->initServerName, $initDocumentRoot), 15, 80, 470, 50); + $this->wbLabelExp = $bearsamppWinbinder->createLabel( + $this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $this->initServerName, $initDocumentRoot), 15, 80, 470, 50 + ); - $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190); - $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132); - $this->wbBtnDelete = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132); - $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132); + $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( + $this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190 + ); + $this->wbBtnSave = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132 + ); + $this->wbBtnDelete = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132 + ); + $this->wbBtnCancel = $bearsamppWinbinder->createButton( + $this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132 + ); $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow'); $bearsamppWinbinder->mainLoop(); @@ -73,13 +101,13 @@ public function __construct($args) /** * Processes window events and handles user interactions. * - * @param mixed $window The window object. + * @param object $window The window object. * @param int $id The ID of the control that triggered the event. - * @param mixed $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 $bearsamppRoot, $bearsamppBins, $bearsamppLang, $bearsamppOpenSsl, $bearsamppWinbinder; @@ -92,7 +120,7 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot) ); - $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true); + $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], !empty($serverName)); break; case $this->wbBtnDocRoot[WinBinder::CTRL_ID]: $documentRoot = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot); @@ -113,15 +141,17 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) if (!Util::isValidDomainName($serverName)) { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $serverName), - $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE)); + $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); break; } - if ($serverName != $this->initServerName && is_file($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf')) { + if ($serverName !== $this->initServerName && is_file($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf')) { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName), - sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName)); + sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); break; } @@ -138,12 +168,14 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $bearsamppWinbinder->messageBoxInfo( sprintf($bearsamppLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot), - sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName)); + sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName) + ); $bearsamppWinbinder->destroyWindow($window); } else { $bearsamppWinbinder->messageBoxError( $bearsamppLang->getValue(Lang::VHOST_CREATED_ERROR), - sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName)); + sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName) + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); } // Reload to remove host @@ -156,7 +188,8 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $boxTitle = $bearsamppLang->getValue(Lang::DELETE_VHOST_TITLE); $confirm = $bearsamppWinbinder->messageBoxYesNo( sprintf($bearsamppLang->getValue(Lang::DELETE_VHOST), $this->initServerName), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->incrProgressBar($this->wbProgressBar); @@ -169,12 +202,14 @@ public function processWindow($window, $id, $ctrl, $param1, $param2) $bearsamppWinbinder->messageBoxInfo( sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVED), $this->initServerName), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->destroyWindow($window); } else { $bearsamppWinbinder->messageBoxError( sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVE_ERROR), $bearsamppRoot->getVhostsPath() . '/' . $this->initServerName . '.conf'), - $boxTitle); + $boxTitle + ); $bearsamppWinbinder->resetProgressBar($this->wbProgressBar); } } diff --git a/core/classes/actions/class.action.enable.php b/core/classes/actions/class.action.enable.php index 53bb4e62..3cbc6c06 100644 --- a/core/classes/actions/class.action.enable.php +++ b/core/classes/actions/class.action.enable.php @@ -17,48 +17,38 @@ class ActionEnable /** * Constructor for the ActionEnable class. * - * @param array $args An array of arguments where the first element is the service name and the second element is the enable flag. + * @param array $args An array of arguments where the first element is the service name and the second element is the enable flag. * - * @global object $bearsamppBins Global object containing instances of various services. + * @global object $bearsamppBins Global object containing instances of various services. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppBins; - if ( isset( $args[0] ) && !empty( $args[0] ) && isset( $args[1] ) ) { + if (isset($args[0]) && !empty($args[0]) && isset($args[1])) { Util::startLoading(); - if ( $args[0] == $bearsamppBins->getApache()->getName() ) { - $bearsamppBins->getApache()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getPhp()->getName() ) { - $bearsamppBins->getPhp()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMysql()->getName() ) { - $bearsamppBins->getMysql()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMariadb()->getName() ) { - $bearsamppBins->getMariadb()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getNodejs()->getName() ) { - $bearsamppBins->getNodejs()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getPostgresql()->getName() ) { - $bearsamppBins->getPostgresql()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getFilezilla()->getName() ) { - $bearsamppBins->getFilezilla()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMailhog()->getName() ) { - $bearsamppBins->getMailhog()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMailpit()->getName() ) { - $bearsamppBins->getMailpit()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getMemcached()->getName() ) { - $bearsamppBins->getMemcached()->setEnable( $args[1], true ); - } - elseif ( $args[0] == $bearsamppBins->getXlight()->getName() ) { - $bearsamppBins->getXlight()->setEnable( $args[1], true ); + if ($args[0] === $bearsamppBins->getApache()->getName()) { + $bearsamppBins->getApache()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getPhp()->getName()) { + $bearsamppBins->getPhp()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMysql()->getName()) { + $bearsamppBins->getMysql()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMariadb()->getName()) { + $bearsamppBins->getMariadb()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getNodejs()->getName()) { + $bearsamppBins->getNodejs()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getPostgresql()->getName()) { + $bearsamppBins->getPostgresql()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getFilezilla()->getName()) { + $bearsamppBins->getFilezilla()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMailhog()->getName()) { + $bearsamppBins->getMailhog()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMailpit()->getName()) { + $bearsamppBins->getMailpit()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getMemcached()->getName()) { + $bearsamppBins->getMemcached()->setEnable($args[1], true); + } elseif ($args[0] === $bearsamppBins->getXlight()->getName()) { + $bearsamppBins->getXlight()->setEnable($args[1], true); } } } diff --git a/core/classes/actions/class.action.exec.php b/core/classes/actions/class.action.exec.php index 06043c2a..dd5f9477 100644 --- a/core/classes/actions/class.action.exec.php +++ b/core/classes/actions/class.action.exec.php @@ -19,12 +19,12 @@ class ActionExec /** * Constant representing the 'quit' action. */ - const QUIT = 'quit'; + public const QUIT = 'quit'; /** * Constant representing the 'restart' action. */ - const RESTART = 'restart'; + public const RESTART = 'restart'; /** * ActionExec constructor. @@ -35,15 +35,15 @@ class ActionExec * * @param array $args Arguments passed to the constructor (not used in the current implementation). */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppCore; if (file_exists($bearsamppCore->getExec())) { $action = file_get_contents($bearsamppCore->getExec()); - if ($action == self::QUIT) { + if ($action === self::QUIT) { Batch::exitApp(); - } elseif ($action == self::RESTART) { + } elseif ($action === self::RESTART) { Batch::restartApp(); } @unlink($bearsamppCore->getExec()); diff --git a/core/classes/actions/class.action.ext.php b/core/classes/actions/class.action.ext.php index ed3d2aad..c80b8d60 100644 --- a/core/classes/actions/class.action.ext.php +++ b/core/classes/actions/class.action.ext.php @@ -13,32 +13,36 @@ class ActionExt { // Constants for different actions - const START = 'start'; - const STOP = 'stop'; - const RELOAD = 'reload'; - const REFRESH = 'refresh'; + public const START = 'start'; + public const STOP = 'stop'; + public const RELOAD = 'reload'; + public const REFRESH = 'refresh'; // Constants for status codes - const STATUS_ERROR = 2; - const STATUS_WARNING = 1; - const STATUS_SUCCESS = 0; + public const STATUS_ERROR = 2; + public const STATUS_WARNING = 1; + public const STATUS_SUCCESS = 0; /** - * @var int Holds the current status of the action. + * Holds the current status of the action. + * + * @var int */ - private $status = self::STATUS_SUCCESS; + private int $status = self::STATUS_SUCCESS; /** - * @var string Holds the logs generated during the action execution. + * Holds the logs generated during the action execution. + * + * @var string */ - private $logs = ''; + private string $logs = ''; /** * Constructor for the ActionExt class. * * @param array $args The command line arguments passed to the action. */ - public function __construct($args) + public function __construct(array $args) { if (!isset($args[0]) || empty($args[0])) { $this->addLog('No args defined'); @@ -53,7 +57,7 @@ public function __construct($args) $action = $args[0]; - $newArgs = array(); + $newArgs = []; foreach ($args as $key => $arg) { if ($key > 0) { $newArgs[] = $arg; @@ -72,7 +76,7 @@ public function __construct($args) return; } - call_user_func(array($this, $method), $newArgs); + call_user_func([$this, $method], $newArgs); $this->sendLogs(); } @@ -81,14 +85,14 @@ public function __construct($args) * * @return array The list of available actions. */ - private function getProcs() + private function getProcs(): array { - return array( + return [ self::START, self::STOP, self::RELOAD, self::REFRESH - ); + ]; } /** @@ -96,7 +100,7 @@ private function getProcs() * * @param string $data The log entry to add. */ - private function addLog($data) + private function addLog(string $data): void { $this->logs .= $data . "\n"; } @@ -106,7 +110,7 @@ private function addLog($data) * * @param int $status The status code to set. */ - private function setStatus($status) + private function setStatus(int $status): void { $this->status = $status; } @@ -114,12 +118,12 @@ private function setStatus($status) /** * Sends the logs as a JSON-encoded response. */ - private function sendLogs() + private function sendLogs(): void { - echo json_encode(array( + echo json_encode([ 'status' => $this->status, 'response' => $this->logs - )); + ]); } /** @@ -127,7 +131,7 @@ private function sendLogs() * * @param array $args The command line arguments passed to the action. */ - private function procStart($args) + private function procStart(array $args): void { global $bearsamppRoot, $bearsamppWinbinder; @@ -145,7 +149,7 @@ private function procStart($args) * * @param array $args The command line arguments passed to the action. */ - private function procStop($args) + private function procStop(array $args): void { global $bearsamppBins; @@ -173,7 +177,7 @@ private function procStop($args) * * @param array $args The command line arguments passed to the action. */ - private function procReload($args) + private function procReload(array $args): void { global $bearsamppRoot, $bearsamppBins, $bearsamppWinbinder; @@ -214,7 +218,7 @@ private function procReload($args) * * @param array $args The command line arguments passed to the action. */ - private function procRefresh($args) + private function procRefresh(array $args): void { global $bearsamppAction; diff --git a/core/classes/actions/class.action.genSslCertificate.php b/core/classes/actions/class.action.genSslCertificate.php index 14192682..23a8812e 100644 --- a/core/classes/actions/class.action.genSslCertificate.php +++ b/core/classes/actions/class.action.genSslCertificate.php @@ -35,7 +35,7 @@ class ActionGenSslCertificate * * @param array $args Command line arguments passed to the script. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder; @@ -73,7 +73,7 @@ public function __construct($args) * @param mixed $param1 Additional parameter 1. * @param mixed $param2 Additional parameter 2. */ - public function processWindow($window, $id, $ctrl, $param1, $param2) + public function processWindow($window, int $id, $ctrl, mixed $param1, mixed $param2): void { global $bearsamppLang, $bearsamppOpenSsl, $bearsamppWinbinder; diff --git a/core/classes/actions/class.action.launchStartup.php b/core/classes/actions/class.action.launchStartup.php index 67eea02e..2db23410 100644 --- a/core/classes/actions/class.action.launchStartup.php +++ b/core/classes/actions/class.action.launchStartup.php @@ -25,13 +25,13 @@ class ActionLaunchStartup * @param array $args An array of arguments where the first element should be either Config::ENABLED or Config::DISABLED * to indicate the desired launch startup setting. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppConfig; if (isset($args[0])) { Util::startLoading(); - $launchStartup = $args[0] == Config::ENABLED; + $launchStartup = $args[0] === Config::ENABLED; if ($launchStartup) { Util::enableLaunchStartup(); } else { diff --git a/core/classes/actions/class.action.loading.php b/core/classes/actions/class.action.loading.php index 99df6a62..8a4a5dd1 100644 --- a/core/classes/actions/class.action.loading.php +++ b/core/classes/actions/class.action.loading.php @@ -36,7 +36,7 @@ class ActionLoading * * @param array $args The arguments passed to the constructor. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppCore, $bearsamppLang, $bearsamppWinbinder; @@ -65,7 +65,7 @@ public function __construct($args) * * @param int $nb The number of steps to increment the progress bar by. Default is 1. */ - public function incrProgressBar($nb = 1) + public function incrProgressBar(int $nb = 1): void { global $bearsamppCore, $bearsamppWinbinder; @@ -87,7 +87,7 @@ public function incrProgressBar($nb = 1) * @param mixed $param1 The first parameter of the event. * @param mixed $param2 The second parameter of the event. */ - public function processLoading($window, $id, $ctrl, $param1, $param2) + public function processLoading(mixed $window, int $id, mixed $ctrl, mixed $param1, mixed $param2): void { global $bearsamppRoot, $bearsamppWinbinder; diff --git a/core/classes/actions/class.action.manualRestart.php b/core/classes/actions/class.action.manualRestart.php index 752b3edf..97c50b81 100644 --- a/core/classes/actions/class.action.manualRestart.php +++ b/core/classes/actions/class.action.manualRestart.php @@ -28,7 +28,7 @@ class ActionManualRestart * 4. Sets the application to restart. * 5. Stops the loading process. */ - public function __construct($args) + public function __construct(array $args) { global $bearsamppCore, $bearsamppBins; diff --git a/core/classes/actions/class.action.php b/core/classes/actions/class.action.php index b7e87995..6946d914 100644 --- a/core/classes/actions/class.action.php +++ b/core/classes/actions/class.action.php @@ -13,44 +13,44 @@ class Action { // Constants for different actions - const ABOUT = 'about'; - const ADD_ALIAS = 'addAlias'; - const ADD_VHOST = 'addVhost'; - const CHANGE_BROWSER = 'changeBrowser'; - const CHANGE_DB_ROOT_PWD = 'changeDbRootPwd'; - const CHANGE_PORT = 'changePort'; - const CHECK_PORT = 'checkPort'; - const CHECK_VERSION = 'checkVersion'; - const CLEAR_FOLDERS = 'clearFolders'; - const DEBUG_APACHE = 'debugApache'; - const DEBUG_MARIADB = 'debugMariadb'; - const DEBUG_MYSQL = 'debugMysql'; - const DEBUG_POSTGRESQL = 'debugPostgresql'; - const EDIT_ALIAS = 'editAlias'; - const EDIT_VHOST = 'editVhost'; - const ENABLE = 'enable'; - const EXEC = 'exec'; - const GEN_SSL_CERTIFICATE = 'genSslCertificate'; - const LAUNCH_STARTUP = 'launchStartup'; - const MANUAL_RESTART = 'manualRestart'; - const LOADING = 'loading'; - const QUIT = 'quit'; - const REBUILD_INI = 'rebuildIni'; - const REFRESH_REPOS = 'refreshRepos'; - const REFRESH_REPOS_STARTUP = 'refreshReposStartup'; - const RELOAD = 'reload'; - const RESTART = 'restart'; - const SERVICE = 'service'; - const STARTUP = 'startup'; - const SWITCH_APACHE_MODULE = 'switchApacheModule'; - const SWITCH_LANG = 'switchLang'; - const SWITCH_LOGS_VERBOSE = 'switchLogsVerbose'; - const SWITCH_PHP_EXTENSION = 'switchPhpExtension'; - const SWITCH_PHP_PARAM = 'switchPhpParam'; - const SWITCH_ONLINE = 'switchOnline'; - const SWITCH_VERSION = 'switchVersion'; + public const ABOUT = 'about'; + public const ADD_ALIAS = 'addAlias'; + public const ADD_VHOST = 'addVhost'; + public const CHANGE_BROWSER = 'changeBrowser'; + public const CHANGE_DB_ROOT_PWD = 'changeDbRootPwd'; + public const CHANGE_PORT = 'changePort'; + public const CHECK_PORT = 'checkPort'; + public const CHECK_VERSION = 'checkVersion'; + public const CLEAR_FOLDERS = 'clearFolders'; + public const DEBUG_APACHE = 'debugApache'; + public const DEBUG_MARIADB = 'debugMariadb'; + public const DEBUG_MYSQL = 'debugMysql'; + public const DEBUG_POSTGRESQL = 'debugPostgresql'; + public const EDIT_ALIAS = 'editAlias'; + public const EDIT_VHOST = 'editVhost'; + public const ENABLE = 'enable'; + public const EXEC = 'exec'; + public const GEN_SSL_CERTIFICATE = 'genSslCertificate'; + public const LAUNCH_STARTUP = 'launchStartup'; + public const MANUAL_RESTART = 'manualRestart'; + public const LOADING = 'loading'; + public const QUIT = 'quit'; + public const REBUILD_INI = 'rebuildIni'; + public const REFRESH_REPOS = 'refreshRepos'; + public const REFRESH_REPOS_STARTUP = 'refreshReposStartup'; + public const RELOAD = 'reload'; + public const RESTART = 'restart'; + public const SERVICE = 'service'; + public const STARTUP = 'startup'; + public const SWITCH_APACHE_MODULE = 'switchApacheModule'; + public const SWITCH_LANG = 'switchLang'; + public const SWITCH_LOGS_VERBOSE = 'switchLogsVerbose'; + public const SWITCH_PHP_EXTENSION = 'switchPhpExtension'; + public const SWITCH_PHP_PARAM = 'switchPhpParam'; + public const SWITCH_ONLINE = 'switchOnline'; + public const SWITCH_VERSION = 'switchVersion'; - const EXT = 'ext'; + public const EXT = 'ext'; /** * @var mixed Holds the current action instance. @@ -75,16 +75,16 @@ public function __construct() * * @return void */ - public function process() + public function process(): void { if ($this->exists()) { $action = Util::cleanArgv(1); $actionClass = 'Action' . ucfirst($action); - $args = array(); + $args = []; foreach ($_SERVER['argv'] as $key => $arg) { if ($key > 1) { - $args[] = $action == self::EXT ? $arg : base64_decode($arg); + $args[] = $action === self::EXT ? $arg : base64_decode($arg); } } @@ -107,7 +107,7 @@ public function process() * @param mixed $actionArgs Optional arguments for the action. * @return void */ - public function call($actionName, $actionArgs = null) + public function call(string $actionName, mixed $actionArgs = null): void { $actionClass = 'Action' . ucfirst($actionName); if (class_exists($actionClass)) { @@ -124,7 +124,7 @@ public function call($actionName, $actionArgs = null) * * @return bool Returns true if the action exists, false otherwise. */ - public function exists() + public function exists(): bool { return isset($_SERVER['argv']) && isset($_SERVER['argv'][1]) diff --git a/core/classes/actions/class.action.quickPick.php b/core/classes/actions/class.action.quickPick.php index d5023ad0..5133b621 100644 --- a/core/classes/actions/class.action.quickPick.php +++ b/core/classes/actions/class.action.quickPick.php @@ -1,11 +1,9 @@ ['type' => 'application'], 'Apache' => ['type' => 'binary'], 'Bruno' => ['type' => 'tools'], @@ -64,14 +62,14 @@ class QuickPick * * An associative array where the key is the module name and the value is an array containing the module versions. */ - private $versions = []; + private array $versions = []; /** * @var string $jsonFilePath * * The file path to the local quickpick-releases.json file. */ - private $jsonFilePath; + private string $jsonFilePath; /** * Constructor to initialize the jsonFilePath. @@ -89,13 +87,13 @@ public function __construct() */ public function getModules(): array { - return array_keys( $this->modules ); + return array_keys($this->modules); } /** * Loads the QuickPick interface with the available modules and their versions. * - * @param string $imagesPath The path to the images directory. + * @param string $imagesPath The path to the images directory. * * @return string The HTML content of the QuickPick interface. * @@ -108,7 +106,7 @@ public function loadQuickpick(string $imagesPath): string $modules = $this->getModules(); $versions = $this->getVersions(); - return $this->getQuickpickMenu( $modules, $versions, $imagesPath ); + return $this->getQuickpickMenu($modules, $versions, $imagesPath); } /** @@ -122,29 +120,28 @@ public function loadQuickpick(string $imagesPath): string * otherwise returns false. * @throws Exception */ - public function checkQuickpickJson() + public function checkQuickpickJson(): array|false { // Initialize variables $localFileCreationTime = 0; // Get the creation time of the local file if it exists - if ( file_exists( $this->jsonFilePath ) ) { - $localFileCreationTime = filectime( $this->jsonFilePath ); - } - else { + if (file_exists($this->jsonFilePath)) { + $localFileCreationTime = filectime($this->jsonFilePath); + } else { $result = $this->rebuildQuickpickJson(); } // Get the creation time of the remote file - $headers = get_headers( self::JSON_URL, 1 ); - if ( $headers === false || !isset( $headers['Last-Modified'] ) ) { + $headers = get_headers(self::JSON_URL, 1); + if ($headers === false || !isset($headers['Last-Modified'])) { // If we cannot get the headers or Last-Modified is not set, assume no update is needed return false; } - $remoteFileCreationTime = strtotime( $headers['Last-Modified'] ); + $remoteFileCreationTime = strtotime($headers['Last-Modified']); // Compare the creation times - if ( $remoteFileCreationTime > $localFileCreationTime || $localFileCreationTime === 0 ) { + if ($remoteFileCreationTime > $localFileCreationTime || $localFileCreationTime === 0) { return $this->rebuildQuickpickJson(); } @@ -159,16 +156,16 @@ public function checkQuickpickJson() */ public function getQuickpickJson(): array { - $content = @file_get_contents( $this->jsonFilePath ); - if ( $content === false ) { - Util::logError( 'Error fetching content from JSON file: ' . $this->jsonFilePath ); + $content = @file_get_contents($this->jsonFilePath); + if ($content === false) { + Util::logError('Error fetching content from JSON file: ' . $this->jsonFilePath); return ['error' => 'Error fetching JSON file']; } - $data = json_decode( $content, true ); - if ( json_last_error() !== JSON_ERROR_NONE ) { - Util::logError( 'Error decoding JSON content: ' . json_last_error_msg() ); + $data = json_decode($content, true); + if (json_last_error() !== JSON_ERROR_NONE) { + Util::logError('Error decoding JSON content: ' . json_last_error_msg()); return ['error' => 'Error decoding JSON content']; } @@ -184,25 +181,25 @@ public function getQuickpickJson(): array */ public function rebuildQuickpickJson(): array { - Util::logDebug( 'Fetching JSON file: ' . $this->jsonFilePath ); + Util::logDebug('Fetching JSON file: ' . $this->jsonFilePath); // Define the URL of the remote JSON file $url = self::JSON_URL; // Fetch the JSON content from the URL - $jsonContent = file_get_contents( $url ); + $jsonContent = file_get_contents($url); - if ( $jsonContent === false ) { + if ($jsonContent === false) { // Handle error if the file could not be fetched - throw new Exception( 'Failed to fetch JSON content from the URL.' ); + throw new Exception('Failed to fetch JSON content from the URL.'); } // Save the JSON content to the specified path - $result = file_put_contents( $this->jsonFilePath, $jsonContent ); + $result = file_put_contents($this->jsonFilePath, $jsonContent); - if ( $result === false ) { + if ($result === false) { // Handle error if the file could not be saved - throw new Exception( 'Failed to save JSON content to the specified path.' ); + throw new Exception('Failed to save JSON content to the specified path.'); } // Return success message @@ -219,32 +216,31 @@ public function rebuildQuickpickJson(): array */ public function getVersions(): array { - Util::logDebug( 'Versions called' ); + Util::logDebug('Versions called'); $versions = []; $jsonData = $this->getQuickpickJson(); - foreach ( $jsonData as $entry ) { - if ( is_array( $entry ) ) { - if ( isset( $entry['module'] ) && is_string( $entry['module'] ) ) { - if ( isset( $entry['versions'] ) && is_array( $entry['versions'] ) ) { - $versions[$entry['module']] = array_column( $entry['versions'], null, 'version' ); + foreach ($jsonData as $entry) { + if (is_array($entry)) { + if (isset($entry['module']) && is_string($entry['module'])) { + if (isset($entry['versions']) && is_array($entry['versions'])) { + $versions[$entry['module']] = array_column($entry['versions'], null, 'version'); } } - } - else { - Util::logError( 'Invalid entry format in JSON data' ); + } else { + Util::logError('Invalid entry format in JSON data'); } } - if ( empty( $versions ) ) { - Util::logError( 'No versions found' ); + if (empty($versions)) { + Util::logError('No versions found'); return ['error' => 'No versions found']; } - Util::logDebug( 'Found versions' ); + Util::logDebug('Found versions'); $this->versions = $versions; @@ -257,23 +253,22 @@ public function getVersions(): array * This method reads the quickpick-releases.json file to find the URL associated with the given module * and version. It logs the process and returns the URL if found, or an error message if not. * - * @param string $module The name of the module. - * @param string $version The version of the module. + * @param string $module The name of the module. + * @param string $version The version of the module. * * @return string|array The URL of the specified module version or an error message if the version is not found. */ - public function getModuleUrl(string $module, string $version) + public function getModuleUrl(string $module, string $version): string|array { $this->getVersions(); - Util::logDebug( 'getModuleUrl called for module: ' . $module . ' version: ' . $version ); - $url = trim( $this->versions['module-' . strtolower( $module )][$version]['url'] ); - if ( $url <> '' ) { - Util::logDebug( 'Found URL for version: ' . $version . ' URL: ' . $url ); + Util::logDebug('getModuleUrl called for module: ' . $module . ' version: ' . $version); + $url = trim($this->versions['module-' . strtolower($module)][$version]['url']); + if ($url !== '') { + Util::logDebug('Found URL for version: ' . $version . ' URL: ' . $url); return $url; - } - else { - Util::logError( 'Version not found: ' . $version ); + } else { + Util::logError('Version not found: ' . $version); return ['error' => 'Version not found']; } @@ -298,57 +293,57 @@ public function checkDownloadId(): bool { global $bearsamppConfig; - Util::logDebug( 'checkDownloadId method called.' ); + Util::logDebug('checkDownloadId method called.'); // Ensure the global config is available - if ( !isset( $bearsamppConfig ) ) { - Util::logError( 'Global configuration is not set.' ); + if (!isset($bearsamppConfig)) { + Util::logError('Global configuration is not set.'); return false; } $DownloadId = $bearsamppConfig->getDownloadId(); - Util::logDebug( 'DownloadId is: ' . $DownloadId ); + Util::logDebug('DownloadId is: ' . $DownloadId); // Ensure the license key is not empty - if ( empty( $DownloadId ) ) { - Util::logError( 'License key is empty.' ); + if (empty($DownloadId)) { + Util::logError('License key is empty.'); return false; } $url = self::API_URL . self::API_KEY . '&download_id=' . $DownloadId; - Util::logDebug( 'API URL: ' . $url ); + Util::logDebug('API URL: ' . $url); - $response = @file_get_contents( $url ); + $response = @file_get_contents($url); // Check if the response is false - if ( $response === false ) { + if ($response === false) { $error = error_get_last(); - Util::logError( 'Error fetching API response: ' . $error['message'] ); + Util::logError('Error fetching API response: ' . $error['message']); return false; } - Util::logDebug( 'API response: ' . $response ); + Util::logDebug('API response: ' . $response); - $data = json_decode( $response, true ); + $data = json_decode($response, true); // Check if the JSON decoding was successful - if ( json_last_error() !== JSON_ERROR_NONE ) { - Util::logError( 'Error decoding JSON response: ' . json_last_error_msg() ); + if (json_last_error() !== JSON_ERROR_NONE) { + Util::logError('Error decoding JSON response: ' . json_last_error_msg()); return false; } // Validate the response data - if ( isset( $data['success'] ) && $data['success'] === true && isset( $data['data'] ) && is_array( $data['data'] ) && count( $data['data'] ) > 0 ) { - Util::logDebug( 'License key valid: ' . $DownloadId ); + if (isset($data['success']) && $data['success'] === true && isset($data['data']) && is_array($data['data']) && count($data['data']) > 0) { + Util::logDebug('License key valid: ' . $DownloadId); return true; } - Util::logError( 'Invalid license key: ' . $DownloadId ); + Util::logError('Invalid license key: ' . $DownloadId); return false; } @@ -360,8 +355,8 @@ public function checkDownloadId(): bool * If the URL is found, it fetches and unzips the module. If the URL is not found, it logs an error * and returns an error message. * - * @param string $module The name of the module to install. - * @param string $version The version of the module to install. + * @param string $module The name of the module to install. + * @param string $version The version of the module to install. * * @return array An array containing the status and message of the installation process. * If successful, it returns the response from the fetchAndUnzipModule method. @@ -370,29 +365,28 @@ public function checkDownloadId(): bool public function installModule(string $module, string $version): array { // Find the module URL and module name from the data - $moduleUrl = $this->getModuleUrl( $module, $version ); + $moduleUrl = $this->getModuleUrl($module, $version); - if ( is_array( $moduleUrl ) && isset( $moduleUrl['error'] ) ) { - Util::logError( 'Module URL not found for module: ' . $module . ' version: ' . $version ); + if (is_array($moduleUrl) && isset($moduleUrl['error'])) { + Util::logError('Module URL not found for module: ' . $module . ' version: ' . $version); return ['error' => 'Module URL not found']; } - if ( empty( $moduleUrl ) ) { - Util::logError( 'Module URL not found for module: ' . $module . ' version: ' . $version ); + if (empty($moduleUrl)) { + Util::logError('Module URL not found for module: ' . $module . ' version: ' . $version); return ['error' => 'Module URL not found']; } $state = Util::checkInternetState(); - if ( $state ) { - $response = $this->fetchAndUnzipModule( $moduleUrl, $module ); - Util::logDebug( 'Response is: ' . print_r( $response, true ) ); + if ($state) { + $response = $this->fetchAndUnzipModule($moduleUrl, $module); + Util::logDebug('Response is: ' . print_r($response, true)); return $response; - } - else { - Util::logError( 'No internet connection available.' ); + } else { + Util::logError('No internet connection available.'); return ['error' => 'No internet connection']; } @@ -401,75 +395,75 @@ public function installModule(string $module, string $version): array /** * Fetches the module URL and stores it in /tmp, then unzips the file based on its extension. * - * @param string $moduleUrl The URL of the module to fetch. - * @param string $module The name of the module. + * @param string $moduleUrl The URL of the module to fetch. + * @param string $module The name of the module. * * @return array An array containing the status and message. */ public function fetchAndUnzipModule(string $moduleUrl, string $module): array -{ - Util::logDebug("$module is: " . $module); - - global $bearsamppRoot, $bearsamppCore; - $tmpDir = $bearsamppRoot->getTmpPath(); - Util::logDebug('Temporary Directory: ' . $tmpDir); - - $fileName = basename($moduleUrl); - Util::logDebug('File Name: ' . $fileName); + { + Util::logDebug("$module is: " . $module); - $tmpFilePath = $tmpDir . '/' . $fileName; - Util::logDebug('File Path: ' . $tmpFilePath); + global $bearsamppRoot, $bearsamppCore; + $tmpDir = $bearsamppRoot->getTmpPath(); + Util::logDebug('Temporary Directory: ' . $tmpDir); - $moduleName = str_replace('module-', '', $module); - Util::logDebug('Module Name: ' . $moduleName); + $fileName = basename($moduleUrl); + Util::logDebug('File Name: ' . $fileName); - $moduleType = $this->modules[$module]['type']; - Util::logDebug('Module Type: ' . $moduleType); + $tmpFilePath = $tmpDir . '/' . $fileName; + Util::logDebug('File Path: ' . $tmpFilePath); - // Get module type - $destination = $this->getModuleDestinationPath($moduleType, $moduleName); - Util::logDebug('Destination: ' . $destination); + $moduleName = str_replace('module-', '', $module); + Util::logDebug('Module Name: ' . $moduleName); - // Retrieve the file path from the URL using the bearsamppCore module, - // passing the module URL and temporary file path, with the use Progress Bar parameter set to true. - $result = $bearsamppCore->getFileFromUrl($moduleUrl, $tmpFilePath, true); + $moduleType = $this->modules[$module]['type']; + Util::logDebug('Module Type: ' . $moduleType); - // Check if $result is false - if ($result === false) { - Util::logError('Failed to retrieve file from URL: ' . $moduleUrl); - return ['error' => 'Failed to retrieve file from URL']; - } + // Get module type + $destination = $this->getModuleDestinationPath($moduleType, $moduleName); + Util::logDebug('Destination: ' . $destination); - // Determine the file extension and call the appropriate unzipping function - $fileExtension = pathinfo($tmpFilePath, PATHINFO_EXTENSION); - Util::logDebug('File extension: ' . $fileExtension); + // Retrieve the file path from the URL using the bearsamppCore module, + // passing the module URL and temporary file path, with the use Progress Bar parameter set to true. + $result = $bearsamppCore->getFileFromUrl($moduleUrl, $tmpFilePath, true); - if ($fileExtension === '7z' || $fileExtension === 'zip') { - // Send phase indicator for extraction - echo json_encode(['phase' => 'extracting']); - if (ob_get_length()) { - ob_flush(); + // Check if $result is false + if ($result === false) { + Util::logError('Failed to retrieve file from URL: ' . $moduleUrl); + return ['error' => 'Failed to retrieve file from URL']; } - flush(); - $unzipResult = $bearsamppCore->unzipFile($tmpFilePath, $destination, function ($currentPercentage) { - echo json_encode(['progress' => "$currentPercentage%"]); + // Determine the file extension and call the appropriate unzipping function + $fileExtension = pathinfo($tmpFilePath, PATHINFO_EXTENSION); + Util::logDebug('File extension: ' . $fileExtension); + + if ($fileExtension === '7z' || $fileExtension === 'zip') { + // Send phase indicator for extraction + echo json_encode(['phase' => 'extracting']); if (ob_get_length()) { ob_flush(); } flush(); - }); - if ($unzipResult === false) { - return ['error' => 'Failed to unzip file. File: ' . $tmpFilePath . ' could not be unzipped', 'Destination: ' . $destination]; + $unzipResult = $bearsamppCore->unzipFile($tmpFilePath, $destination, function ($currentPercentage) { + echo json_encode(['progress' => "$currentPercentage%"]); + if (ob_get_length()) { + ob_flush(); + } + flush(); + }); + + if ($unzipResult === false) { + return ['error' => 'Failed to unzip file. File: ' . $tmpFilePath . ' could not be unzipped', 'Destination: ' . $destination]; + } + } else { + Util::logError('Unsupported file extension: ' . $fileExtension); + return ['error' => 'Unsupported file extension']; } - } else { - Util::logError('Unsupported file extension: ' . $fileExtension); - return ['error' => 'Unsupported file extension']; - } - return ['success' => 'Module installed successfully']; -} + return ['success' => 'Module installed successfully']; + } /** * Get the destination path for a given module type and name. @@ -478,24 +472,21 @@ public function fetchAndUnzipModule(string $moduleUrl, string $module): array * (application, binary, or tools) and the module name. It utilizes the * `bearsamppRoot` global object to retrieve the base paths for each module type. * - * @param string $moduleType The type of the module ('application', 'binary', or 'tools'). - * @param string $moduleName The name of the module. + * @param string $moduleType The type of the module ('application', 'binary', or 'tools'). + * @param string $moduleName The name of the module. * * @return string The constructed destination path for the module. */ - public function getModuleDestinationPath(string $moduleType, string $moduleName) + public function getModuleDestinationPath(string $moduleType, string $moduleName): string { global $bearsamppRoot; - if ( $moduleType === 'application' ) { - $destination = $bearsamppRoot->getAppsPath() . '/' . strtolower( $moduleName ) . '/'; - } - elseif ( $moduleType === 'binary' ) { - $destination = $bearsamppRoot->getBinPath() . '/' . strtolower( $moduleName ) . '/'; - } - elseif ( $moduleType === 'tools' ) { - $destination = $bearsamppRoot->getToolsPath() . '/' . strtolower( $moduleName ) . '/'; - } - else { + if ($moduleType === 'application') { + $destination = $bearsamppRoot->getAppsPath() . '/' . strtolower($moduleName) . '/'; + } elseif ($moduleType === 'binary') { + $destination = $bearsamppRoot->getBinPath() . '/' . strtolower($moduleName) . '/'; + } elseif ($moduleType === 'tools') { + $destination = $bearsamppRoot->getToolsPath() . '/' . strtolower($moduleName) . '/'; + } else { $destination = ''; } @@ -510,50 +501,50 @@ public function getModuleDestinationPath(string $moduleType, string $moduleName) * before displaying the modules. If the license key is invalid, it displays a subscription prompt. * If there is no internet connection, it displays a message indicating the lack of internet. * - * @param array $modules An array of available modules. - * @param array $versions An associative array where the key is the module name and the value is an array containing the module versions. - * @param string $imagesPath The path to the images directory. + * @param array $modules An array of available modules. + * @param array $versions An associative array where the key is the module name and the value is an array containing the module versions. + * @param string $imagesPath The path to the images directory. * * @return string The HTML content of the QuickPick menu. */ public function getQuickpickMenu(array $modules, array $versions, string $imagesPath): string { ob_start(); - if ( Util::checkInternetState() ) { + if (Util::checkInternetState()) { // Check if the license key is valid - if ( $this->checkDownloadId() ): ?> -
-
- -
- -
    +
      - -
    • - + foreach ($modules as $module): ?> + +
    • +
    • -
    • - + foreach ($versions['module-' . strtolower($module)] as $version_array): ?> +
    • + + for="-version-">
    • @@ -561,29 +552,28 @@ public function getQuickpickMenu(array $modules, array $versions, string $images
-