<?php
namespace Patchouli;
use FWIF\FWIF;
require_once __DIR__ . '/../startup.php';
$request = Http\HttpRequest::create();
header('Content-Type: ' . FWIF::CONTENT_TYPE);
if($request->match('GET', '/packages')) {
$tags = explode(';', (string)$request->getQueryParam('tags', FILTER_SANITIZE_STRING));
$packages = empty($tags) ? Patchouli::getPackages() : Patchouli::getPackagesWithTags($tags);
header('Content-Type: text/plain; charset=us-ascii');
echo FWIF::encode($packages);
return;
}
if($request->match('GET', '/')) {
header('Content-Type: text/html; charset=utf-8');
echo '<!doctype html><title>Patchouli</title><pre style="font-family:IPAMonaPGothic,\'IPA モナー Pゴシック\',Monapo,Mona,\'MS PGothic\',\'MS Pゴシック\',sans-serif;font-size:16px;line-height:18px;">';
readfile(PAT_ROOT . '/patchouli.txt');
echo '</pre>';
http_response_code(404);
echo '{"code":404,"message":"Path not found."}';