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 +96 -23 2.3.17 → 2.1.11 View file →
@@ -11,11 +11,8 @@
11 11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 12 * @version SVN: $id$
13 13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 14 */
15 -
16 -declare(strict_types=1);
17 -
18 15 namespace UserAccessManager\Controller;
19 16
20 17 use UserAccessManager\Config\WordpressConfig;
21 18 use UserAccessManager\Controller\Backend\BackendController;
@@ -32,41 +29,91 @@
32 29 use BaseControllerTrait {
33 30 render as traitRender;
34 31 }
35 32
36 - public const ACTION_PARAMETER = 'uam_action';
37 - public const ACTION_SUFFIX = 'Action';
33 + const ACTION_PARAMETER = 'uam_action';
34 + const ACTION_SUFFIX = 'Action';
38 35
39 - protected ?string $updateMessage = null;
36 + /**
37 + * @var Php
38 + */
39 + protected $php;
40 40
41 - public function __construct(
42 - protected Php $php,
43 - protected Wordpress $wordpress,
44 - protected WordpressConfig $wordpressConfig
45 - ) {
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;
46 68 }
47 69
48 - protected function getPhp(): Php
70 + /**
71 + * @return Php
72 + */
73 + protected function getPhp()
49 74 {
50 75 return $this->php;
51 76 }
52 77
53 - protected function getWordpressConfig(): WordpressConfig
78 + /**
79 + * @return WordpressConfig
80 + */
81 + protected function getWordpressConfig()
54 82 {
55 83 return $this->wordpressConfig;
56 84 }
57 85
58 - 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)
59 94 {
60 95 return $this->wordpress->getNonceField($name, $name.'Nonce');
61 96 }
62 97
63 - 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)
64 106 {
65 107 return $this->wordpress->createNonce($name);
66 108 }
67 109
68 - 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)
69 116 {
70 117 $nonce = $this->getRequestParameter($name.'Nonce');
71 118
72 119 if ($this->wordpress->verifyNonce($nonce, $name) === false) {
@@ -73,14 +120,24 @@
73 120 $this->wordpress->wpDie(TXT_UAM_NONCE_FAILURE_MESSAGE, TXT_UAM_NONCE_FAILURE_TITLE, ['response' => 401]);
74 121 }
75 122 }
76 123
77 - protected function setUpdateMessage(string $message): void
124 + /**
125 + * Sets the update message.
126 + *
127 + * @param string $message
128 + */
129 + protected function setUpdateMessage($message)
78 130 {
79 131 $this->updateMessage = $message;
80 132 }
81 133
82 - protected function addErrorMessage(string $message): void
134 + /**
135 + * Adds an error message.
136 + *
137 + * @param string $message
138 + */
139 + protected function addErrorMessage($message)
83 140 {
84 141 if (isset($_SESSION[BackendController::UAM_ERRORS]) === false) {
85 142 $_SESSION[BackendController::UAM_ERRORS] = [];
86 143 }
@@ -87,21 +144,34 @@
87 144
88 145 $_SESSION[BackendController::UAM_ERRORS][] = $message;
89 146 }
90 147
91 - public function getUpdateMessage(): ?string
148 + /**
149 + * Returns the update message.
150 + *
151 + * @return string
152 + */
153 + public function getUpdateMessage()
92 154 {
93 155 return $this->updateMessage;
94 156 }
95 157
96 - public function hasUpdateMessage(): bool
158 + /**
159 + * Returns true if a update message is set.
160 + *
161 + * @return bool
162 + */
163 + public function hasUpdateMessage()
97 164 {
98 165 return $this->updateMessage !== null;
99 166 }
100 167
101 - protected function processAction(): void
168 + /**
169 + * Process the action.
170 + */
171 + protected function processAction()
102 172 {
103 - $postAction = (string) $this->getRequestParameter(self::ACTION_PARAMETER);
173 + $postAction = $this->getRequestParameter(self::ACTION_PARAMETER);
104 174 $postActionSplit = explode('_', $postAction);
105 175 $postAction = array_shift($postActionSplit);
106 176 $postAction .= implode('', array_map('ucfirst', $postActionSplit));
107 177 $actionMethod = $postAction.self::ACTION_SUFFIX;
@@ -110,9 +180,12 @@
110 180 $this->{$actionMethod}();
111 181 }
112 182 }
113 183
114 - public function render(): void
184 + /**
185 + * Renders the given template
186 + */
187 + public function render()
115 188 {
116 189 $this->processAction();
117 190 $this->traitRender();
118 191 }