Skip to content

Instantly share code, notes, and snippets.

@walva
Created March 16, 2018 12:37
Show Gist options
  • Save walva/23092baf9a09aee039dce94ef0261363 to your computer and use it in GitHub Desktop.
Save walva/23092baf9a09aee039dce94ef0261363 to your computer and use it in GitHub Desktop.
PHP Trait for status
trait StatusTrait
{
public static function ALL_STATUS($associative = false)
{
$oClass = new \ReflectionClass(__CLASS__);
$all = $oClass->getConstants();
$all = array_filter($all,
function ($value) {
return strpos($value, 'STATUS_') === 0;
}, ARRAY_FILTER_USE_KEY);
if (!$associative) {
return $all;
}
$result = [];
foreach ($all as $key => $item) {
$result[ $item ] = $item;
}
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment