for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Flatdown\Controllers;
use Flatdown\Application;
use Flatdown\Exceptions\FileNotFoundException;
use Middlewares\HttpErrorException;
use Psr\Http\Message\ServerRequestInterface;
class ContentController
{
public function __invoke(ServerRequestInterface $req, array $params, Application $app)
// do not allow dangerous path chars
$document = str_replace(['..', '*', '?', './'], '_', $params['document']);
$index_filename = $app->getConfig('content_path') . '/' . $document . '/index.md';
if (file_exists($index_filename)) {
$filename = $index_filename;
} else {
$filename = $app->getConfig('content_path') . '/' . $document . '.md';
}
try {
return $app->get('markdown.page', [$filename]);
} catch (FileNotFoundException $e) {
throw HttpErrorException::create(404);