mince/src/HomeRoutes.php

38 lines
1.1 KiB
PHP
Raw Normal View History

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']);
$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');
}
public function getGuide() {
return $this->templating->render('guide');
}
2023-08-16 23:45:46 +00:00
}