website/src/Repository/Page.php

36 lines
987 B
PHP
Raw Normal View History

2021-08-05 13:51:44 +02:00
<?php
namespace JeroenED\Website\Repository;
use DateTime;
use GuzzleHttp\Client;
use JeroenED\Framework\Repository;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SSH2;
2021-08-06 12:30:00 +02:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2021-08-05 13:51:44 +02:00
class Page
{
private $root;
public function __construct()
{
global $kernel;
$this->root = $kernel->getCacheDir() . 'pages';
}
public function getPage(string $page)
{
$return['header'] = file_get_contents(strtolower($this->root . '/_main.md'));
2021-08-05 14:46:20 +02:00
$titles = json_decode(file_get_contents($this->root . '/titles.json'), true);
2021-08-05 13:51:44 +02:00
if(file_exists($this->root . '/' . $page . '.md')) {
2021-08-05 14:46:20 +02:00
$return['title'] = $titles[$page] ?? '';
2021-08-05 13:51:44 +02:00
$return['content'] = file_get_contents(strtolower($this->root . '/' . $page . '.md'));
$return['status'] = '200';
} else {
2021-08-06 12:30:00 +02:00
throw new NotFoundHttpException();
2021-08-05 13:51:44 +02:00
}
return $return;
}
}