1
0
Fork 0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2024-12-27 22:58:23 +03:00
rss-bridge/lib/RssBridge.php

42 lines
1.3 KiB
PHP
Raw Normal View History

<?php
final class RssBridge
{
2024-08-30 05:21:51 +03:00
private Container $container;
public function __construct(
Container $container
) {
2024-08-30 05:21:51 +03:00
$this->container = $container;
}
public function main(Request $request): Response
{
$action = $request->get('action', 'Frontpage');
$actionName = strtolower($action) . 'Action';
$actionName = implode(array_map('ucfirst', explode('-', $actionName)));
$filePath = __DIR__ . '/../actions/' . $actionName . '.php';
if (!file_exists($filePath)) {
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'Invalid action']), 400);
}
2024-08-30 05:21:51 +03:00
$handler = $this->container[$actionName];
$middlewares = [
new CacheMiddleware($this->container['cache']),
new ExceptionMiddleware($this->container['logger']),
new SecurityMiddleware(),
new MaintenanceMiddleware(),
new BasicAuthMiddleware(),
new TokenAuthenticationMiddleware(),
];
$action = function ($req) use ($handler) {
return $handler($req);
};
foreach (array_reverse($middlewares) as $middleware) {
$action = fn ($req) => $middleware($req, $action);
}
return $action($request->withAttribute('action', $actionName));
}
}