@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param EndpointFactory $endpointFactory |
23 | 23 | */ |
24 | - public function __construct(EndpointFactory $endpointFactory){ |
|
24 | + public function __construct(EndpointFactory $endpointFactory) { |
|
25 | 25 | $this->endpointFactory = $endpointFactory; |
26 | 26 | } |
27 | 27 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @throws MethodNotFoundException |
44 | 44 | */ |
45 | 45 | protected function executeEndpoint(Endpoint $endpoint, Request $request): ResponseData { |
46 | - if(!method_exists($endpoint, $request->getMethod())){ |
|
47 | - throw new MethodNotFoundException("The endpoint method " . $request->getMethod() . " was not found"); |
|
46 | + if (!method_exists($endpoint, $request->getMethod())) { |
|
47 | + throw new MethodNotFoundException("The endpoint method ".$request->getMethod()." was not found"); |
|
48 | 48 | } |
49 | 49 | return call_user_func([$endpoint, $request->getMethod()], $request); |
50 | 50 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param EndpointFactory $endpointFactory |
23 | 23 | */ |
24 | - public function __construct(EndpointFactory $endpointFactory){ |
|
24 | + public function __construct(EndpointFactory $endpointFactory) { |
|
25 | 25 | $this->endpointFactory = $endpointFactory; |
26 | 26 | } |
27 | 27 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @throws MethodNotFoundException |
44 | 44 | */ |
45 | 45 | protected function executeEndpoint(Endpoint $endpoint, Request $request): ResponseData { |
46 | - if(!method_exists($endpoint, $request->getMethod())){ |
|
46 | + if(!method_exists($endpoint, $request->getMethod())) { |
|
47 | 47 | throw new MethodNotFoundException("The endpoint method " . $request->getMethod() . " was not found"); |
48 | 48 | } |
49 | 49 | return call_user_func([$endpoint, $request->getMethod()], $request); |
@@ -11,11 +11,11 @@ |
||
11 | 11 | * @throws NotAcceptableResponseTypeException |
12 | 12 | */ |
13 | 13 | public function getResponse(ResponseData $data, array $acceptedMIMETypes): Response { |
14 | - if(empty($acceptedMIMETypes)){ |
|
14 | + if (empty($acceptedMIMETypes)) { |
|
15 | 15 | $acceptedMIMETypes = $this->getSupportedMIMETypes(); |
16 | 16 | } |
17 | 17 | |
18 | - foreach($acceptedMIMETypes as $acceptedMIMEType) { |
|
18 | + foreach ($acceptedMIMETypes as $acceptedMIMEType) { |
|
19 | 19 | switch (strtolower($acceptedMIMEType)) { |
20 | 20 | case "application/json": |
21 | 21 | return new JSONResponse($data); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * @throws NotAcceptableResponseTypeException |
12 | 12 | */ |
13 | 13 | public function getResponse(ResponseData $data, array $acceptedMIMETypes): Response { |
14 | - if(empty($acceptedMIMETypes)){ |
|
14 | + if(empty($acceptedMIMETypes)) { |
|
15 | 15 | $acceptedMIMETypes = $this->getSupportedMIMETypes(); |
16 | 16 | } |
17 | 17 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param ResponseFactory $responseFactory |
40 | 40 | * @param EndpointFactory $endpointFactory |
41 | 41 | */ |
42 | - public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory){ |
|
42 | + public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory) { |
|
43 | 43 | $this->accessControl = $accessControl; |
44 | 44 | $this->throttle = $throttle; |
45 | 45 | $this->responseFactory = $responseFactory; |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | |
61 | 61 | $this->validateExtension($request); |
62 | 62 | |
63 | - if($this->throttle->shouldThrottle($request)) { |
|
63 | + if ($this->throttle->shouldThrottle($request)) { |
|
64 | 64 | throw new ThrottleLimitExceededException('Request limit exceeded'); |
65 | 65 | } |
66 | 66 | |
67 | - if(!$this->accessControl->validateAccess($request)) { |
|
67 | + if (!$this->accessControl->validateAccess($request)) { |
|
68 | 68 | throw new AccessDeniedException("API key does not have the required permissions to access requested resource"); |
69 | 69 | } |
70 | 70 | |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @param Request $request |
80 | 80 | * @throws InvalidAPIKeyException |
81 | 81 | */ |
82 | - protected function validateKey(Request $request){ |
|
83 | - if(!$this->accessControl->validateKey($request->getApiKey())){ |
|
82 | + protected function validateKey(Request $request) { |
|
83 | + if (!$this->accessControl->validateKey($request->getApiKey())) { |
|
84 | 84 | throw new InvalidAPIKeyException('Invalid API key'); |
85 | 85 | } |
86 | 86 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | protected function validateExtension(Request $request) { |
93 | 93 | $formats = $this->responseFactory->getSupportedMIMETypes(); |
94 | - if(empty($formats) || ( |
|
94 | + if (empty($formats) || ( |
|
95 | 95 | !empty($request->getAcceptableMIMETypes()) && empty(array_intersect($request->getAcceptableMIMETypes(), $formats)) |
96 | 96 | )) { |
97 | 97 | throw new NotAcceptableResponseTypeException('None of the requests acceptable response types are valid'); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param ResponseFactory $responseFactory |
41 | 41 | * @param EndpointFactory $endpointFactory |
42 | 42 | */ |
43 | - public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory){ |
|
43 | + public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory) { |
|
44 | 44 | $this->accessControl = $accessControl; |
45 | 45 | $this->throttle = $throttle; |
46 | 46 | $this->responseFactory = $responseFactory; |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | * @param Request $request |
81 | 81 | * @throws InvalidAPIKeyException |
82 | 82 | */ |
83 | - protected function validateKey(Request $request){ |
|
84 | - if(!$this->accessControl->validateKey($request->getApiKey())){ |
|
83 | + protected function validateKey(Request $request) { |
|
84 | + if(!$this->accessControl->validateKey($request->getApiKey())) { |
|
85 | 85 | throw new InvalidAPIKeyException('Invalid API key'); |
86 | 86 | } |
87 | 87 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | public function __construct($body) { |
18 | 18 | $this->jsonString = $body; |
19 | 19 | $this->parsedData = json_decode($body, true); |
20 | - if($this->parsedData === null) { |
|
20 | + if ($this->parsedData === null) { |
|
21 | 21 | throw new InvalidRequestDataException('Content not valid JSON'); |
22 | 22 | } |
23 | 23 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @internal param string $extension |
65 | 65 | */ |
66 | 66 | |
67 | - public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, array $acceptableMIMETypes = [], $instance = null){ |
|
67 | + public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, array $acceptableMIMETypes = [], $instance = null) { |
|
68 | 68 | $this->method = strtolower($method); |
69 | 69 | $this->headers = $headers; |
70 | 70 | $this->body = $body; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return string |
89 | 89 | */ |
90 | 90 | public function getMethod() { |
91 | - return $this->method . ($this->instance ? '' : 'All'); |
|
91 | + return $this->method.($this->instance ? '' : 'All'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -64,7 +64,7 @@ |
||
64 | 64 | * @internal param string $extension |
65 | 65 | */ |
66 | 66 | |
67 | - public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, array $acceptableMIMETypes = [], $instance = null){ |
|
67 | + public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, array $acceptableMIMETypes = [], $instance = null) { |
|
68 | 68 | $this->method = strtolower($method); |
69 | 69 | $this->headers = $headers; |
70 | 70 | $this->body = $body; |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $parsedData = $bodyParser->parse($data); |
58 | 58 | |
59 | 59 | $apiKey = $parsedURL->getAPIKey(); |
60 | - if($apiKey === null) { |
|
60 | + if ($apiKey === null) { |
|
61 | 61 | $apiKey = $parsedHeaders->getAPIKey(); |
62 | 62 | } |
63 | 63 |
@@ -40,28 +40,28 @@ |
||
40 | 40 | |
41 | 41 | try { |
42 | 42 | $response = $this->server->handleRequest($request); |
43 | - header("Content-Type: " . $response->getMIMEType()); |
|
43 | + header("Content-Type: ".$response->getMIMEType()); |
|
44 | 44 | echo $response->getAsString(); |
45 | - } catch(InvalidAPIKeyException $e){ |
|
45 | + } catch (InvalidAPIKeyException $e) { |
|
46 | 46 | header('400 Bad Request', true, 400); |
47 | - } catch(UnknownEndpointException $e){ |
|
47 | + } catch (UnknownEndpointException $e) { |
|
48 | 48 | header('404 Not Found', true, 404); |
49 | - } catch(NotAcceptableResponseTypeException $e){ |
|
49 | + } catch (NotAcceptableResponseTypeException $e) { |
|
50 | 50 | header('406 Not Acceptable', true, 406); |
51 | - } catch(AccessDeniedException $e){ |
|
51 | + } catch (AccessDeniedException $e) { |
|
52 | 52 | header('403 Access Denied', true, 403); |
53 | - } catch(ThrottleLimitExceededException $e){ |
|
53 | + } catch (ThrottleLimitExceededException $e) { |
|
54 | 54 | header('429 Too Many Requests', true, 429); |
55 | 55 | } catch (\Exception $e) { |
56 | 56 | header('500 Internal Server Error', true, 500); |
57 | 57 | } |
58 | - } catch(InvalidRequestURLException $e){ |
|
58 | + } catch (InvalidRequestURLException $e) { |
|
59 | 59 | header('400 Bad Request', true, 400); |
60 | - } catch(UnknownContentTypeException $e){ |
|
60 | + } catch (UnknownContentTypeException $e) { |
|
61 | 61 | header('400 Bad Request', true, 400); |
62 | - } catch(InvalidRequestDataException $e){ |
|
62 | + } catch (InvalidRequestDataException $e) { |
|
63 | 63 | header('400 Bad Request', true, 400); |
64 | - } catch(\Exception $e){ |
|
64 | + } catch (\Exception $e) { |
|
65 | 65 | header('500 Internal Server Error', true, 500); |
66 | 66 | } |
67 | 67 | } |
@@ -42,26 +42,26 @@ |
||
42 | 42 | $response = $this->server->handleRequest($request); |
43 | 43 | header("Content-Type: " . $response->getMIMEType()); |
44 | 44 | echo $response->getAsString(); |
45 | - } catch(InvalidAPIKeyException $e){ |
|
45 | + } catch(InvalidAPIKeyException $e) { |
|
46 | 46 | header('400 Bad Request', true, 400); |
47 | - } catch(UnknownEndpointException $e){ |
|
47 | + } catch(UnknownEndpointException $e) { |
|
48 | 48 | header('404 Not Found', true, 404); |
49 | - } catch(NotAcceptableResponseTypeException $e){ |
|
49 | + } catch(NotAcceptableResponseTypeException $e) { |
|
50 | 50 | header('406 Not Acceptable', true, 406); |
51 | - } catch(AccessDeniedException $e){ |
|
51 | + } catch(AccessDeniedException $e) { |
|
52 | 52 | header('403 Access Denied', true, 403); |
53 | - } catch(ThrottleLimitExceededException $e){ |
|
53 | + } catch(ThrottleLimitExceededException $e) { |
|
54 | 54 | header('429 Too Many Requests', true, 429); |
55 | 55 | } catch (\Exception $e) { |
56 | 56 | header('500 Internal Server Error', true, 500); |
57 | 57 | } |
58 | - } catch(InvalidRequestURLException $e){ |
|
58 | + } catch(InvalidRequestURLException $e) { |
|
59 | 59 | header('400 Bad Request', true, 400); |
60 | - } catch(UnknownContentTypeException $e){ |
|
60 | + } catch(UnknownContentTypeException $e) { |
|
61 | 61 | header('400 Bad Request', true, 400); |
62 | - } catch(InvalidRequestDataException $e){ |
|
62 | + } catch(InvalidRequestDataException $e) { |
|
63 | 63 | header('400 Bad Request', true, 400); |
64 | - } catch(\Exception $e){ |
|
64 | + } catch(\Exception $e) { |
|
65 | 65 | header('500 Internal Server Error', true, 500); |
66 | 66 | } |
67 | 67 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * @param array $keys |
17 | 17 | */ |
18 | - public function __construct(Array $keys){ |
|
18 | + public function __construct(array $keys){ |
|
19 | 19 | $this->keys = $keys; |
20 | 20 | } |
21 | 21 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @param array $keys |
19 | 19 | */ |
20 | - public function __construct(Array $keys){ |
|
20 | + public function __construct(Array $keys) { |
|
21 | 21 | $this->keys = $keys; |
22 | 22 | } |
23 | 23 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param \LunixREST\Request\Request $request |
26 | 26 | * @return bool true if key is valid |
27 | 27 | */ |
28 | - public function validateAccess(Request $request){ |
|
28 | + public function validateAccess(Request $request) { |
|
29 | 29 | return $this->validateKey($request->getApiKey()); |
30 | 30 | } |
31 | 31 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param $apiKey |
34 | 34 | * @return bool true if key is in the array passed to this object in it's construction |
35 | 35 | */ |
36 | - public function validateKey($apiKey){ |
|
36 | + public function validateKey($apiKey) { |
|
37 | 37 | return in_array($apiKey, $this->keys); |
38 | 38 | } |
39 | 39 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @param array $keys |
19 | 19 | */ |
20 | - public function __construct(Array $keys){ |
|
20 | + public function __construct(Array $keys) { |
|
21 | 21 | $this->keys = $keys; |
22 | 22 | } |
23 | 23 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param \LunixREST\Request\Request $request |
26 | 26 | * @return bool true if key is valid |
27 | 27 | */ |
28 | - public function validateAccess(Request $request){ |
|
28 | + public function validateAccess(Request $request) { |
|
29 | 29 | return $this->validateKey($request->getApiKey()); |
30 | 30 | } |
31 | 31 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param $apiKey |
34 | 34 | * @return bool true if key is in the array passed to this object in it's construction |
35 | 35 | */ |
36 | - public function validateKey($apiKey){ |
|
36 | + public function validateKey($apiKey) { |
|
37 | 37 | return in_array($apiKey, $this->keys); |
38 | 38 | } |
39 | 39 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param string $filename |
23 | 23 | * @param string $nameSpace |
24 | 24 | */ |
25 | - public function __construct($filename, $nameSpace = null){ |
|
25 | + public function __construct($filename, $nameSpace = null) { |
|
26 | 26 | $this->filename = $filename; |
27 | 27 | $this->nameSpace = $nameSpace; |
28 | 28 | } |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * @throws INIKeyNotFoundException |
34 | 34 | * @throws INIParseException |
35 | 35 | */ |
36 | - public function get($key){ |
|
36 | + public function get($key) { |
|
37 | 37 | $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
38 | 38 | |
39 | - if($config === false){ |
|
39 | + if($config === false) { |
|
40 | 40 | throw new INIParseException('Could not parse: ' . $this->filename, true); |
41 | 41 | } |
42 | 42 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * @param $key |
56 | 56 | */ |
57 | - public function set($key){ |
|
57 | + public function set($key) { |
|
58 | 58 | //TODO write this |
59 | 59 | } |
60 | 60 | } |
@@ -10,54 +10,54 @@ |
||
10 | 10 | * @package LunixREST\Configuration |
11 | 11 | */ |
12 | 12 | class INIConfiguration implements Configuration { |
13 | - /** |
|
14 | - * @var null |
|
15 | - */ |
|
16 | - protected $nameSpace; |
|
17 | - /** |
|
18 | - * @var |
|
19 | - */ |
|
20 | - protected $filename; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $filename |
|
24 | - * @param string $nameSpace |
|
25 | - */ |
|
26 | - public function __construct($filename, $nameSpace = null){ |
|
27 | - $this->filename = $filename; |
|
28 | - $this->nameSpace = $nameSpace; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
13 | + /** |
|
14 | + * @var null |
|
15 | + */ |
|
16 | + protected $nameSpace; |
|
17 | + /** |
|
18 | + * @var |
|
19 | + */ |
|
20 | + protected $filename; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $filename |
|
24 | + * @param string $nameSpace |
|
25 | + */ |
|
26 | + public function __construct($filename, $nameSpace = null){ |
|
27 | + $this->filename = $filename; |
|
28 | + $this->nameSpace = $nameSpace; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | 32 | * //TODO: Move throws/loading to constructor to keep with get contract |
33 | - * @param $key |
|
34 | - * @return mixed |
|
35 | - * @throws INIKeyNotFoundException |
|
36 | - * @throws INIParseException |
|
37 | - */ |
|
38 | - public function get($key){ |
|
39 | - //TODO: Cache the file contents |
|
40 | - $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
|
41 | - |
|
42 | - if($config === false){ |
|
43 | - throw new INIParseException('Could not parse: ' . $this->filename, true); |
|
44 | - } |
|
45 | - |
|
46 | - if($this->nameSpace) { |
|
47 | - if(isset($config[$this->nameSpace])) { |
|
48 | - $config = $config[$this->nameSpace]; |
|
49 | - } else { |
|
50 | - throw new INIKeyNotFoundException(); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return isset($config[$key]) ? $config[$key] : null; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param $key |
|
59 | - */ |
|
60 | - public function set($key){ |
|
61 | - //TODO write this |
|
62 | - } |
|
33 | + * @param $key |
|
34 | + * @return mixed |
|
35 | + * @throws INIKeyNotFoundException |
|
36 | + * @throws INIParseException |
|
37 | + */ |
|
38 | + public function get($key){ |
|
39 | + //TODO: Cache the file contents |
|
40 | + $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
|
41 | + |
|
42 | + if($config === false){ |
|
43 | + throw new INIParseException('Could not parse: ' . $this->filename, true); |
|
44 | + } |
|
45 | + |
|
46 | + if($this->nameSpace) { |
|
47 | + if(isset($config[$this->nameSpace])) { |
|
48 | + $config = $config[$this->nameSpace]; |
|
49 | + } else { |
|
50 | + throw new INIKeyNotFoundException(); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return isset($config[$key]) ? $config[$key] : null; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param $key |
|
59 | + */ |
|
60 | + public function set($key){ |
|
61 | + //TODO write this |
|
62 | + } |
|
63 | 63 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string $filename |
24 | 24 | * @param string $nameSpace |
25 | 25 | */ |
26 | - public function __construct($filename, $nameSpace = null){ |
|
26 | + public function __construct($filename, $nameSpace = null) { |
|
27 | 27 | $this->filename = $filename; |
28 | 28 | $this->nameSpace = $nameSpace; |
29 | 29 | } |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @throws INIKeyNotFoundException |
36 | 36 | * @throws INIParseException |
37 | 37 | */ |
38 | - public function get($key){ |
|
38 | + public function get($key) { |
|
39 | 39 | //TODO: Cache the file contents |
40 | - $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
|
40 | + $config = parse_ini_file($this->filename, (bool) $this->nameSpace); |
|
41 | 41 | |
42 | - if($config === false){ |
|
43 | - throw new INIParseException('Could not parse: ' . $this->filename, true); |
|
42 | + if ($config === false) { |
|
43 | + throw new INIParseException('Could not parse: '.$this->filename, true); |
|
44 | 44 | } |
45 | 45 | |
46 | - if($this->nameSpace) { |
|
47 | - if(isset($config[$this->nameSpace])) { |
|
46 | + if ($this->nameSpace) { |
|
47 | + if (isset($config[$this->nameSpace])) { |
|
48 | 48 | $config = $config[$this->nameSpace]; |
49 | 49 | } else { |
50 | 50 | throw new INIKeyNotFoundException(); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @param $key |
59 | 59 | */ |
60 | - public function set($key){ |
|
60 | + public function set($key) { |
|
61 | 61 | //TODO write this |
62 | 62 | } |
63 | 63 | } |