@@ -19,7 +19,7 @@ |
||
| 19 | 19 | /** |
| 20 | 20 | * @param array $keys |
| 21 | 21 | */ |
| 22 | - public function __construct(Array $keys) |
|
| 22 | + public function __construct(array $keys) |
|
| 23 | 23 | { |
| 24 | 24 | $this->keys = $keys; |
| 25 | 25 | } |
@@ -9,8 +9,7 @@ discard block |
||
| 9 | 9 | * Class AllAccessListAccessControl |
| 10 | 10 | * @package LunixRESTBasics\AccessControl |
| 11 | 11 | */ |
| 12 | -class AllAccessListAccessControl implements AccessControl |
|
| 13 | -{ |
|
| 12 | +class AllAccessListAccessControl implements AccessControl { |
|
| 14 | 13 | /** |
| 15 | 14 | * @var array |
| 16 | 15 | */ |
@@ -19,8 +18,7 @@ discard block |
||
| 19 | 18 | /** |
| 20 | 19 | * @param array $keys |
| 21 | 20 | */ |
| 22 | - public function __construct(Array $keys) |
|
| 23 | - { |
|
| 21 | + public function __construct(Array $keys) { |
|
| 24 | 22 | $this->keys = $keys; |
| 25 | 23 | } |
| 26 | 24 | |
@@ -28,8 +26,7 @@ discard block |
||
| 28 | 26 | * @param \LunixREST\APIRequest\APIRequest $request |
| 29 | 27 | * @return bool true if key is valid |
| 30 | 28 | */ |
| 31 | - public function validateAccess(APIRequest $request) |
|
| 32 | - { |
|
| 29 | + public function validateAccess(APIRequest $request) { |
|
| 33 | 30 | return $this->validateKey($request->getApiKey()); |
| 34 | 31 | } |
| 35 | 32 | |
@@ -37,8 +34,7 @@ discard block |
||
| 37 | 34 | * @param $apiKey |
| 38 | 35 | * @return bool true if key is in the array passed to this object in it's construction |
| 39 | 36 | */ |
| 40 | - public function validateKey($apiKey) |
|
| 41 | - { |
|
| 37 | + public function validateKey($apiKey) { |
|
| 42 | 38 | return in_array($apiKey, $this->keys); |
| 43 | 39 | } |
| 44 | 40 | } |
@@ -7,8 +7,7 @@ |
||
| 7 | 7 | * Interface AccessControl |
| 8 | 8 | * @package LunixREST\AccessControl |
| 9 | 9 | */ |
| 10 | -interface AccessControl |
|
| 11 | -{ |
|
| 10 | +interface AccessControl { |
|
| 12 | 11 | /** |
| 13 | 12 | * Validates if a given request should be able to access what it's trying to |
| 14 | 13 | * @param $request |
@@ -8,14 +8,12 @@ discard block |
||
| 8 | 8 | * Class PublicAccessControl |
| 9 | 9 | * @package LunixREST\AccessControl |
| 10 | 10 | */ |
| 11 | -class PublicAccessControl implements AccessControl |
|
| 12 | -{ |
|
| 11 | +class PublicAccessControl implements AccessControl { |
|
| 13 | 12 | /** |
| 14 | 13 | * @param \LunixREST\APIRequest\APIRequest $request |
| 15 | 14 | * @return bool |
| 16 | 15 | */ |
| 17 | - public function validateAccess(APIRequest $request) |
|
| 18 | - { |
|
| 16 | + public function validateAccess(APIRequest $request) { |
|
| 19 | 17 | return true; |
| 20 | 18 | } |
| 21 | 19 | |
@@ -23,8 +21,7 @@ discard block |
||
| 23 | 21 | * @param $apiKey |
| 24 | 22 | * @return bool |
| 25 | 23 | */ |
| 26 | - public function validateKey($apiKey) |
|
| 27 | - { |
|
| 24 | + public function validateKey($apiKey) { |
|
| 28 | 25 | return true; |
| 29 | 26 | } |
| 30 | 27 | } |
@@ -8,8 +8,7 @@ discard block |
||
| 8 | 8 | * Class OneKeyAccessControl |
| 9 | 9 | * @package LunixREST\AccessControl |
| 10 | 10 | */ |
| 11 | -class OneKeyAccessControl implements AccessControl |
|
| 12 | -{ |
|
| 11 | +class OneKeyAccessControl implements AccessControl { |
|
| 13 | 12 | /** |
| 14 | 13 | * @var string |
| 15 | 14 | */ |
@@ -18,8 +17,7 @@ discard block |
||
| 18 | 17 | /** |
| 19 | 18 | * @param string $key |
| 20 | 19 | */ |
| 21 | - public function __construct($key) |
|
| 22 | - { |
|
| 20 | + public function __construct($key) { |
|
| 23 | 21 | $this->key = $key; |
| 24 | 22 | } |
| 25 | 23 | |
@@ -27,8 +25,7 @@ discard block |
||
| 27 | 25 | * @param \LunixREST\APIRequest\APIRequest $request |
| 28 | 26 | * @return bool true if key is valid |
| 29 | 27 | */ |
| 30 | - public function validateAccess(APIRequest $request) |
|
| 31 | - { |
|
| 28 | + public function validateAccess(APIRequest $request) { |
|
| 32 | 29 | return $this->validateKey($request->getApiKey()); |
| 33 | 30 | } |
| 34 | 31 | |
@@ -36,8 +33,7 @@ discard block |
||
| 36 | 33 | * @param $apiKey |
| 37 | 34 | * @return bool true if key is the key specified in the constructor |
| 38 | 35 | */ |
| 39 | - public function validateKey($apiKey) |
|
| 40 | - { |
|
| 36 | + public function validateKey($apiKey) { |
|
| 41 | 37 | return $apiKey === $this->key; |
| 42 | 38 | } |
| 43 | 39 | } |
@@ -55,10 +55,10 @@ |
||
| 55 | 55 | public function __construct( |
| 56 | 56 | string $method, |
| 57 | 57 | string $endpoint, |
| 58 | - ?string $element, |
|
| 58 | + ? string $element, |
|
| 59 | 59 | array $acceptableMIMETypes, |
| 60 | - ?string $version, |
|
| 61 | - ?string $apiKey, |
|
| 60 | + ? string $version, |
|
| 61 | + ? string $apiKey, |
|
| 62 | 62 | array $queryData, |
| 63 | 63 | $data |
| 64 | 64 | ) { |
@@ -6,8 +6,7 @@ discard block |
||
| 6 | 6 | * Class APIRequest |
| 7 | 7 | * @package LunixREST\Request |
| 8 | 8 | */ |
| 9 | -class APIRequest |
|
| 10 | -{ |
|
| 9 | +class APIRequest { |
|
| 11 | 10 | /** |
| 12 | 11 | * @var string |
| 13 | 12 | */ |
@@ -91,8 +90,7 @@ discard block |
||
| 91 | 90 | /** |
| 92 | 91 | * @return null|string |
| 93 | 92 | */ |
| 94 | - public function getElement() |
|
| 95 | - { |
|
| 93 | + public function getElement() { |
|
| 96 | 94 | return $this->element; |
| 97 | 95 | } |
| 98 | 96 | |
@@ -107,16 +105,14 @@ discard block |
||
| 107 | 105 | /** |
| 108 | 106 | * @return null|string |
| 109 | 107 | */ |
| 110 | - public function getVersion() |
|
| 111 | - { |
|
| 108 | + public function getVersion() { |
|
| 112 | 109 | return $this->version; |
| 113 | 110 | } |
| 114 | 111 | |
| 115 | 112 | /** |
| 116 | 113 | * @return null|string |
| 117 | 114 | */ |
| 118 | - public function getApiKey() |
|
| 119 | - { |
|
| 115 | + public function getApiKey() { |
|
| 120 | 116 | return $this->apiKey; |
| 121 | 117 | } |
| 122 | 118 | |
@@ -131,8 +127,7 @@ discard block |
||
| 131 | 127 | /** |
| 132 | 128 | * @return array|null|object |
| 133 | 129 | */ |
| 134 | - public function getData() |
|
| 135 | - { |
|
| 130 | + public function getData() { |
|
| 136 | 131 | return $this->data; |
| 137 | 132 | } |
| 138 | 133 | } |
@@ -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; |
@@ -6,8 +6,7 @@ discard block |
||
| 6 | 6 | * Class ParsedURL |
| 7 | 7 | * @package LunixREST\APIRequest\URLParser |
| 8 | 8 | */ |
| 9 | -class ParsedURL |
|
| 10 | -{ |
|
| 9 | +class ParsedURL { |
|
| 11 | 10 | /** |
| 12 | 11 | * @var string |
| 13 | 12 | */ |
@@ -42,8 +41,7 @@ discard block |
||
| 42 | 41 | * @param array $acceptableMIMETypes |
| 43 | 42 | * @param null|string $queryString |
| 44 | 43 | */ |
| 45 | - public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) |
|
| 46 | - { |
|
| 44 | + public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) { |
|
| 47 | 45 | $this->endpoint = $endpoint; |
| 48 | 46 | $this->element = $element; |
| 49 | 47 | $this->version = $version; |
@@ -63,24 +61,21 @@ discard block |
||
| 63 | 61 | /** |
| 64 | 62 | * @return null|string |
| 65 | 63 | */ |
| 66 | - public function getElement() |
|
| 67 | - { |
|
| 64 | + public function getElement() { |
|
| 68 | 65 | return $this->element; |
| 69 | 66 | } |
| 70 | 67 | |
| 71 | 68 | /** |
| 72 | 69 | * @return null|string |
| 73 | 70 | */ |
| 74 | - public function getVersion() |
|
| 75 | - { |
|
| 71 | + public function getVersion() { |
|
| 76 | 72 | return $this->version; |
| 77 | 73 | } |
| 78 | 74 | |
| 79 | 75 | /** |
| 80 | 76 | * @return null|string |
| 81 | 77 | */ |
| 82 | - public function getApiKey() |
|
| 83 | - { |
|
| 78 | + public function getApiKey() { |
|
| 84 | 79 | return $this->apiKey; |
| 85 | 80 | } |
| 86 | 81 | |
@@ -95,8 +90,7 @@ discard block |
||
| 95 | 90 | /** |
| 96 | 91 | * @return null|string |
| 97 | 92 | */ |
| 98 | - public function getQueryString() |
|
| 99 | - { |
|
| 93 | + public function getQueryString() { |
|
| 100 | 94 | return $this->queryString; |
| 101 | 95 | } |
| 102 | 96 | } |
@@ -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 | } |
@@ -20,8 +20,7 @@ discard block |
||
| 20 | 20 | * Class HTTPServer |
| 21 | 21 | * @package LunixREST\Server |
| 22 | 22 | */ |
| 23 | -class HTTPServer |
|
| 24 | -{ |
|
| 23 | +class HTTPServer { |
|
| 25 | 24 | use LoggerAwareTrait; |
| 26 | 25 | |
| 27 | 26 | /** |
@@ -39,8 +38,7 @@ discard block |
||
| 39 | 38 | * @param RequestFactory $requestFactory |
| 40 | 39 | * @param LoggerInterface $logger |
| 41 | 40 | */ |
| 42 | - public function __construct(Server $server, RequestFactory $requestFactory, LoggerInterface $logger) |
|
| 43 | - { |
|
| 41 | + public function __construct(Server $server, RequestFactory $requestFactory, LoggerInterface $logger) { |
|
| 44 | 42 | $this->server = $server; |
| 45 | 43 | $this->requestFactory = $requestFactory; |
| 46 | 44 | $this->logger = $logger; |
@@ -76,8 +74,7 @@ discard block |
||
| 76 | 74 | * @param ResponseInterface $response |
| 77 | 75 | * @return ResponseInterface |
| 78 | 76 | */ |
| 79 | - protected function handleAPIRequest(APIRequest $APIRequest, ResponseInterface $response) |
|
| 80 | - { |
|
| 77 | + protected function handleAPIRequest(APIRequest $APIRequest, ResponseInterface $response) { |
|
| 81 | 78 | try { |
| 82 | 79 | $APIResponse = $this->server->handleRequest($APIRequest); |
| 83 | 80 | |
@@ -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 | |