Skip to content

Commit

Permalink
Close #21
Browse files Browse the repository at this point in the history
  • Loading branch information
neomerx committed Apr 26, 2016
1 parent b5b94fd commit 589cdf1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Strategies/Settings.php
Expand Up @@ -140,7 +140,7 @@ public function isPreFlightCanBeCached(RequestInterface $request)
*/
public function getPreFlightCacheMaxAge(RequestInterface $request)
{
return $this->settings[self::KEY_FLIGHT_CACHE_MAX_AGE];
return $this->getValue(self::KEY_FLIGHT_CACHE_MAX_AGE, 0);
}

/**
Expand All @@ -158,7 +158,7 @@ public function setPreFlightCacheMaxAge($cacheMaxAge)
*/
public function isForceAddAllowedMethodsToPreFlightResponse()
{
return $this->settings[self::KEY_IS_FORCE_ADD_METHODS];
return $this->getValue(self::KEY_IS_FORCE_ADD_METHODS, false);
}

/**
Expand All @@ -176,7 +176,7 @@ public function setForceAddAllowedMethodsToPreFlightResponse($forceFlag)
*/
public function isForceAddAllowedHeadersToPreFlightResponse()
{
return $this->settings[self::KEY_IS_FORCE_ADD_HEADERS];
return $this->getValue(self::KEY_IS_FORCE_ADD_HEADERS, false);
}

/**
Expand All @@ -194,7 +194,7 @@ public function setForceAddAllowedHeadersToPreFlightResponse($forceFlag)
*/
public function isRequestCredentialsSupported(RequestInterface $request)
{
return $this->settings[self::KEY_IS_USING_CREDENTIALS];
return $this->getValue(self::KEY_IS_USING_CREDENTIALS, false);
}

/**
Expand Down Expand Up @@ -340,7 +340,7 @@ public function setResponseExposedHeaders(array $headers)
*/
public function isCheckHost()
{
return $this->settings[self::KEY_IS_CHECK_HOST];
return $this->getValue(self::KEY_IS_CHECK_HOST, false);
}

/**
Expand Down Expand Up @@ -472,4 +472,15 @@ protected function getDefaultSettings()
self::KEY_IS_CHECK_HOST => false,
];
}

/**
* @param mixed $key
* @param mixed $default
*
* @return mixed
*/
private function getValue($key, $default)
{
return array_key_exists($key, $this->settings) === true ? $this->settings[$key] : $default;
}
}

0 comments on commit 589cdf1

Please sign in to comment.