2023-08-16 23:45:46 +00:00
|
|
|
<?php
|
|
|
|
namespace Mince;
|
|
|
|
|
|
|
|
use Index\Routing\IRouter;
|
|
|
|
|
|
|
|
class HomeRoutes {
|
|
|
|
public function __construct(
|
2023-08-17 00:23:55 +00:00
|
|
|
private Servers $servers,
|
2023-08-16 23:45:46 +00:00
|
|
|
private Templating $templating,
|
2023-08-22 23:47:37 +00:00
|
|
|
private object $userInfo,
|
|
|
|
private string $loginUrl
|
2023-08-16 23:45:46 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public function register(IRouter $router): void {
|
|
|
|
$router->get('/', [$this, 'getIndex']);
|
2023-08-22 23:47:37 +00:00
|
|
|
$router->get('/downloads', [$this, 'getDownloads']);
|
2023-08-23 20:59:04 +00:00
|
|
|
$router->get('/guide', [$this, 'getGuide']);
|
2023-08-22 23:47:37 +00:00
|
|
|
$router->get('/login', fn($response) => $response->redirect($this->userInfo->success ? '/' : $this->loginUrl));
|
2023-08-16 23:45:46 +00:00
|
|
|
$router->get('/index.php', function($response) {
|
|
|
|
$response->redirect('/', true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIndex($response, $request) {
|
|
|
|
return $this->templating->render('index', [
|
2023-08-17 00:23:55 +00:00
|
|
|
'servers' => $this->servers->getServers(deleted: false),
|
2023-08-16 23:45:46 +00:00
|
|
|
]);
|
|
|
|
}
|
2023-08-22 23:47:37 +00:00
|
|
|
|
|
|
|
public function getDownloads() {
|
|
|
|
return $this->templating->render('downloads');
|
|
|
|
}
|
2023-08-23 20:59:04 +00:00
|
|
|
|
|
|
|
public function getGuide() {
|
|
|
|
return $this->templating->render('guide');
|
|
|
|
}
|
2023-08-16 23:45:46 +00:00
|
|
|
}
|