Skip to content

Commit 91a229e

Browse files
committed
Class docs
1 parent c5328b5 commit 91a229e

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/VerifierServer/Endpoints/EndPointInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
use Psr\Http\Message\ServerRequestInterface;
66

7+
/**
8+
* Interface EndpointInterface
9+
*
10+
* Defines the contract for handling incoming HTTP requests and generating appropriate responses.
11+
*
12+
* @package VerifierServer\Endpoints
13+
*/
714
interface EndpointInterface
815
{
916

src/VerifierServer/Endpoints/VerifiedEndpoint.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@
66
use Psr\Http\Message\ServerRequestInterface;
77
use VerifierServer\PersistentState;
88

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+
*/
947
class VerifiedEndpoint implements EndpointInterface
1048
{
1149
public function __construct(private PersistentState &$state)

src/VerifierServer/PersistentState.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
use Dotenv\Dotenv;
66

7+
/**
8+
* Class PersistentState
9+
*
10+
* This class provides a persistent state management system for verification data. It supports two storage types:
11+
* - Filesystem: Stores the verification data in a JSON file.
12+
* - Database: Stores the verification data in a database table.
13+
*
14+
* The class includes methods for initializing the storage, retrieving and updating the verification list,
15+
* and managing environment configurations.
16+
*
17+
* @package VerifierServer
18+
*/
719
class PersistentState {
820
private \PDO $pdo;
921
private array $verifyList;

src/VerifierServer/Server.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
use VerifierServer\Endpoints\VerifiedEndpoint;
1515
use VerifierServer\Endpoints\EndpointInterface;
1616

17+
/**
18+
* Class Server
19+
*
20+
* This class represents a server implementation that can handle HTTP requests
21+
* using ReactPHP's HttpServer or a stream socket server. It provides methods
22+
* for initializing, starting, stopping, and handling client requests. The server
23+
* supports endpoints and logging functionality.
24+
*
25+
* @package VerifierServer
26+
*/
1727
class Server {
1828
private LoopInterface $loop;
1929
private $server;

0 commit comments

Comments
 (0)