website/src/Repository/Page.php

25 lines
898 B
PHP

<?php
namespace App\Repository;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
class Page
{
public function getPage(KernelInterface $kernel, string $page)
{
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_main.md');
$return['nav'] = file_get_contents($kernel->getCacheDir() . '/pages/_nav.md');
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) {
$return['title'] = $titles[$page] ?? '';
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md');
$return['status'] = '200';
} else {
throw new NotFoundHttpException();
}
return $return;
}
}