diff --git a/source/lib/SihnonFramework/Exceptions.class.php b/source/lib/SihnonFramework/Exceptions.class.php index 4aa2764..947d05c 100644 --- a/source/lib/SihnonFramework/Exceptions.class.php +++ b/source/lib/SihnonFramework/Exceptions.class.php @@ -7,6 +7,7 @@ class SihnonFramework_Exception_AlreadyInitialisted extends SihnonFramework_E class SihnonFramework_Exception_NotImplemented extends SihnonFramework_Exception {}; class SihnonFramework_Exception_MissingDefinition extends SihnonFramework_Exception {}; +class SihnonFramework_Exception_ClassNotFound extends SihnonFramework_Exception {}; class SihnonFramework_Exception_TemplateException extends SihnonFramework_Exception {}; class SihnonFramework_Exception_AbortEntirePage extends SihnonFramework_Exception_TemplateException {}; diff --git a/source/lib/SihnonFramework/Main.class.php b/source/lib/SihnonFramework/Main.class.php index 2e91893..f3cbb76 100644 --- a/source/lib/SihnonFramework/Main.class.php +++ b/source/lib/SihnonFramework/Main.class.php @@ -370,6 +370,25 @@ class SihnonFramework_Main { return $size; } + public static function isClassConstantValue($class, $prefix, $value) { + try { + $reflected = new ReflectionClass($class); + } catch (ReflectionException $e) { + throw new Sihnon_Exception_ClassNotFound($class); + } + + $constants = $reflected->getConstants(); + foreach ($constants as $const_name => $const_value) { + if (preg_match("/{$prefix}/", $const_name)) { + if ($value == $const_value) { + return true; + } + } + } + + return false; + } + } SihnonFramework_Main::initialise(); diff --git a/test/constants.php b/test/constants.php new file mode 100644 index 0000000..f8c0bd9 --- /dev/null +++ b/test/constants.php @@ -0,0 +1,16 @@ + \ No newline at end of file