Files
Jump/jumpapp/classes/Main.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2022-02-04 09:53:55 +00:00
<?php
2022-03-15 21:38:39 +00:00
/**
* TO DO:
* - use CSRF token in weatherdata and icon api
*
*/
2022-02-04 09:53:55 +00:00
namespace Jump;
2022-03-15 21:38:39 +00:00
use Nette\Routing\RouteList;
2022-02-04 09:53:55 +00:00
class Main {
private Cache $cache;
2022-03-15 21:38:39 +00:00
private Config $config;
2022-02-04 09:53:55 +00:00
public function __construct() {
$this->config = new Config();
$this->cache = new Cache($this->config);
2022-03-15 21:38:39 +00:00
$this->router = new RouteList;
2022-02-04 09:53:55 +00:00
2022-03-15 21:38:39 +00:00
// Set up the routes that Jump expects.
$this->router->addRoute('/tag/<param>', [
'class' => 'Jump\Pages\TagPage'
]);
2022-02-04 09:53:55 +00:00
}
2022-03-15 21:38:39 +00:00
function init() {
// Try to match the correct route based on the HTTP request.
$matchedroute = $this->router->match(
(new \Nette\Http\RequestFactory)->fromGlobals()
);
2022-02-04 09:53:55 +00:00
2022-03-15 21:38:39 +00:00
// If we do not have a matched route then just serve up the home page.
$pageclass = $matchedroute['class'] ?? 'Jump\Pages\HomePage';
$param = $matchedroute['param'] ?? null;
2022-02-04 09:53:55 +00:00
2022-03-15 21:38:39 +00:00
// Instantiate the correct class to build the requested page, get the
// content and return it.
$page = new $pageclass($this->config, $this->cache, $param ?? null);
return $page->get_output();
2022-02-04 09:53:55 +00:00
}
}