mince/src/HomeRoutes.php

38 lines
1.1 KiB
PHP

<?php
namespace Mince;
use Index\Routing\IRouter;
use Sasae\SasaeEnvironment;
class HomeRoutes {
public function __construct(
private SasaeEnvironment $templating,
private Servers $servers,
private object $userInfo,
private string $loginUrl
) {}
public function register(IRouter $router): void {
$router->get('/', [$this, 'getIndex']);
$router->get('/downloads', [$this, 'getDownloads']);
$router->get('/guide', [$this, 'getGuide']);
$router->get('/login', fn($response) => $response->redirect($this->userInfo->success ? '/' : $this->loginUrl));
$router->get('/index.php', function($response) {
$response->redirect('/', true);
});
}
public function getIndex($response, $request) {
return $this->templating->render('index', [
'servers' => $this->servers->getServers(deleted: false),
]);
}
public function getDownloads() {
return $this->templating->render('downloads');
}
public function getGuide() {
return $this->templating->render('guide');
}
}