|
6 | 6 | use Psr\Http\Message\ServerRequestInterface; |
7 | 7 | use VerifierServer\PersistentState; |
8 | 8 |
|
| 9 | +/** |
| 10 | + * Class VerifiedEndpoint |
| 11 | + * |
| 12 | + * This class is responsible for handling the verification process for the VerifierServer. |
| 13 | + * It implements the EndpointInterface and provides methods to handle HTTP GET, POST, and DELETE requests. |
| 14 | + * |
| 15 | + * Key Responsibilities: |
| 16 | + * - Handles GET requests to retrieve the list of verified users in JSON format. |
| 17 | + * - Handles POST requests to add a new verification entry or DELETE requests to remove an existing entry. |
| 18 | + * - Validates authorization tokens to ensure secure access to the endpoint. |
| 19 | + * - Manages the persistent state of the verification list by reading from and writing to a JSON file. |
| 20 | + * |
| 21 | + * Methods: |
| 22 | + * - __construct: Initializes the VerifiedEndpoint with a reference to the PersistentState object. |
| 23 | + * - handle: Routes incoming HTTP requests to the appropriate handler based on the HTTP method. |
| 24 | + * - get: Handles GET requests to retrieve the verification list. |
| 25 | + * - post: Handles POST and DELETE requests to modify the verification list. |
| 26 | + * - __post: Adds a new verification entry to the list if it does not already exist. |
| 27 | + * - delete: Removes an existing verification entry from the list. |
| 28 | + * |
| 29 | + * Authorization: |
| 30 | + * - The class checks the provided token against the expected token stored in the PersistentState. |
| 31 | + * - If the token is invalid, the response is set to 401 Unauthorized. |
| 32 | + * - If the token is valid, the requested action is performed. |
| 33 | + * |
| 34 | + * Error Handling: |
| 35 | + * - Returns 401 Unauthorized if the provided token does not match the expected token. |
| 36 | + * - Returns 403 Forbidden if a duplicate entry is detected during a POST request. |
| 37 | + * - Returns 404 Not Found if an entry to be deleted does not exist. |
| 38 | + * - Returns 405 Method Not Allowed for unsupported HTTP methods. |
| 39 | + * |
| 40 | + * Response Structure: |
| 41 | + * - Sets appropriate HTTP status codes. |
| 42 | + * - Sets the Content-Type header based on the response type (e.g., application/json, text/plain). |
| 43 | + * - Encodes the response body as JSON for successful requests or as plain text for error responses. |
| 44 | + * |
| 45 | + * @package VerifierServer\Endpoints |
| 46 | + */ |
9 | 47 | class VerifiedEndpoint implements EndpointInterface |
10 | 48 | { |
11 | 49 | public function __construct(private PersistentState &$state) |
|
0 commit comments