From a15ae9356471d6bd80db6efa2eddbdf9ec749753 Mon Sep 17 00:00:00 2001 From: Dragon Date: Thu, 11 Apr 2024 17:40:49 +0700 Subject: [PATCH 1/2] add has_validator method --- gump.class.php | 11 ++++++ tests/StaticHasValidatorTest.php | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/StaticHasValidatorTest.php diff --git a/gump.class.php b/gump.class.php index 8d9762b..02120f9 100644 --- a/gump.class.php +++ b/gump.class.php @@ -1950,4 +1950,15 @@ protected function validate_valid_array_size_equal($field, array $input, array $ { return !(!is_array($input[$field]) || count($input[$field]) != $params[0]); } + + /** + * Checks if a validator method exists for a given rule. + * + * @param string $rule + * @return bool + */ + public static function has_validator(string $rule): bool + { + return method_exists(__CLASS__, self::validator_to_method($rule)) || isset(self::$validation_methods[$rule]); + } } diff --git a/tests/StaticHasValidatorTest.php b/tests/StaticHasValidatorTest.php new file mode 100644 index 0000000..023cdcd --- /dev/null +++ b/tests/StaticHasValidatorTest.php @@ -0,0 +1,66 @@ +assertTrue(GUMP::has_validator($rule)); + } + } + + public function testHasValidatorWhenNotExists(): void + { + $this->assertFalse(GUMP::has_validator('custom_rule')); + } +} \ No newline at end of file From f308ee67a58183b8ef3ac9a4757544cc027747ab Mon Sep 17 00:00:00 2001 From: Dragon Date: Thu, 18 Apr 2024 19:41:51 +0700 Subject: [PATCH 2/2] add has_filter method --- gump.class.php | 12 ++++++++++ tests/StaticHasFilterTest.php | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/StaticHasFilterTest.php diff --git a/gump.class.php b/gump.class.php index 02120f9..866cc98 100644 --- a/gump.class.php +++ b/gump.class.php @@ -1961,4 +1961,16 @@ public static function has_validator(string $rule): bool { return method_exists(__CLASS__, self::validator_to_method($rule)) || isset(self::$validation_methods[$rule]); } + + /** + * Checks if a filter method exists for a given filter. + * @param string $filter + * @return bool + */ + public static function has_filter(string $filter): bool + { + return method_exists(__CLASS__, self::filter_to_method($filter)) + || isset(self::$filter_methods[$filter]) + || function_exists($filter); + } } diff --git a/tests/StaticHasFilterTest.php b/tests/StaticHasFilterTest.php new file mode 100644 index 0000000..6c45839 --- /dev/null +++ b/tests/StaticHasFilterTest.php @@ -0,0 +1,45 @@ +assertTrue(GUMP::has_filter($filterRule)); + } + } + + public function testHasFilterWhenNotExists(): void + { + $this->assertFalse(GUMP::has_filter('custom_filter')); + } +} \ No newline at end of file