mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-04 23:57:29 +02:00
refactor: extract index.php to RssBridge.php (#2961)
* refactor: extract entry point into class * refactor: js * refactor: extract frontpage action
This commit is contained in:
58
lib/RssBridge.php
Normal file
58
lib/RssBridge.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
final class RssBridge
|
||||
{
|
||||
public function main(array $argv = [])
|
||||
{
|
||||
if ($argv) {
|
||||
parse_str(implode('&', array_slice($argv, 1)), $cliArgs);
|
||||
$request = $cliArgs;
|
||||
} else {
|
||||
$request = $_GET;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->run($request);
|
||||
} catch (\Throwable $e) {
|
||||
error_log($e);
|
||||
$message = sprintf(
|
||||
'Uncaught Exception %s: %s at %s line %s',
|
||||
get_class($e),
|
||||
$e->getMessage(),
|
||||
trim_path_prefix($e->getFile()),
|
||||
$e->getLine()
|
||||
);
|
||||
http_response_code(500);
|
||||
print render('error.html.php', [
|
||||
'message' => $message,
|
||||
'stacktrace' => create_sane_stacktrace($e),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function run($request): void
|
||||
{
|
||||
Configuration::verifyInstallation();
|
||||
Configuration::loadConfiguration();
|
||||
|
||||
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
|
||||
|
||||
define('CUSTOM_CACHE_TIMEOUT', Configuration::getConfig('cache', 'custom_timeout'));
|
||||
|
||||
$authenticationMiddleware = new AuthenticationMiddleware();
|
||||
if (Configuration::getConfig('authentication', 'enable')) {
|
||||
$authenticationMiddleware();
|
||||
}
|
||||
|
||||
foreach ($request as $key => $value) {
|
||||
if (!is_string($value)) {
|
||||
throw new \Exception("Query parameter \"$key\" is not a string.");
|
||||
}
|
||||
}
|
||||
|
||||
$actionFactory = new ActionFactory();
|
||||
$action = $request['action'] ?? 'Frontpage';
|
||||
$action = $actionFactory->create($action);
|
||||
$action->execute($request);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user