PluginProbe
User Access Manager / 2.2.21
User Access Manager v2.2.21
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 +79 -13 2.3.152.2.21 View file →
@@ -32,41 +32,85 @@
32 32 use BaseControllerTrait {
33 33 render as traitRender;
34 34 }
35 35
36 - public const ACTION_PARAMETER = 'uam_action';
37 - public const ACTION_SUFFIX = 'Action';
36 + const ACTION_PARAMETER = 'uam_action';
37 + const ACTION_SUFFIX = 'Action';
38 38
39 - protected ?string $updateMessage = null;
39 + /**
40 + * @var Php
41 + */
42 + protected $php;
40 43
41 - public function __construct(
42 - protected Php $php,
43 - protected Wordpress $wordpress,
44 - protected WordpressConfig $wordpressConfig
45 - ) {
44 + /**
45 + * @var WordpressConfig
46 + */
47 + protected $wordpressConfig;
48 +
49 + /**
50 + * @var Wordpress
51 + */
52 + protected $wordpress;
53 +
54 + /**
55 + * @var string
56 + */
57 + protected $updateMessage = null;
58 +
59 + /**
60 + * Controller constructor.
61 + * @param Php $php
62 + * @param Wordpress $wordpress
63 + * @param WordpressConfig $wordpressConfig
64 + */
65 + public function __construct(Php $php, Wordpress $wordpress, WordpressConfig $wordpressConfig)
66 + {
67 + $this->php = $php;
68 + $this->wordpress = $wordpress;
69 + $this->wordpressConfig = $wordpressConfig;
46 70 }
47 71
72 + /**
73 + * @return Php
74 + */
48 75 protected function getPhp(): Php
49 76 {
50 77 return $this->php;
51 78 }
52 79
80 + /**
81 + * @return WordpressConfig
82 + */
53 83 protected function getWordpressConfig(): WordpressConfig
54 84 {
55 85 return $this->wordpressConfig;
56 86 }
57 87
88 + /**
89 + * Returns the nonce field.
90 + * @param string $name
91 + * @return string
92 + */
58 93 public function createNonceField(string $name): string
59 94 {
60 95 return $this->wordpress->getNonceField($name, $name.'Nonce');
61 96 }
62 97
98 + /**
99 + * Returns the nonce.
100 + * @param string $name
101 + * @return string
102 + */
63 103 public function getNonce(string $name): string
64 104 {
65 105 return $this->wordpress->createNonce($name);
66 106 }
67 107
68 - protected function verifyNonce(string $name): void
108 + /**
109 + * Verifies the nonce and terminates the application if the nonce is wrong.
110 + * @param string $name
111 + */
112 + protected function verifyNonce(string $name)
69 113 {
70 114 $nonce = $this->getRequestParameter($name.'Nonce');
71 115
72 116 if ($this->wordpress->verifyNonce($nonce, $name) === false) {
@@ -73,14 +117,22 @@
73 117 $this->wordpress->wpDie(TXT_UAM_NONCE_FAILURE_MESSAGE, TXT_UAM_NONCE_FAILURE_TITLE, ['response' => 401]);
74 118 }
75 119 }
76 120
77 - protected function setUpdateMessage(string $message): void
121 + /**
122 + * Sets the update message.
123 + * @param string $message
124 + */
125 + protected function setUpdateMessage(string $message)
78 126 {
79 127 $this->updateMessage = $message;
80 128 }
81 129
82 - protected function addErrorMessage(string $message): void
130 + /**
131 + * Adds an error message.
132 + * @param string $message
133 + */
134 + protected function addErrorMessage(string $message)
83 135 {
84 136 if (isset($_SESSION[BackendController::UAM_ERRORS]) === false) {
85 137 $_SESSION[BackendController::UAM_ERRORS] = [];
86 138 }
@@ -87,19 +139,30 @@
87 139
88 140 $_SESSION[BackendController::UAM_ERRORS][] = $message;
89 141 }
90 142
143 + /**
144 + * Returns the update message.
145 + * @return string
146 + */
91 147 public function getUpdateMessage(): ?string
92 148 {
93 149 return $this->updateMessage;
94 150 }
95 151
152 + /**
153 + * Returns true if a update message is set.
154 + * @return bool
155 + */
96 156 public function hasUpdateMessage(): bool
97 157 {
98 158 return $this->updateMessage !== null;
99 159 }
100 160
101 - protected function processAction(): void
161 + /**
162 + * Process the action.
163 + */
164 + protected function processAction()
102 165 {
103 166 $postAction = (string) $this->getRequestParameter(self::ACTION_PARAMETER);
104 167 $postActionSplit = explode('_', $postAction);
105 168 $postAction = array_shift($postActionSplit);
@@ -110,9 +173,12 @@
110 173 $this->{$actionMethod}();
111 174 }
112 175 }
113 176
114 - public function render(): void
177 + /**
178 + * Renders the given template
179 + */
180 + public function render()
115 181 {
116 182 $this->processAction();
117 183 $this->traitRender();
118 184 }