Created
March 16, 2018 12:37
-
-
Save walva/23092baf9a09aee039dce94ef0261363 to your computer and use it in GitHub Desktop.
PHP Trait for status
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
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