Add method to verify user input exists as class constant of given type
This commit is contained in:
@@ -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 {};
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user