Last active
February 14, 2020 03:04
-
-
Save murilozilli/c8738b2b33691764677b4af53e8959c5 to your computer and use it in GitHub Desktop.
Constant validation by 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
<?php | |
namespace Application\Model; | |
class Model | |
{ | |
/** | |
* @var string | |
*/ | |
const TYPE_PDF = 'pdf'; | |
/** | |
* @var string | |
*/ | |
const TYPE_EMAIL_MARKETING = 'mkt'; | |
/** | |
* @var string | |
*/ | |
const TYPE_BUSINESS_CARD = 'business_card'; | |
/** | |
* @var string | |
*/ | |
const TYPE_TIMBER_PAPER = 'timbred_paper'; | |
/** | |
* @var string | |
*/ | |
const TYPE_LANDING_PAGE = 'landing_page'; | |
/** | |
* Inform if given type is a valid constant | |
* @param string $type | |
* @return bool | |
*/ | |
public static function isValidType($type) { | |
$reflectedClass = new \ReflectionClass(self::class); | |
$constants = $reflectedClass->getConstants(); | |
foreach ($constants as $constName => $constValue) { | |
if (substr($constName, 0, 4) === 'TYPE' && $constValue === $type) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment