Last active
February 9, 2016 05:13
-
-
Save metalagman/815ee61e3a8190d1b59b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 common\traits; | |
use yii\base\InvalidConfigException; | |
use yii\helpers\ArrayHelper; | |
/** | |
* Trait for default status column | |
* | |
* Class StatusTrait | |
* @package common\traits | |
* | |
* @property int $status | |
* @property string|null $statusLabel | |
*/ | |
trait StatusTrait | |
{ | |
/** | |
* @param null $default | |
* @return string|null | |
*/ | |
public function getStatusLabel($default = null) | |
{ | |
return ArrayHelper::getValue(static::getStatusLabels(), $this->status, $default); | |
} | |
/** | |
* @throws InvalidConfigException | |
* @return array|null | |
*/ | |
public static function getStatusLabels() | |
{ | |
throw new InvalidConfigException('Please define static getStatusLabels() in your class ' . get_called_class()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment