+ $this->profiler->set(microtime(true), 'ready');
+ $timestamp = microtime(true);
+
+ Core\Hook::callAll($this->args->getModuleName() . '_mod_init', $placeholder);
+
+ $this->profiler->set(microtime(true) - $timestamp, 'init');
+
+ switch ($this->args->getMethod()) {
+ case Router::DELETE:
+ $this->delete($request);
+ break;
+ case Router::PATCH:
+ $this->patch($request);
+ break;
+ case Router::POST:
+ Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $request);
+ $this->post($request);
+ break;
+ case Router::PUT:
+ $this->put($request);
+ break;
+ }
+
+ $timestamp = microtime(true);
+ // "rawContent" is especially meant for technical endpoints.
+ // This endpoint doesn't need any theme initialization or other comparable stuff.
+ $this->rawContent($request);
+
+ try {
+ $arr = ['content' => ''];
+ Hook::callAll(static::class . '_mod_content', $arr);
+ $this->response->addContent($arr['content']);
+ $this->response->addContent($this->content($request));
+ } catch (HTTPException $e) {
+ // In case of System::externalRedirects(), we don't want to prettyprint the exception
+ // just redirect to the new location
+ if (($e instanceof HTTPException\FoundException) ||
+ ($e instanceof HTTPException\MovedPermanentlyException) ||
+ ($e instanceof HTTPException\TemporaryRedirectException)) {
+ throw $e;
+ }
+
+ $this->response->setStatus($e->getCode(), $e->getMessage());
+ $this->response->addContent($httpException->content($e));
+ } finally {
+ $this->profiler->set(microtime(true) - $timestamp, 'content');
+ }
+
+ return $this->response->generate();
+ }
+
+ /**
+ * Checks request inputs and sets default parameters
+ *
+ * @param array $defaults Associative array of expected request keys and their default typed value. A null
+ * value will remove the request key from the resulting value array.
+ * @param array $input Custom REQUEST array, superglobal instead
+ *
+ * @return array Request data
+ */
+ protected function checkDefaults(array $defaults, array $input): array
+ {
+ $request = [];
+
+ foreach ($defaults as $parameter => $defaultvalue) {
+ $request[$parameter] = $this->getRequestValue($input, $parameter, $defaultvalue);
+ }
+
+ foreach ($input ?? [] as $parameter => $value) {
+ if ($parameter == 'pagename') {
+ continue;
+ }
+ if (!in_array($parameter, array_keys($defaults))) {
+ $this->logger->notice('Unhandled request field', ['parameter' => $parameter, 'value' => $value, 'command' => $this->args->getCommand()]);
+ }
+ }
+
+ $this->logger->debug('Got request parameters', ['request' => $request, 'command' => $this->args->getCommand()]);
+ return $request;