* Returns the parameter value filtered as a boolean. Uses flag: * FILTER_VALIDATE_BOOLEAN */ public function getBoolean(string $key, $default = false): bool { return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN); } /** * Returns the parameter value validated as a 2 character country code. If * the preg_match for exactly two alphabetic characters fails, the default * value is returned. */ public function getCountryCode(string $key, string $default = ''): string { $country = strtoupper(trim($this->get($key, $default))); if (preg_match('/^[a-z]{2}$/i', $country)) { return $country; } return $default; } /** * Returns a boolean if the value is considered not empty. * @param array|int|string|null $keys */ public function isNotEmpty($keys = null): bool { return $this->isEmpty($keys) === false; } /** * Returns a boolean if the value of one of the keys is considered empty. * @param array|int|string|null $keys */ public function isOneEmpty($keys = []): bool { foreach ($keys as $key) { if ($this->isEmpty($key)) { return true; } } return false; } /** * Filter key. * @return mixed * @see http://php.net/manual/en/function.filter-var.php */ public function filter(string $key, $default = null, int $filter = FILTER_DEFAULT, $options = []) { $value = $this->get($key, $default); // Always turn $options into an array - this allows filter_var option shortcuts. if (!\is_array($options) && $options) { $options = ['flags' => $options]; } // Add a convenience check for arrays. if (\is_array($value) && !isset($options['flags'])) { $options['flags'] = FILTER_REQUIRE_ARRAY; } return filter_var($value, $filter, $options); } }