@@ -9,52 +9,52 @@ |
||
9 | 9 | * @package LunixREST\Configuration |
10 | 10 | */ |
11 | 11 | class INIConfiguration implements Configuration { |
12 | - /** |
|
13 | - * @var null |
|
14 | - */ |
|
15 | - protected $nameSpace; |
|
16 | - /** |
|
17 | - * @var |
|
18 | - */ |
|
19 | - protected $filename; |
|
20 | - |
|
21 | - /** |
|
22 | - * @param string $filename |
|
23 | - * @param string $nameSpace |
|
24 | - */ |
|
25 | - public function __construct($filename, $nameSpace = null){ |
|
26 | - $this->filename = $filename; |
|
27 | - $this->nameSpace = $nameSpace; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @param $key |
|
32 | - * @return mixed |
|
33 | - * @throws INIKeyNotFoundException |
|
34 | - * @throws INIParseException |
|
35 | - */ |
|
36 | - public function get($key){ |
|
37 | - $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
|
38 | - |
|
39 | - if($config === false){ |
|
40 | - throw new INIParseException('Could not parse: ' . $this->filename, true); |
|
41 | - } |
|
42 | - |
|
43 | - if($this->nameSpace) { |
|
44 | - if(isset($config[$this->nameSpace])) { |
|
45 | - $config = $config[$this->nameSpace]; |
|
46 | - } else { |
|
47 | - throw new INIKeyNotFoundException(); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - return isset($config[$key]) ? $config[$key] : null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param $key |
|
56 | - */ |
|
57 | - public function set($key){ |
|
58 | - //TODO write this |
|
59 | - } |
|
12 | + /** |
|
13 | + * @var null |
|
14 | + */ |
|
15 | + protected $nameSpace; |
|
16 | + /** |
|
17 | + * @var |
|
18 | + */ |
|
19 | + protected $filename; |
|
20 | + |
|
21 | + /** |
|
22 | + * @param string $filename |
|
23 | + * @param string $nameSpace |
|
24 | + */ |
|
25 | + public function __construct($filename, $nameSpace = null){ |
|
26 | + $this->filename = $filename; |
|
27 | + $this->nameSpace = $nameSpace; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @param $key |
|
32 | + * @return mixed |
|
33 | + * @throws INIKeyNotFoundException |
|
34 | + * @throws INIParseException |
|
35 | + */ |
|
36 | + public function get($key){ |
|
37 | + $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
|
38 | + |
|
39 | + if($config === false){ |
|
40 | + throw new INIParseException('Could not parse: ' . $this->filename, true); |
|
41 | + } |
|
42 | + |
|
43 | + if($this->nameSpace) { |
|
44 | + if(isset($config[$this->nameSpace])) { |
|
45 | + $config = $config[$this->nameSpace]; |
|
46 | + } else { |
|
47 | + throw new INIKeyNotFoundException(); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + return isset($config[$key]) ? $config[$key] : null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param $key |
|
56 | + */ |
|
57 | + public function set($key){ |
|
58 | + //TODO write this |
|
59 | + } |
|
60 | 60 | } |
@@ -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 | } |
@@ -2,6 +2,6 @@ |
||
2 | 2 | namespace LunixREST\Configuration; |
3 | 3 | |
4 | 4 | interface Configuration { |
5 | - public function get($key); |
|
6 | - public function set($key); |
|
5 | + public function get($key); |
|
6 | + public function set($key); |
|
7 | 7 | } |
@@ -17,5 +17,5 @@ |
||
17 | 17 | $helloWorld = new \HelloWorld\Models\HelloWorld(); |
18 | 18 | |
19 | 19 | return $helloWorld; |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -20,6 +20,6 @@ |
||
20 | 20 | |
21 | 21 | |
22 | 22 | public function get(Request $request): ResponseData{ |
23 | - return $this->geoPhone->lookupNumber($request->getInstance()); |
|
24 | - } |
|
23 | + return $this->geoPhone->lookupNumber($request->getInstance()); |
|
24 | + } |
|
25 | 25 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @param string $filename |
16 | 16 | */ |
17 | - public function __construct($filename = 'data.csv'){ |
|
17 | + public function __construct($filename = 'data.csv') { |
|
18 | 18 | $this->fileHandle = fopen($filename, 'r'); |
19 | 19 | } |
20 | 20 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $nextThree = substr($phoneNumber, 3, 3); |
30 | 30 | |
31 | 31 | while (($data = fgetcsv($this->fileHandle)) !== FALSE) { |
32 | - if($areaCode == $data[0] && $nextThree == $data[1]){ |
|
32 | + if($areaCode == $data[0] && $nextThree == $data[1]) { |
|
33 | 33 | return new LookupResponse($data[2], $data[3]); |
34 | 34 | } |
35 | 35 | } |
@@ -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); |
@@ -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 | } |
@@ -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 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function getEndpoint(string $name, string $version): Endpoint { |
25 | 25 | $className = $this->buildVersionedEndpointNamespace($version) . $name; |
26 | - if(!class_exists($className)){ |
|
26 | + if(!class_exists($className)) { |
|
27 | 27 | throw new UnknownEndpointException("Could not find $className"); |
28 | 28 | } |
29 | 29 |