PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Controller/Controller.php +122 -34 2.3.18 → 2.1.11 View file →
@@ -1,14 +1,30 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * Controller.php
4 + *
5 + * The Controller class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\Controller;
6 16
7 17 use UserAccessManager\Config\WordpressConfig;
18 +use UserAccessManager\Controller\Backend\BackendController;
8 19 use UserAccessManager\Wrapper\Php;
9 20 use UserAccessManager\Wrapper\Wordpress;
10 21
22 +/**
23 + * Class Controller
24 + *
25 + * @package UserAccessManager\Controller
26 + */
11 27 abstract class Controller
12 28 {
13 29 use BaseControllerTrait {
14 30 render as traitRender;
@@ -13,42 +29,91 @@
13 29 use BaseControllerTrait {
14 30 render as traitRender;
15 31 }
16 32
17 - public const ACTION_PARAMETER = 'uam_action';
18 - public const ACTION_SUFFIX = 'Action';
19 - public const UAM_ERRORS = 'UAM_ERRORS';
33 + const ACTION_PARAMETER = 'uam_action';
34 + const ACTION_SUFFIX = 'Action';
20 35
21 - protected ?string $updateMessage = null;
36 + /**
37 + * @var Php
38 + */
39 + protected $php;
22 40
23 - public function __construct(
24 - protected Php $php,
25 - protected Wordpress $wordpress,
26 - protected WordpressConfig $wordpressConfig
27 - ) {
41 + /**
42 + * @var WordpressConfig
43 + */
44 + protected $wordpressConfig;
45 +
46 + /**
47 + * @var Wordpress
48 + */
49 + protected $wordpress;
50 +
51 + /**
52 + * @var string
53 + */
54 + protected $updateMessage = null;
55 +
56 + /**
57 + * Controller constructor.
58 + *
59 + * @param Php $php
60 + * @param Wordpress $wordpress
61 + * @param WordpressConfig $wordpressConfig
62 + */
63 + public function __construct(Php $php, Wordpress $wordpress, WordpressConfig $wordpressConfig)
64 + {
65 + $this->php = $php;
66 + $this->wordpress = $wordpress;
67 + $this->wordpressConfig = $wordpressConfig;
28 68 }
29 69
30 - protected function getPhp(): Php
70 + /**
71 + * @return Php
72 + */
73 + protected function getPhp()
31 74 {
32 75 return $this->php;
33 76 }
34 77
35 - protected function getWordpressConfig(): WordpressConfig
78 + /**
79 + * @return WordpressConfig
80 + */
81 + protected function getWordpressConfig()
36 82 {
37 83 return $this->wordpressConfig;
38 84 }
39 85
40 - public function createNonceField(string $name): string
86 + /**
87 + * Returns the nonce field.
88 + *
89 + * @param string $name
90 + *
91 + * @return string
92 + */
93 + public function createNonceField($name)
41 94 {
42 95 return $this->wordpress->getNonceField($name, $name.'Nonce');
43 96 }
44 97
45 - public function getNonce(string $name): string
98 + /**
99 + * Returns the nonce.
100 + *
101 + * @param string $name
102 + *
103 + * @return string
104 + */
105 + public function getNonce($name)
46 106 {
47 107 return $this->wordpress->createNonce($name);
48 108 }
49 109
50 - protected function verifyNonce(string $name): void
110 + /**
111 + * Verifies the nonce and terminates the application if the nonce is wrong.
112 + *
113 + * @param string $name
114 + */
115 + protected function verifyNonce($name)
51 116 {
52 117 $nonce = $this->getRequestParameter($name.'Nonce');
53 118
54 119 if ($this->wordpress->verifyNonce($nonce, $name) === false) {
@@ -55,49 +120,72 @@
55 120 $this->wordpress->wpDie(TXT_UAM_NONCE_FAILURE_MESSAGE, TXT_UAM_NONCE_FAILURE_TITLE, ['response' => 401]);
56 121 }
57 122 }
58 123
59 - protected function setUpdateMessage(string $message): void
124 + /**
125 + * Sets the update message.
126 + *
127 + * @param string $message
128 + */
129 + protected function setUpdateMessage($message)
60 130 {
61 131 $this->updateMessage = $message;
62 132 }
63 133
64 - protected function addErrorMessage(string $message): void
134 + /**
135 + * Adds an error message.
136 + *
137 + * @param string $message
138 + */
139 + protected function addErrorMessage($message)
65 140 {
66 - if (isset($_SESSION[self::UAM_ERRORS]) === false) {
67 - $_SESSION[self::UAM_ERRORS] = [];
141 + if (isset($_SESSION[BackendController::UAM_ERRORS]) === false) {
142 + $_SESSION[BackendController::UAM_ERRORS] = [];
68 143 }
69 144
70 - $_SESSION[self::UAM_ERRORS][] = $message;
145 + $_SESSION[BackendController::UAM_ERRORS][] = $message;
71 146 }
72 147
73 - public function getUpdateMessage(): ?string
148 + /**
149 + * Returns the update message.
150 + *
151 + * @return string
152 + */
153 + public function getUpdateMessage()
74 154 {
75 155 return $this->updateMessage;
76 156 }
77 157
78 - public function hasUpdateMessage(): bool
158 + /**
159 + * Returns true if a update message is set.
160 + *
161 + * @return bool
162 + */
163 + public function hasUpdateMessage()
79 164 {
80 165 return $this->updateMessage !== null;
81 166 }
82 167
83 - private function toCamelCase(string $snakeCaseName): string
168 + /**
169 + * Process the action.
170 + */
171 + protected function processAction()
84 172 {
85 - $words = explode('_', $snakeCaseName);
86 - return array_shift($words).implode('', array_map('ucfirst', $words));
87 - }
173 + $postAction = $this->getRequestParameter(self::ACTION_PARAMETER);
174 + $postActionSplit = explode('_', $postAction);
175 + $postAction = array_shift($postActionSplit);
176 + $postAction .= implode('', array_map('ucfirst', $postActionSplit));
177 + $actionMethod = $postAction.self::ACTION_SUFFIX;
88 178
89 - protected function processAction(): void
90 - {
91 - $requestedAction = (string) $this->getRequestParameter(self::ACTION_PARAMETER);
92 - $actionMethod = $this->toCamelCase($requestedAction).self::ACTION_SUFFIX;
93 -
94 179 if (method_exists($this, $actionMethod) === true) {
95 180 $this->{$actionMethod}();
96 181 }
97 182 }
98 183
99 - public function render(): void
184 + /**
185 + * Renders the given template
186 + */
187 + public function render()
100 188 {
101 189 $this->processAction();
102 190 $this->traitRender();
103 191 }