Skip to content

Commit 112d08f

Browse files
committed
Endpoint class and remove type on $request param
Makes it easier to write phpunit tests and prototype traits without messing with the other endpoint classes
1 parent bb4ae83 commit 112d08f

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace VerifierServer\Endpoints;
4+
5+
use React\Http\Message\Response;
6+
use Psr\Http\Message\ServerRequestInterface;
7+
8+
class Endpoint implements EndpointInterface
9+
{
10+
//use RequestTrait, MessageTrait, ServerRequestTrait;
11+
use RequestParserTrait;
12+
13+
public function handle(
14+
string $method,
15+
$request,
16+
int|string &$response,
17+
array &$headers,
18+
string &$body
19+
): void
20+
{
21+
$response = Response::STATUS_OK; // HTTP status code
22+
$headers = ['Content-Type' => 'application/json']; // Response headers
23+
$body = json_encode(['message' => 'Hello, World!']); // Response body
24+
}
25+
}

src/VerifierServer/Endpoints/USPSEndpoint.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
* such as GET, HEAD, and POST, and generates XML requests to interact
1616
* with the USPS API.
1717
*/
18-
class USPSEndpoint implements EndpointInterface
18+
class USPSEndpoint extends Endpoint
1919
{
20-
use RequestParserTrait;
21-
2220
CONST BASE_URL = 'http://production.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=';
2321
CONST INFO = 'Information provided by www.usps.com';
2422

@@ -118,7 +116,7 @@ private function get(
118116
$params = $request instanceof ServerRequestInterface
119117
? $request->getQueryParams()
120118
: (is_string($request)
121-
? self::getQueryParams($request)
119+
? $this->getQueryParams($request)
122120
: []);
123121

124122
$requiredFields = ['address2', 'city', 'state'];

src/VerifierServer/Endpoints/VerifiedEndpoint.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
*
4545
* @package VerifierServer\Endpoints
4646
*/
47-
class VerifiedEndpoint implements EndpointInterface
47+
class VerifiedEndpoint extends Endpoint
4848
{
49-
use RequestParserTrait;
50-
5149
public function __construct(private PersistentState &$state)
5250
{}
5351

@@ -63,7 +61,7 @@ public function __construct(private PersistentState &$state)
6361
*/
6462
public function handle(
6563
string $method,
66-
ServerRequestInterface|string $request,
64+
$request,
6765
int|string &$response,
6866
array &$headers,
6967
string &$body,

0 commit comments

Comments
 (0)