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

56 lines
1.9 KiB
PHP
Raw Normal View History

2020-12-23 01:44:45 +00:00
<?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);
$encoded = FWIF::encode($packages);
2020-12-26 04:12:26 +00:00
echo 'FWIF ' . strlen($encoded) . ' bytes ' . $encoded;
2020-12-23 01:44:45 +00:00
echo "\r\n\r\n--------------------\r\n\r\n";
2020-12-24 03:25:10 +00:00
$jsonEncoded = json_encode($packages, JSON_INVALID_UTF8_SUBSTITUTE);
2020-12-26 04:12:26 +00:00
echo 'JSON ' . strlen($jsonEncoded) . ' bytes ' . $jsonEncoded;
2020-12-23 01:44:45 +00:00
echo "\r\n\r\n--------------------\r\n\r\n";
$hexdump = bin2hex($encoded); $hexdumpSect = 8; $hexdumpSize = 32;
for($i = 0; $i < strlen($hexdump) / $hexdumpSize; ++$i) {
$line = substr($hexdump, $i * $hexdumpSize, $hexdumpSize);
echo str_pad(dechex($i * $hexdumpSize), 4, '0', STR_PAD_LEFT) . ' ';
for($j = 0; $j < strlen($line) / $hexdumpSect; ++$j)
echo substr($line, $j * $hexdumpSect, $hexdumpSect) . ' ';
echo "\r\n";
}
echo "\r\n--------------------\r\n\r\n";
var_dump([(object)$packages[0]->fwifSerialize()]);
echo "\r\n--------------------\r\n\r\n";
$decoded = FWIF::decode($encoded);
var_dump($decoded);
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;
}
http_response_code(404);
echo '{"code":404,"message":"Path not found."}';