refactor: extract frontpage to template (#3130)

Also introduce usage of Response object
This commit is contained in:
Dag 2022-11-07 18:22:54 +01:00 committed by GitHub
parent fe59cbabc9
commit 2ef98b299f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 147 additions and 225 deletions

View file

@ -60,6 +60,7 @@ final class RssBridge
}
});
// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
$authenticationMiddleware = new AuthenticationMiddleware();
@ -73,9 +74,22 @@ final class RssBridge
}
}
$actionFactory = new ActionFactory();
$action = $request['action'] ?? 'Frontpage';
$action = $actionFactory->create($action);
$action->execute($request);
$actionName = $request['action'] ?? 'Frontpage';
$actionName = strtolower($actionName) . 'Action';
$actionName = implode(array_map('ucfirst', explode('-', $actionName)));
$filePath = __DIR__ . '/../actions/' . $actionName . '.php';
if (!file_exists($filePath)) {
throw new \Exception(sprintf('Invalid action: %s', $actionName));
}
$className = '\\' . $actionName;
$action = new $className();
$response = $action->execute($request);
if (is_string($response)) {
print $response;
} elseif ($response instanceof Response) {
$response->send();
}
}
}