refactor: flatten src/AKSRT → src (drop theme-identifier dir)

Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
2026-08-02 22:06:06 +08:00
parent 56f1a8175f
commit 8c5b1555c9
285 changed files with 26 additions and 3600 deletions
+102
View File
@@ -0,0 +1,102 @@
<?php
/**
* Public identity verification REST API.
*
* @package AKSRT
*/
namespace AKSRT\Identity;
defined('ABSPATH') || exit;
final class RestController {
private const NS = 'aksrt/v1';
public function __construct(
private ?ApplicationRepository $applications = null,
private ?ApplicationService $service = null
) {
$this->applications ??= new ApplicationRepository();
$this->service ??= new ApplicationService($this->applications);
}
public function register_routes(): void {
register_rest_route(self::NS, '/identity/applications', [
'methods' => 'POST',
'callback' => [$this, 'create'],
'permission_callback' => [$this, 'logged_in'],
]);
register_rest_route(self::NS, '/identity/applications/current', [
'methods' => 'GET',
'callback' => [$this, 'current'],
'permission_callback' => [$this, 'logged_in'],
]);
register_rest_route(self::NS, '/identity/applications/(?P<uuid>[a-f0-9-]{36})', [
'methods' => 'GET',
'callback' => [$this, 'get'],
'permission_callback' => [$this, 'owns_application'],
]);
register_rest_route(self::NS, '/identity/applications/(?P<uuid>[a-f0-9-]{36})/refresh', [
'methods' => 'POST',
'callback' => [$this, 'refresh'],
'permission_callback' => [$this, 'owns_application'],
]);
register_rest_route(self::NS, '/identity/applications/(?P<uuid>[a-f0-9-]{36})/manual', [
'methods' => 'POST',
'callback' => [$this, 'manual'],
'permission_callback' => [$this, 'owns_application'],
]);
}
public function logged_in(): bool {
return is_user_logged_in();
}
public function owns_application(\WP_REST_Request $request): bool {
if (!is_user_logged_in()) {
return false;
}
$application = $this->applications->find_by_uuid((string) $request['uuid']);
return is_array($application) && (int) $application['user_id'] === get_current_user_id();
}
public function create(\WP_REST_Request $request): \WP_REST_Response {
$params = $request->get_json_params();
$params = is_array($params) ? $params : [];
$result = $this->service->create(get_current_user_id(), $params);
return $this->respond($result, 201);
}
public function current(): \WP_REST_Response {
$application = $this->applications->latest_for_user(get_current_user_id());
return new \WP_REST_Response(['success' => true, 'data' => $application ? $this->service->view($application) : null]);
}
public function get(\WP_REST_Request $request): \WP_REST_Response {
$application = $this->applications->find_by_uuid((string) $request['uuid']);
return new \WP_REST_Response(['success' => true, 'data' => $this->service->view($application)]);
}
public function refresh(\WP_REST_Request $request): \WP_REST_Response {
$application = $this->applications->find_by_uuid((string) $request['uuid']);
return $this->respond($this->service->refresh($application));
}
public function manual(\WP_REST_Request $request): \WP_REST_Response {
$application = $this->applications->find_by_uuid((string) $request['uuid']);
return $this->respond($this->service->move_to_manual($application, $_FILES['evidence'] ?? null));
}
private function respond($result, int $success_status = 200): \WP_REST_Response {
if (is_wp_error($result)) {
$status = in_array($result->get_error_code(), ['aksrt_identity_active', 'aksrt_identity_verified', 'aksrt_identity_conflict'], true) ? 409 : 422;
return new \WP_REST_Response([
'success' => false,
'code' => $result->get_error_code(),
'message' => $result->get_error_message(),
], $status);
}
return new \WP_REST_Response(['success' => true, 'data' => $result], $success_status);
}
}