| @@ -1,18 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Controller.php | |
| 4 | - * | |
| 5 | - * The Controller class file. | |
| 6 | - * | |
| 7 | - * PHP versions 5 | |
| 8 | - * | |
| 9 | - * @author Alexander Schneider <alexanderschneider85@gmail.com> | |
| 10 | - * @copyright 2008-2017 Alexander Schneider | |
| 11 | - * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 | |
| 12 | - * @version SVN: $id$ | |
| 13 | - * @link http://wordpress.org/extend/plugins/user-access-manager/ | |
| 14 | - */ | |
| 15 | 2 | |
| 16 | 3 | declare(strict_types=1); |
| 17 | 4 | |
| 18 | 5 | namespace UserAccessManager\Controller; |
| @@ -17,17 +4,11 @@ | ||
| 17 | 4 | |
| 18 | 5 | namespace UserAccessManager\Controller; |
| 19 | 6 | |
| 20 | 7 | use UserAccessManager\Config\WordpressConfig; |
| 21 | -use UserAccessManager\Controller\Backend\BackendController; | |
| 22 | 8 | use UserAccessManager\Wrapper\Php; |
| 23 | 9 | use UserAccessManager\Wrapper\Wordpress; |
| 24 | 10 | |
| 25 | -/** | |
| 26 | - * Class Controller | |
| 27 | - * | |
| 28 | - * @package UserAccessManager\Controller | |
| 29 | - */ | |
| 30 | 11 | abstract class Controller |
| 31 | 12 | { |
| 32 | 13 | use BaseControllerTrait { |
| 33 | 14 | render as traitRender; |
| @@ -34,8 +15,9 @@ | ||
| 34 | 15 | } |
| 35 | 16 | |
| 36 | 17 | public const ACTION_PARAMETER = 'uam_action'; |
| 37 | 18 | public const ACTION_SUFFIX = 'Action'; |
| 19 | + public const UAM_ERRORS = 'UAM_ERRORS'; | |
| 38 | 20 | |
| 39 | 21 | protected ?string $updateMessage = null; |
| 40 | 22 | |
| 41 | 23 | public function __construct( |
| @@ -80,13 +62,13 @@ | ||
| 80 | 62 | } |
| 81 | 63 | |
| 82 | 64 | protected function addErrorMessage(string $message): void |
| 83 | 65 | { |
| 84 | - if (isset($_SESSION[BackendController::UAM_ERRORS]) === false) { | |
| 85 | - $_SESSION[BackendController::UAM_ERRORS] = []; | |
| 66 | + if (isset($_SESSION[self::UAM_ERRORS]) === false) { | |
| 67 | + $_SESSION[self::UAM_ERRORS] = []; | |
| 86 | 68 | } |
| 87 | 69 | |
| 88 | - $_SESSION[BackendController::UAM_ERRORS][] = $message; | |
| 70 | + $_SESSION[self::UAM_ERRORS][] = $message; | |
| 89 | 71 | } |
| 90 | 72 | |
| 91 | 73 | public function getUpdateMessage(): ?string |
| 92 | 74 | { |
| @@ -97,15 +79,18 @@ | ||
| 97 | 79 | { |
| 98 | 80 | return $this->updateMessage !== null; |
| 99 | 81 | } |
| 100 | 82 | |
| 83 | + private function toCamelCase(string $snakeCaseName): string | |
| 84 | + { | |
| 85 | + $words = explode('_', $snakeCaseName); | |
| 86 | + return array_shift($words).implode('', array_map('ucfirst', $words)); | |
| 87 | + } | |
| 88 | + | |
| 101 | 89 | protected function processAction(): void |
| 102 | 90 | { |
| 103 | - $postAction = (string) $this->getRequestParameter(self::ACTION_PARAMETER); | |
| 104 | - $postActionSplit = explode('_', $postAction); | |
| 105 | - $postAction = array_shift($postActionSplit); | |
| 106 | - $postAction .= implode('', array_map('ucfirst', $postActionSplit)); | |
| 107 | - $actionMethod = $postAction.self::ACTION_SUFFIX; | |
| 91 | + $requestedAction = (string) $this->getRequestParameter(self::ACTION_PARAMETER); | |
| 92 | + $actionMethod = $this->toCamelCase($requestedAction).self::ACTION_SUFFIX; | |
| 108 | 93 | |
| 109 | 94 | if (method_exists($this, $actionMethod) === true) { |
| 110 | 95 | $this->{$actionMethod}(); |
| 111 | 96 | } |