move_detect/server/src/Http/Router.php
유창욱 3f2823a764 refactor: rename cloud/ to server/ (cafe24 is web hosting, not cloud)
The PHP app runs on Cafe24 shared web hosting -- calling it 'cloud'
was misleading. Renames the directory, the edge client module, and
every doc/script/identifier that used the term.

- cloud/ -> server/ (incl. server/deploy/build_cafe24_package.sh paths)
- edge/cloudclient.py -> edge/serverclient.py, CloudClient -> ServerClient
- cloud/docs/cloud-deploy.md -> server/docs/server-deploy.md
- CLOUD_* env/config keys -> SERVER_*
- tests renamed to match

Tests: PHP 109 pass (4 skipped), pytest 167 pass. dist/ regenerated.
2026-07-20 11:30:52 +09:00

28 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http;
final class Router
{
private array $routes = [];
public function add(string $method, string $path, callable $handler): void {
$regex = '#^' . preg_replace('#\{(\w+)\}#', '(?P<$1>[^/]+)', $path) . '$#';
$this->routes[] = [strtoupper($method), $regex, $handler];
}
public function dispatch(Request $req): Response {
foreach ($this->routes as [$method, $regex, $handler]) {
if ($req->method() !== $method) continue;
if (preg_match($regex, $req->path(), $m)) {
// Decode captured params: a camera_id/zone_id with a space or Korean text is
// %-encoded in the URL, so without this GET /api/zones/{camera} never matches
// what POST /api/zones stored.
$params = array_map('rawurldecode',
array_filter($m, 'is_string', ARRAY_FILTER_USE_KEY));
return $handler($req, $params);
}
}
return Response::json(['error' => 'not_found'], 404);
}
}