From cb29ae00d78d6a527a09dea2e2f1cd0aecbed4bb Mon Sep 17 00:00:00 2001 From: Rafael Dohms Date: Mon, 25 Jul 2011 22:53:42 -0300 Subject: [PATCH] [Filter] Adding ToLower and ToUpper filter rules, closes #2 --- Rules/ToLower.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++ Rules/ToUpper.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 Rules/ToLower.php create mode 100644 Rules/ToUpper.php diff --git a/Rules/ToLower.php b/Rules/ToLower.php new file mode 100644 index 0000000..0f1faea --- /dev/null +++ b/Rules/ToLower.php @@ -0,0 +1,65 @@ +useEncoding()) { + return mb_strtolower((string) $value, $this->encoding); + } + + return strtolower((string) $value); + } + + /** + * Verify is encoding is set and if we have the proper + * function to use it + * + * @return boolean + */ + public function useEncoding() + { + if ($this->encoding === null) { + return false; + } + + if (!function_exists('mb_strtolower')) { + throw new FilterException( + 'mbstring is required to use ToLower with an encoding.'); + } + + $this->encoding = (string) $this->encoding; + $encodings = array_map('strtolower', mb_list_encodings()); + + if (!in_array(strtolower($this->encoding), $encodings)) { + throw new FilterException( + "mbstring does not support the '".$this->encoding."' encoding" + ); + } + + return true; + } + +} \ No newline at end of file diff --git a/Rules/ToUpper.php b/Rules/ToUpper.php new file mode 100644 index 0000000..5f62700 --- /dev/null +++ b/Rules/ToUpper.php @@ -0,0 +1,65 @@ +useEncoding()) { + return mb_strtoupper((string) $value, $this->encoding); + } + + return strtoupper((string) $value); + } + + /** + * Verify is encoding is set and if we have the proper + * function to use it + * + * @return boolean + */ + public function useEncoding() + { + if ($this->encoding === null) { + return false; + } + + if (!function_exists('mb_strtoupper')) { + throw new FilterException( + 'mbstring is required to use ToLower with an encoding.'); + } + + $this->encoding = (string) $this->encoding; + $encodings = array_map('strtolower', mb_list_encodings()); + + if (!in_array(strtolower($this->encoding), $encodings)) { + throw new FilterException( + "mbstring does not support the '".$this->encoding."' encoding" + ); + } + + return true; + } + +} \ No newline at end of file