@@ -37,7 +37,7 @@ |
||
| 37 | 37 | * @param array $acceptableMIMETypes |
| 38 | 38 | * @param null|string $queryString |
| 39 | 39 | */ |
| 40 | - public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) |
|
| 40 | + public function __construct(string $endpoint, ? string $element, ? string $version, ? string $apiKey, array $acceptableMIMETypes, ? string $queryString) |
|
| 41 | 41 | { |
| 42 | 42 | $this->endpoint = $endpoint; |
| 43 | 43 | $this->element = $element; |
@@ -1,8 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace LunixREST\APIRequest\URLParser; |
| 3 | 3 | |
| 4 | -class ParsedURL |
|
| 5 | -{ |
|
| 4 | +class ParsedURL { |
|
| 6 | 5 | /** |
| 7 | 6 | * @var string |
| 8 | 7 | */ |
@@ -37,8 +36,7 @@ discard block |
||
| 37 | 36 | * @param array $acceptableMIMETypes |
| 38 | 37 | * @param null|string $queryString |
| 39 | 38 | */ |
| 40 | - public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) |
|
| 41 | - { |
|
| 39 | + public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) { |
|
| 42 | 40 | $this->endpoint = $endpoint; |
| 43 | 41 | $this->element = $element; |
| 44 | 42 | $this->version = $version; |
@@ -58,24 +56,21 @@ discard block |
||
| 58 | 56 | /** |
| 59 | 57 | * @return null|string |
| 60 | 58 | */ |
| 61 | - public function getElement() |
|
| 62 | - { |
|
| 59 | + public function getElement() { |
|
| 63 | 60 | return $this->element; |
| 64 | 61 | } |
| 65 | 62 | |
| 66 | 63 | /** |
| 67 | 64 | * @return null|string |
| 68 | 65 | */ |
| 69 | - public function getVersion() |
|
| 70 | - { |
|
| 66 | + public function getVersion() { |
|
| 71 | 67 | return $this->version; |
| 72 | 68 | } |
| 73 | 69 | |
| 74 | 70 | /** |
| 75 | 71 | * @return null|string |
| 76 | 72 | */ |
| 77 | - public function getApiKey() |
|
| 78 | - { |
|
| 73 | + public function getApiKey() { |
|
| 79 | 74 | return $this->apiKey; |
| 80 | 75 | } |
| 81 | 76 | |
@@ -90,8 +85,7 @@ discard block |
||
| 90 | 85 | /** |
| 91 | 86 | * @return null|string |
| 92 | 87 | */ |
| 93 | - public function getQueryString() |
|
| 94 | - { |
|
| 88 | + public function getQueryString() { |
|
| 95 | 89 | return $this->queryString; |
| 96 | 90 | } |
| 97 | 91 | } |
@@ -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 | } |
@@ -15,8 +15,7 @@ discard block |
||
| 15 | 15 | use Psr\Log\LoggerAwareTrait; |
| 16 | 16 | use Psr\Log\LoggerInterface; |
| 17 | 17 | |
| 18 | -class HTTPServer |
|
| 19 | -{ |
|
| 18 | +class HTTPServer { |
|
| 20 | 19 | use LoggerAwareTrait; |
| 21 | 20 | |
| 22 | 21 | /** |
@@ -34,8 +33,7 @@ discard block |
||
| 34 | 33 | * @param RequestFactory $requestFactory |
| 35 | 34 | * @param LoggerInterface $logger |
| 36 | 35 | */ |
| 37 | - public function __construct(Server $server, RequestFactory $requestFactory, LoggerInterface $logger) |
|
| 38 | - { |
|
| 36 | + public function __construct(Server $server, RequestFactory $requestFactory, LoggerInterface $logger) { |
|
| 39 | 37 | $this->server = $server; |
| 40 | 38 | $this->requestFactory = $requestFactory; |
| 41 | 39 | $this->logger = $logger; |
@@ -65,8 +63,7 @@ discard block |
||
| 65 | 63 | } |
| 66 | 64 | } |
| 67 | 65 | |
| 68 | - protected function handleAPIRequest(APIRequest $APIRequest, ResponseInterface $response) |
|
| 69 | - { |
|
| 66 | + protected function handleAPIRequest(APIRequest $APIRequest, ResponseInterface $response) { |
|
| 70 | 67 | try { |
| 71 | 68 | $APIResponse = $this->server->handleRequest($APIRequest); |
| 72 | 69 | |
@@ -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 |
@@ -28,8 +28,7 @@ |
||
| 28 | 28 | * @param URLParser $URLParser |
| 29 | 29 | * @param HeaderParser $headerParser |
| 30 | 30 | */ |
| 31 | - public function __construct(URLParser $URLParser, HeaderParser $headerParser) |
|
| 32 | - { |
|
| 31 | + public function __construct(URLParser $URLParser, HeaderParser $headerParser) { |
|
| 33 | 32 | $this->URLParser = $URLParser; |
| 34 | 33 | $this->headerParser = $headerParser; |
| 35 | 34 | } |
@@ -48,12 +48,12 @@ |
||
| 48 | 48 | $parsedHeaders = $this->headerParser->parse($serverRequest->getHeaders()); |
| 49 | 49 | |
| 50 | 50 | $urlQueryData = []; |
| 51 | - if($urlQueryString = $parsedURL->getQueryString()) { |
|
| 51 | + if ($urlQueryString = $parsedURL->getQueryString()) { |
|
| 52 | 52 | parse_str($urlQueryString, $urlQueryData); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $apiKey = $parsedURL->getAPIKey(); |
| 56 | - if($apiKey === null) { |
|
| 56 | + if ($apiKey === null) { |
|
| 57 | 57 | $apiKey = $parsedHeaders->getAPIKey(); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | { |
| 48 | 48 | foreach ($headers as $key => $values) { |
| 49 | 49 | if (strtolower($key) == strtolower($this->apiKeyHeaderKey)) { |
| 50 | - foreach($values as $value) { |
|
| 50 | + foreach ($values as $value) { |
|
| 51 | 51 | return $value; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -1,8 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace LunixREST\APIRequest\HeaderParser; |
| 3 | 3 | |
| 4 | -class DefaultHeaderParser implements HeaderParser |
|
| 5 | -{ |
|
| 4 | +class DefaultHeaderParser implements HeaderParser { |
|
| 6 | 5 | |
| 7 | 6 | private $apiKeyHeaderKey; |
| 8 | 7 | |
@@ -10,8 +9,7 @@ discard block |
||
| 10 | 9 | * DefaultHeaderParser constructor. |
| 11 | 10 | * @param string $apiKeyHeaderKey |
| 12 | 11 | */ |
| 13 | - public function __construct($apiKeyHeaderKey = 'x-api-key') |
|
| 14 | - { |
|
| 12 | + public function __construct($apiKeyHeaderKey = 'x-api-key') { |
|
| 15 | 13 | $this->apiKeyHeaderKey = $apiKeyHeaderKey; |
| 16 | 14 | } |
| 17 | 15 | |
@@ -43,8 +41,7 @@ discard block |
||
| 43 | 41 | return $acceptedMIMETypes; |
| 44 | 42 | } |
| 45 | 43 | |
| 46 | - protected function findAPIKey(array $headers) |
|
| 47 | - { |
|
| 44 | + protected function findAPIKey(array $headers) { |
|
| 48 | 45 | foreach ($headers as $key => $values) { |
| 49 | 46 | if (strtolower($key) == strtolower($this->apiKeyHeaderKey)) { |
| 50 | 47 | foreach($values as $value) { |
@@ -55,8 +52,7 @@ discard block |
||
| 55 | 52 | return null; |
| 56 | 53 | } |
| 57 | 54 | |
| 58 | - protected function getContentType(array $headers) |
|
| 59 | - { |
|
| 55 | + protected function getContentType(array $headers) { |
|
| 60 | 56 | foreach ($headers as $key => $values) { |
| 61 | 57 | if (strtolower($key) == 'content-type') { |
| 62 | 58 | foreach ($values as $value) { |
@@ -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 | } |
@@ -11,8 +11,7 @@ discard block |
||
| 11 | 11 | * Class GenericRouter |
| 12 | 12 | * @package LunixREST\Server |
| 13 | 13 | */ |
| 14 | -class GenericRouter implements Router |
|
| 15 | -{ |
|
| 14 | +class GenericRouter implements Router { |
|
| 16 | 15 | /** |
| 17 | 16 | * @var EndpointFactory |
| 18 | 17 | */ |
@@ -22,8 +21,7 @@ discard block |
||
| 22 | 21 | * DefaultRouter constructor. |
| 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 | |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | |
| 4 | 4 | use Psr\Log\LoggerAwareTrait; |
| 5 | 5 | |
| 6 | -abstract class LoggingEndpoint implements Endpoint |
|
| 7 | -{ |
|
| 6 | +abstract class LoggingEndpoint implements Endpoint { |
|
| 8 | 7 | use LoggerAwareTrait; |
| 9 | 8 | } |
@@ -7,8 +7,7 @@ discard block |
||
| 7 | 7 | * Class LoggingEndpointFactory |
| 8 | 8 | * @package LunixREST\Endpoint |
| 9 | 9 | */ |
| 10 | -abstract class LoggingEndpointFactory implements EndpointFactory |
|
| 11 | -{ |
|
| 10 | +abstract class LoggingEndpointFactory implements EndpointFactory { |
|
| 12 | 11 | /** |
| 13 | 12 | * @var LoggerInterface |
| 14 | 13 | */ |
@@ -18,8 +17,7 @@ discard block |
||
| 18 | 17 | * LoggingEndpointFactory constructor. |
| 19 | 18 | * @param LoggerInterface $logger |
| 20 | 19 | */ |
| 21 | - public function __construct(LoggerInterface $logger) |
|
| 22 | - { |
|
| 20 | + public function __construct(LoggerInterface $logger) { |
|
| 23 | 21 | $this->logger = $logger; |
| 24 | 22 | } |
| 25 | 23 | |
@@ -8,8 +8,7 @@ discard block |
||
| 8 | 8 | * Class CachingEndpointFactory |
| 9 | 9 | * @package LunixREST\Endpoint |
| 10 | 10 | */ |
| 11 | -abstract class CachingEndpointFactory extends LoggingEndpointFactory |
|
| 12 | -{ |
|
| 11 | +abstract class CachingEndpointFactory extends LoggingEndpointFactory { |
|
| 13 | 12 | /** |
| 14 | 13 | * @var CacheItemPoolInterface |
| 15 | 14 | */ |
@@ -20,8 +19,7 @@ discard block |
||
| 20 | 19 | * @param CacheItemPoolInterface $cachePool |
| 21 | 20 | * @param LoggerInterface $logger |
| 22 | 21 | */ |
| 23 | - public function __construct(CacheItemPoolInterface $cachePool, LoggerInterface $logger) |
|
| 24 | - { |
|
| 22 | + public function __construct(CacheItemPoolInterface $cachePool, LoggerInterface $logger) { |
|
| 25 | 23 | $this->cachePool = $cachePool; |
| 26 | 24 | parent::__construct($logger); |
| 27 | 25 | } |