This repository has been archived on 2023-10-21. You can view files and clone it, but cannot push or open issues or pull requests.
patchouli/public/index.php

44 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Patchouli;
use FWIF\FWIF;
require_once __DIR__ . '/../startup.php';
$request = Http\HttpRequest::create();
header('Content-Type: ' . (PAT_DEBUG ? 'text/plain; charset=us-ascii' : FWIF::CONTENT_TYPE));
$tPlat = Platform::getUser();
// ONLY EXACT MATCHES ↓
if($request->match('GET', '/packages')) {
$tags = explode(';', (string)$request->getQueryParam('tags', FILTER_SANITIZE_STRING));
$packages = empty($tags) ? Patchouli::getPackages() : Patchouli::getPackagesWithTags($tags);
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\',\' Pゴシック\',sans-serif;font-size:16px;line-height:18px;">';
readfile(PAT_ROOT . '/patchouli.txt');
echo '</pre>';
return;
}
// REGEX MATCHES ↓
if($request->match('GET', '#^/packages/([a-z0-9-]+)/?$#', $args)) {
try {
$packageInfo = Patchouli::getPackage($args[0]);
} catch(PackageNotFoundException $ex) {
http_response_code(404);
$packageInfo = new ErrorResponse(404, 'Package not found.');
}
echo FWIF::encode($packageInfo);
return;
}
echo FWIF::encode(new ErrorResponse(404, 'Path not found.'));