@@ -14,8 +14,7 @@ discard block |
||
| 14 | 14 | use LunixREST\Server\Exceptions\MethodNotFoundException; |
| 15 | 15 | use LunixREST\Throttle\Throttle; |
| 16 | 16 | |
| 17 | -class GenericServer implements Server |
|
| 18 | -{ |
|
| 17 | +class GenericServer implements Server { |
|
| 19 | 18 | /** |
| 20 | 19 | * @var AccessControl |
| 21 | 20 | */ |
@@ -86,8 +85,7 @@ discard block |
||
| 86 | 85 | * @param APIRequest $request |
| 87 | 86 | * @throws InvalidAPIKeyException |
| 88 | 87 | */ |
| 89 | - protected function validateKey(APIRequest $request) |
|
| 90 | - { |
|
| 88 | + protected function validateKey(APIRequest $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(APIRequest $request) |
|
| 102 | - { |
|
| 99 | + protected function validateAcceptableMIMETypes(APIRequest $request) { |
|
| 103 | 100 | $formats = $this->responseFactory->getSupportedMIMETypes(); |
| 104 | 101 | if (empty($formats) || ( |
| 105 | 102 | !empty($request->getAcceptableMIMETypes()) && empty(array_intersect($request->getAcceptableMIMETypes(), |
@@ -10,8 +10,7 @@ |
||
| 10 | 10 | * Interface Router |
| 11 | 11 | * @package LunixREST\Server |
| 12 | 12 | */ |
| 13 | -interface Router |
|
| 14 | -{ |
|
| 13 | +interface Router { |
|
| 15 | 14 | /** |
| 16 | 15 | * @param APIRequest $request |
| 17 | 16 | * @return array|null|object |
@@ -47,13 +47,13 @@ |
||
| 47 | 47 | { |
| 48 | 48 | $method = $this->mapEndpointMethod($request); |
| 49 | 49 | if (!method_exists($endpoint, $method)) { |
| 50 | - throw new MethodNotFoundException("The endpoint method " . $method . " was not found"); |
|
| 50 | + throw new MethodNotFoundException("The endpoint method ".$method." was not found"); |
|
| 51 | 51 | } |
| 52 | 52 | return call_user_func([$endpoint, $method], $request); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | protected function mapEndpointMethod(APIRequest $request): string |
| 56 | 56 | { |
| 57 | - return strtolower($request->getMethod()) . ($request->getElement() ? 'All': ''); |
|
| 57 | + return strtolower($request->getMethod()).($request->getElement() ? 'All' : ''); |
|
| 58 | 58 | } |
| 59 | 59 | } |
@@ -10,8 +10,7 @@ discard block |
||
| 10 | 10 | * Class DefaultRouter |
| 11 | 11 | * @package LunixREST\Server |
| 12 | 12 | */ |
| 13 | -class GenericRouter |
|
| 14 | -{ |
|
| 13 | +class GenericRouter { |
|
| 15 | 14 | /** |
| 16 | 15 | * @var EndpointFactory |
| 17 | 16 | */ |
@@ -21,8 +20,7 @@ discard block |
||
| 21 | 20 | * DefaultRouter constructor. |
| 22 | 21 | * @param EndpointFactory $endpointFactory |
| 23 | 22 | */ |
| 24 | - public function __construct(EndpointFactory $endpointFactory) |
|
| 25 | - { |
|
| 23 | + public function __construct(EndpointFactory $endpointFactory) { |
|
| 26 | 24 | $this->endpointFactory = $endpointFactory; |
| 27 | 25 | } |
| 28 | 26 | |
@@ -31,8 +29,7 @@ discard block |
||
| 31 | 29 | * @return null|object|array |
| 32 | 30 | * @throws MethodNotFoundException |
| 33 | 31 | */ |
| 34 | - public function route(APIRequest $request) |
|
| 35 | - { |
|
| 32 | + public function route(APIRequest $request) { |
|
| 36 | 33 | $endpoint = $this->endpointFactory->getEndpoint($request->getEndpoint(), $request->getVersion()); |
| 37 | 34 | return $this->executeEndpoint($endpoint, $request); |
| 38 | 35 | } |
@@ -43,8 +40,7 @@ discard block |
||
| 43 | 40 | * @return null|object|array |
| 44 | 41 | * @throws MethodNotFoundException |
| 45 | 42 | */ |
| 46 | - protected function executeEndpoint(Endpoint $endpoint, APIRequest $request) |
|
| 47 | - { |
|
| 43 | + protected function executeEndpoint(Endpoint $endpoint, APIRequest $request) { |
|
| 48 | 44 | $method = $this->mapEndpointMethod($request); |
| 49 | 45 | if (!method_exists($endpoint, $method)) { |
| 50 | 46 | throw new MethodNotFoundException("The endpoint method " . $method . " was not found"); |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $body = $response->getBody(); |
| 93 | - while(!$body->eof()) { |
|
| 93 | + while (!$body->eof()) { |
|
| 94 | 94 | echo $body->read(1024); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -12,8 +12,7 @@ discard block |
||
| 12 | 12 | use Psr\Http\Message\ResponseInterface; |
| 13 | 13 | use Psr\Http\Message\ServerRequestInterface; |
| 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 | } |
@@ -15,8 +15,7 @@ |
||
| 15 | 15 | * Interface Server |
| 16 | 16 | * @package LunixREST\Server |
| 17 | 17 | */ |
| 18 | -interface Server |
|
| 19 | -{ |
|
| 18 | +interface Server { |
|
| 20 | 19 | /** |
| 21 | 20 | * @param APIRequest $request |
| 22 | 21 | * @return APIResponse |
@@ -7,8 +7,7 @@ |
||
| 7 | 7 | * Class APIResponse |
| 8 | 8 | * @package LunixREST\APIResponse |
| 9 | 9 | */ |
| 10 | -interface APIResponse |
|
| 11 | -{ |
|
| 10 | +interface APIResponse { |
|
| 12 | 11 | /** |
| 13 | 12 | * @return null|object|array |
| 14 | 13 | */ |
@@ -7,15 +7,13 @@ discard block |
||
| 7 | 7 | * Class JSONResponse |
| 8 | 8 | * @package LunixREST\APIResponse |
| 9 | 9 | */ |
| 10 | -class JSONResponse implements APIResponse |
|
| 11 | -{ |
|
| 10 | +class JSONResponse implements APIResponse { |
|
| 12 | 11 | /** |
| 13 | 12 | * @var null|object|array |
| 14 | 13 | */ |
| 15 | 14 | public $data; |
| 16 | 15 | |
| 17 | - public function __construct($data) |
|
| 18 | - { |
|
| 16 | + public function __construct($data) { |
|
| 19 | 17 | $this->data = $data; |
| 20 | 18 | } |
| 21 | 19 | |
@@ -35,8 +33,7 @@ discard block |
||
| 35 | 33 | /** |
| 36 | 34 | * @return null|object|array |
| 37 | 35 | */ |
| 38 | - public function getResponseData() |
|
| 39 | - { |
|
| 36 | + public function getResponseData() { |
|
| 40 | 37 | return $this->data; |
| 41 | 38 | } |
| 42 | 39 | } |