mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 09:02:41 +00:00
0972cff660
- URLs are now matched centrally against a whitelist - %-encoded URLs are still handled correctly - Dispatched methods now only handle one specific task - Filler methods (e.g. versionPOST) are no longer required - Unhandled URLs now return 501 Not Implemented rather than 404 Not Found; this removes some ambiguity in the semantics of 404
36 lines
No EOL
1 KiB
PHP
36 lines
No EOL
1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace JKingWeb\Arsse\REST;
|
|
|
|
abstract class AbstractHandler implements Handler {
|
|
abstract function __construct();
|
|
abstract function dispatch(Request $req): Response;
|
|
|
|
protected function mapFieldNames(array $data, array $map, bool $overwrite = false): array {
|
|
foreach($map as $from => $to) {
|
|
if(array_key_exists($from, $data)) {
|
|
if($overwrite || !array_key_exists($to, $data)) $data[$to] = $data[$from];
|
|
unset($data[$from]);
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function mapFieldTypes(array $data, array $map): array {
|
|
foreach($map as $key => $type) {
|
|
if(array_key_exists($key, $data)) settype($data[$key], $type);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function validateId($id): bool {
|
|
try {
|
|
$ch1 = strval(intval($id));
|
|
$ch2 = strval($id);
|
|
} catch(\Throwable $e) {
|
|
return false;
|
|
}
|
|
return ($ch1 === $ch2);
|
|
}
|
|
|
|
} |