website/src/Repository/Page.php

44 lines
1.9 KiB
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)
{
$parsedown = new \Parsedown();
if(file_exists($kernel->getCacheDir() . '/pages/_header.md')) {
$return['header'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_header.md'));
} elseif(file_exists($kernel->getCacheDir() . '/pages/_header.html')) {
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_header.html');
} else {
throw new NotFoundHttpException('Some required files were not found');
}
if(file_exists($kernel->getCacheDir() . '/pages/_nav.md')) {
$return['nav'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/_nav.md'));
} elseif(file_exists($kernel->getCacheDir() . '/pages/_nav.html')) {
$return['nav'] = file_get_contents($kernel->getCacheDir() . '/pages/_nav.html');
} else {
throw new NotFoundHttpException('Some required files were not found');
}
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) {
$return['content'] = $parsedown->text(file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md'));
} elseif(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.html')) {
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.html');
} else {
throw new NotFoundHttpException('Some required files were not found');
}
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
$return['title'] = $titles[$page] ?? '';
$return['status'] = '200';
return $return;
}
}