%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
namespace mdm\converter;
use ReflectionClass;
/**
* Description of EnumTrait
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
trait EnumTrait
{
/**
* @var array
*/
private static $_constants = [];
/**
* Get all constant name
* @param string $prefix
* @return array
*/
public static function enums($prefix = '')
{
return array_flip(static::constants($prefix));
}
/**
* Get all constant value
* @param string $prefix
* @return array
*/
public static function constants($prefix = '')
{
$className = get_called_class();
if (!isset(self::$_constants[$className][$prefix])) {
$ref = new ReflectionClass($className);
self::$_constants[$className][$prefix] = [];
foreach ($ref->getConstants() as $constName => $constValue) {
if ($prefix === '' || strpos($constName, $prefix) === 0) {
self::$_constants[$className][$prefix][substr($constName, strlen($prefix))] = $constValue;
}
}
}
return self::$_constants[$className][$prefix];
}
protected function getLogical($attribute, $prefix)
{
$enums = static::enums($prefix);
return isset($enums[$this->$attribute]) ? $enums[$this->$attribute] : null;
}
protected function setLogical($attribute, $prefix, $value)
{
$constant = static::constants($prefix);
if (isset($constant[strtoupper($value)])) {
$this->$attribute = $constant[strtoupper($value)];
} elseif ($value === null) {
$this->$attribute = null;
}
}
}