@@ -1,8 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace LunixREST\Configuration; |
3 | 3 | |
4 | -interface Configuration |
|
5 | -{ |
|
4 | +interface Configuration { |
|
6 | 5 | public function get($key); |
7 | 6 | |
8 | 7 | public function set($key); |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | try { |
53 | 53 | $response = $this->server->handleRequest($request); |
54 | - header("Content-Type: " . $response->getMIMEType()); |
|
54 | + header("Content-Type: ".$response->getMIMEType()); |
|
55 | 55 | //TODO: Find a way for the Response to specify additional headers (to enable auth, as well as pagination) |
56 | 56 | echo $response->getAsString(); |
57 | 57 | } catch (InvalidAPIKeyException $e) { |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | use LunixREST\Response\Exceptions\NotAcceptableResponseTypeException; |
13 | 13 | use LunixREST\Server\Exceptions\MethodNotFoundException; |
14 | 14 | |
15 | -class HTTPServer |
|
16 | -{ |
|
15 | +class HTTPServer { |
|
17 | 16 | /** |
18 | 17 | * @var Server |
19 | 18 | */ |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | */ |
31 | 30 | //TODO: Add RequestLogger that we can pass through to log requests |
32 | 31 | //TODO: Add ErrorLogger to log errors (500s) |
33 | - public function __construct(Server $server, RequestFactory $requestFactory) |
|
34 | - { |
|
32 | + public function __construct(Server $server, RequestFactory $requestFactory) { |
|
35 | 33 | $this->server = $server; |
36 | 34 | $this->requestFactory = $requestFactory; |
37 | 35 | } |
@@ -44,8 +42,7 @@ discard block |
||
44 | 42 | * @param $requestURI - gotten from $_SERVER['REQUEST_URI'] for example |
45 | 43 | * Prints out the server response data, and sets any needed HTTP headers based on exceptions |
46 | 44 | */ |
47 | - public function handleSAPIRequest($requestMethod, $headers, $data, $remoteAddress, $requestURI) |
|
48 | - { |
|
45 | + public function handleSAPIRequest($requestMethod, $headers, $data, $remoteAddress, $requestURI) { |
|
49 | 46 | try { |
50 | 47 | $request = $this->requestFactory->create($requestMethod, $headers(), $data, $remoteAddress, $requestURI); |
51 | 48 |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace LunixREST\Server\Exceptions; |
3 | 3 | |
4 | -class MethodNotFoundException extends \Exception |
|
5 | -{ |
|
4 | +class MethodNotFoundException extends \Exception { |
|
6 | 5 | |
7 | 6 | } |
@@ -15,8 +15,7 @@ discard block |
||
15 | 15 | use LunixREST\Throttle\Throttle; |
16 | 16 | |
17 | 17 | //TODO: Unit test |
18 | -class Server |
|
19 | -{ |
|
18 | +class Server { |
|
20 | 19 | /** |
21 | 20 | * @var AccessControl |
22 | 21 | */ |
@@ -86,8 +85,7 @@ discard block |
||
86 | 85 | * @param Request $request |
87 | 86 | * @throws InvalidAPIKeyException |
88 | 87 | */ |
89 | - protected function validateKey(Request $request) |
|
90 | - { |
|
88 | + protected function validateKey(Request $request) { |
|
91 | 89 | if (!$this->accessControl->validateKey($request->getApiKey())) { |
92 | 90 | throw new InvalidAPIKeyException('Invalid API key'); |
93 | 91 | } |
@@ -98,8 +96,7 @@ discard block |
||
98 | 96 | * @throws NotAcceptableResponseTypeException |
99 | 97 | */ |
100 | 98 | //TODO: Handle wildcards in request MIME types (*/*) |
101 | - protected function validateAcceptableMIMETypes(Request $request) |
|
102 | - { |
|
99 | + protected function validateAcceptableMIMETypes(Request $request) { |
|
103 | 100 | $formats = $this->responseFactory->getSupportedMIMETypes(); |
104 | 101 | if (empty($formats) || ( |
105 | 102 | !empty($request->getAcceptableMIMETypes()) && empty(array_intersect($request->getAcceptableMIMETypes(), |
@@ -48,7 +48,7 @@ |
||
48 | 48 | protected function executeEndpoint(Endpoint $endpoint, Request $request): ResponseData |
49 | 49 | { |
50 | 50 | if (!method_exists($endpoint, $request->getMethod())) { |
51 | - throw new MethodNotFoundException("The endpoint method " . $request->getMethod() . " was not found"); |
|
51 | + throw new MethodNotFoundException("The endpoint method ".$request->getMethod()." was not found"); |
|
52 | 52 | } |
53 | 53 | return call_user_func([$endpoint, $request->getMethod()], $request); |
54 | 54 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * Class Router |
13 | 13 | * @package LunixREST\Router |
14 | 14 | */ |
15 | -class Router |
|
16 | -{ |
|
15 | +class Router { |
|
17 | 16 | /** |
18 | 17 | * @var EndpointFactory |
19 | 18 | */ |
@@ -22,8 +21,7 @@ discard block |
||
22 | 21 | /** |
23 | 22 | * @param EndpointFactory $endpointFactory |
24 | 23 | */ |
25 | - public function __construct(EndpointFactory $endpointFactory) |
|
26 | - { |
|
24 | + public function __construct(EndpointFactory $endpointFactory) { |
|
27 | 25 | $this->endpointFactory = $endpointFactory; |
28 | 26 | } |
29 | 27 |
@@ -5,8 +5,7 @@ |
||
5 | 5 | * Class Response |
6 | 6 | * @package LunixREST\Response |
7 | 7 | */ |
8 | -interface Response |
|
9 | -{ |
|
8 | +interface Response { |
|
10 | 9 | /** |
11 | 10 | * @return ResponseData |
12 | 11 | */ |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace LunixREST\Response\Exceptions; |
3 | 3 | |
4 | -class NotAcceptableResponseTypeException extends \Exception |
|
5 | -{ |
|
4 | +class NotAcceptableResponseTypeException extends \Exception { |
|
6 | 5 | |
7 | 6 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | * Class Response |
6 | 6 | * @package LunixREST\Response |
7 | 7 | */ |
8 | -interface ResponseData |
|
9 | -{ |
|
8 | +interface ResponseData { |
|
10 | 9 | /** |
11 | 10 | * @return array |
12 | 11 | */ |
@@ -5,15 +5,13 @@ |
||
5 | 5 | * Class JSONResponse |
6 | 6 | * @package LunixREST\Response |
7 | 7 | */ |
8 | -class JSONResponse implements Response |
|
9 | -{ |
|
8 | +class JSONResponse implements Response { |
|
10 | 9 | /** |
11 | 10 | * @var ResponseData |
12 | 11 | */ |
13 | 12 | public $data; |
14 | 13 | |
15 | - public function __construct(ResponseData $data) |
|
16 | - { |
|
14 | + public function __construct(ResponseData $data) { |
|
17 | 15 | $this->data = $data; |
18 | 16 | } |
19 | 17 |