| @@ -21,7 +21,7 @@ | ||
| 21 | 21 |  		header('404 Not Found', 404); | 
| 22 | 22 |  	} catch(\LunixREST\Exceptions\AccessDeniedException $e){ | 
| 23 | 23 |  		header('403 Access Denied', 403); | 
| 24 | -	}  catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ | |
| 24 | +	} catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ | |
| 25 | 25 |  		header('429 Too Many Requests', 429); | 
| 26 | 26 |  	} catch(\LunixREST\Exceptions\InvalidResponseFormatException $e){ | 
| 27 | 27 |  		header('500 Internal Server Error', 500); | 
| @@ -11,26 +11,26 @@ | ||
| 11 | 11 | $router = new \LunixREST\Router\Router($accessControl, $throttle, $responseFactory, $endpointFactory); | 
| 12 | 12 | |
| 13 | 13 |  try { | 
| 14 | -	$request =  \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1.0/public/helloworld.json");// \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); | |
| 14 | +	$request = \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1.0/public/helloworld.json"); // \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); | |
| 15 | 15 | |
| 16 | 16 |  	try { | 
| 17 | 17 | $response = $router->route($request); | 
| 18 | 18 | echo $response->getAsString(); | 
| 19 | -	} catch(\LunixREST\Exceptions\InvalidAPIKeyException $e){ | |
| 19 | +	} catch (\LunixREST\Exceptions\InvalidAPIKeyException $e) { | |
| 20 | 20 |  		header('400 Bad Request', true, 400); | 
| 21 | -	} catch(\LunixREST\Endpoint\Exceptions\UnknownEndpointException $e){ | |
| 21 | +	} catch (\LunixREST\Endpoint\Exceptions\UnknownEndpointException $e) { | |
| 22 | 22 |  		header('404 Not Found', true, 404); | 
| 23 | -	} catch(\LunixREST\Response\Exceptions\UnknownResponseTypeException $e){ | |
| 23 | +	} catch (\LunixREST\Response\Exceptions\UnknownResponseTypeException $e) { | |
| 24 | 24 |  		header('404 Not Found', true, 404); | 
| 25 | -	} catch(\LunixREST\Exceptions\AccessDeniedException $e){ | |
| 25 | +	} catch (\LunixREST\Exceptions\AccessDeniedException $e) { | |
| 26 | 26 |  		header('403 Access Denied', true, 403); | 
| 27 | -	}  catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ | |
| 27 | +	} catch (\LunixREST\Exceptions\ThrottleLimitExceededException $e) { | |
| 28 | 28 |  		header('429 Too Many Requests', true, 429); | 
| 29 | -	} catch(Exception $e){ | |
| 29 | +	} catch (Exception $e) { | |
| 30 | 30 |  		header('500 Internal Server Error', true, 500); | 
| 31 | 31 | } | 
| 32 | -} catch(\LunixREST\Exceptions\InvalidRequestFormatException $e){ | |
| 32 | +} catch (\LunixREST\Exceptions\InvalidRequestFormatException $e) { | |
| 33 | 33 |  	header('400 Bad Request', true, 400); | 
| 34 | -} catch(Exception $e){ | |
| 34 | +} catch (Exception $e) { | |
| 35 | 35 |  	header('500 Internal Server Error', true, 500); | 
| 36 | 36 | } | 
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | /** | 
| 16 | 16 | * @param AccessControl[] $accessControls array of access controls to use based on implmentation | 
| 17 | 17 | */ | 
| 18 | -    public function __construct(array $accessControls){ | |
| 18 | +    public function __construct(array $accessControls) { | |
| 19 | 19 | $this->accessControls = $accessControls; | 
| 20 | 20 | } | 
| 21 | 21 | } | 
| 22 | 22 | \ No newline at end of file | 
| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | /** | 
| 16 | 16 | * @param string $publicKey | 
| 17 | 17 | */ | 
| 18 | -    public function __construct($publicKey = 'public'){ | |
| 18 | +    public function __construct($publicKey = 'public') { | |
| 19 | 19 | $this->publicKey = $publicKey; | 
| 20 | 20 | } | 
| 21 | 21 | |
| @@ -23,7 +23,7 @@ discard block | ||
| 23 | 23 | * @param \LunixREST\Request\Request $request | 
| 24 | 24 | * @return bool true if key is valid | 
| 25 | 25 | */ | 
| 26 | -    public function validateAccess(Request $request){ | |
| 26 | +    public function validateAccess(Request $request) { | |
| 27 | 27 | return $this->validateKey($request->getApiKey()); | 
| 28 | 28 | } | 
| 29 | 29 | |
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | * @param $apiKey | 
| 32 | 32 | * @return bool true if key is the key specified in the constructor | 
| 33 | 33 | */ | 
| 34 | -    public function validateKey($apiKey){ | |
| 34 | +    public function validateKey($apiKey) { | |
| 35 | 35 | return $apiKey === $this->publicKey; | 
| 36 | 36 | } | 
| 37 | 37 | } | 
| 38 | 38 | \ No newline at end of file | 
| @@ -22,7 +22,7 @@ discard block | ||
| 22 | 22 | * @param Configuration $config a config that has a list of valid keys in the stored $configKey | 
| 23 | 23 | * @param string $configKey key to use when accessing the list of valid keys from the $config | 
| 24 | 24 | */ | 
| 25 | -    public function __construct(Configuration $config, $configKey = 'keys'){ | |
| 25 | +    public function __construct(Configuration $config, $configKey = 'keys') { | |
| 26 | 26 | $this->config = $config; | 
| 27 | 27 | $this->configKey = $configKey; | 
| 28 | 28 | } | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | * @param \LunixREST\Request\Request $request | 
| 32 | 32 | * @return bool true if this key is valid | 
| 33 | 33 | */ | 
| 34 | -    public function validateAccess(Request $request){ | |
| 34 | +    public function validateAccess(Request $request) { | |
| 35 | 35 | return $this->validateKey($request->getApiKey()); | 
| 36 | 36 | } | 
| 37 | 37 | |
| @@ -39,7 +39,7 @@ discard block | ||
| 39 | 39 | * @param $apiKey | 
| 40 | 40 | * @return bool true if the key is found inside of the array returned by the config when $config->get is called with the key from the constructor | 
| 41 | 41 | */ | 
| 42 | -    public function validateKey($apiKey){ | |
| 42 | +    public function validateKey($apiKey) { | |
| 43 | 43 | return in_array($apiKey, $this->config->get($this->configKey)); | 
| 44 | 44 | } | 
| 45 | 45 | } | 
| 46 | 46 | \ No newline at end of file | 
| @@ -15,7 +15,7 @@ discard block | ||
| 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 | |
| @@ -23,7 +23,7 @@ discard block | ||
| 23 | 23 | * @param \LunixREST\Request\Request $request | 
| 24 | 24 | * @return bool true if key is valid | 
| 25 | 25 | */ | 
| 26 | -    public function validateAccess(Request $request){ | |
| 26 | +    public function validateAccess(Request $request) { | |
| 27 | 27 | return $this->validateKey($request->getApiKey()); | 
| 28 | 28 | } | 
| 29 | 29 | |
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | * @param $apiKey | 
| 32 | 32 | * @return bool true if key is in the array passed to this object in it's construction | 
| 33 | 33 | */ | 
| 34 | -    public function validateKey($apiKey){ | |
| 34 | +    public function validateKey($apiKey) { | |
| 35 | 35 | return in_array($apiKey, $this->keys); | 
| 36 | 36 | } | 
| 37 | 37 | } | 
| 38 | 38 | \ No newline at end of file | 
| @@ -11,9 +11,9 @@ discard block | ||
| 11 | 11 | * @param \LunixREST\Request\Request $request | 
| 12 | 12 | * @return bool true if all of the $accessControls' validate access methods returned true for the given request | 
| 13 | 13 | */ | 
| 14 | -    public function validateAccess(Request $request){ | |
| 15 | -        foreach($this->accessControls as $accessControl){ | |
| 16 | -            if(!$accessControl->validateAccess($request)){ | |
| 14 | +    public function validateAccess(Request $request) { | |
| 15 | +        foreach ($this->accessControls as $accessControl) { | |
| 16 | +            if (!$accessControl->validateAccess($request)) { | |
| 17 | 17 | return false; | 
| 18 | 18 | } | 
| 19 | 19 | } | 
| @@ -24,9 +24,9 @@ discard block | ||
| 24 | 24 | * @param $apiKey | 
| 25 | 25 | * @return bool true if all of the $accessControls' validate key methods returned true for the given request | 
| 26 | 26 | */ | 
| 27 | -    public function validateKey($apiKey){ | |
| 28 | -        foreach($this->accessControls as $accessControl){ | |
| 29 | -            if(!$accessControl->validateKey($apiKey)){ | |
| 27 | +    public function validateKey($apiKey) { | |
| 28 | +        foreach ($this->accessControls as $accessControl) { | |
| 29 | +            if (!$accessControl->validateKey($apiKey)) { | |
| 30 | 30 | return false; | 
| 31 | 31 | } | 
| 32 | 32 | } | 
| @@ -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,15 +33,15 @@ discard block | ||
| 33 | 33 | * @throws INIKeyNotFoundException | 
| 34 | 34 | * @throws INIParseException | 
| 35 | 35 | */ | 
| 36 | -	public function get($key){ | |
| 37 | - $config = parse_ini_file($this->filename, (bool)$this->nameSpace); | |
| 36 | +	public function get($key) { | |
| 37 | + $config = parse_ini_file($this->filename, (bool) $this->nameSpace); | |
| 38 | 38 | |
| 39 | -		if($config === false){ | |
| 40 | -			throw new INIParseException('Could not parse: ' . $this->filename, true); | |
| 39 | +		if ($config === false) { | |
| 40 | +			throw new INIParseException('Could not parse: '.$this->filename, true); | |
| 41 | 41 | } | 
| 42 | 42 | |
| 43 | -		if($this->nameSpace) { | |
| 44 | -			if(isset($config[$this->nameSpace])) { | |
| 43 | +		if ($this->nameSpace) { | |
| 44 | +			if (isset($config[$this->nameSpace])) { | |
| 45 | 45 | $config = $config[$this->nameSpace]; | 
| 46 | 46 |  			} else { | 
| 47 | 47 | throw new INIKeyNotFoundException(); | 
| @@ -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 | } | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 | * @param string $extension | 
| 58 | 58 | * @param string $instance | 
| 59 | 59 | */ | 
| 60 | -    public function __construct($method, array $headers, array $data, $ip, $version, $apiKey, $endpoint, $extension, $instance = null){ | |
| 60 | +    public function __construct($method, array $headers, array $data, $ip, $version, $apiKey, $endpoint, $extension, $instance = null) { | |
| 61 | 61 | $this->method = strtolower($method); | 
| 62 | 62 | $this->headers = $headers; | 
| 63 | 63 | $this->data = $data; | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | */ | 
| 83 | 83 | public function getMethod() | 
| 84 | 84 |      { | 
| 85 | - return $this->method . ($this->instance ? '' : 'All'); | |
| 85 | + return $this->method.($this->instance ? '' : 'All'); | |
| 86 | 86 | } | 
| 87 | 87 | |
| 88 | 88 | /** | 
| @@ -150,9 +150,9 @@ discard block | ||
| 150 | 150 | * @return Request | 
| 151 | 151 | * @throws InvalidRequestFormatException | 
| 152 | 152 | */ | 
| 153 | -    public static function createFromURL($method, array $headers, array $data, $ip, $url){ | |
| 153 | +    public static function createFromURL($method, array $headers, array $data, $ip, $url) { | |
| 154 | 154 |          $splitURL = explode('/', trim($url, '/')); | 
| 155 | -        if(count($splitURL) < 3){ | |
| 155 | +        if (count($splitURL) < 3) { | |
| 156 | 156 | throw new InvalidRequestFormatException(); | 
| 157 | 157 | } | 
| 158 | 158 | //Find endpoint | 
| @@ -165,7 +165,7 @@ discard block | ||
| 165 | 165 | |
| 166 | 166 | $instance = null; | 
| 167 | 167 | |
| 168 | -        if(count($splitURL) == 4){ | |
| 168 | +        if (count($splitURL) == 4) { | |
| 169 | 169 |              $instance = implode('.', $splitExtension); | 
| 170 | 170 |          } else { | 
| 171 | 171 |              $endpoint = implode('.', $splitExtension); | 
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | * @throws UnknownResponseTypeException | 
| 12 | 12 | */ | 
| 13 | 13 |      public function getResponse(ResponseData $data, string $type): Response { | 
| 14 | -        switch(strtolower($type)) { | |
| 14 | +        switch (strtolower($type)) { | |
| 15 | 15 | case "json": | 
| 16 | 16 | return new JSONResponse($data); | 
| 17 | 17 | default: |