2022-08-18 23:52:01 +03:00
|
|
|
<?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();
|
|
|
|
|
2022-08-23 22:19:53 +03:00
|
|
|
$customConfig = [];
|
|
|
|
if (file_exists(__DIR__ . '/../config.ini.php')) {
|
|
|
|
$customConfig = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
|
|
|
|
}
|
|
|
|
Configuration::loadConfiguration($customConfig, getenv());
|
2022-08-18 23:52:01 +03:00
|
|
|
|
2022-08-23 22:19:53 +03:00
|
|
|
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
|
2022-08-18 23:52:01 +03:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|