Created
December 30, 2020 12:52
-
-
Save mcunha98/48e513741cc9c0265b92eafa62e91804 to your computer and use it in GitHub Desktop.
Check if current class has constant/enumeration based on value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Assets | |
{ | |
const ASSETS_BANNER = 'banner'; | |
const ASSETS_BLOG = 'blog'; | |
const ASSETS_TEMPLATE = 'template'; | |
private static $constants; | |
public static function isConstant($value) | |
{ | |
if (!isset(self::$constants)) | |
{ | |
$reflect = new ReflectionClass(__CLASS__); | |
self::$constants = $reflect->getConstants(); | |
} | |
return in_array($value, self::$constants); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment