diff --git a/src/Strategies/Settings.php b/src/Strategies/Settings.php index b1e9dec..b45f95f 100644 --- a/src/Strategies/Settings.php +++ b/src/Strategies/Settings.php @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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; + } }