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