Skip to content

Instantly share code, notes, and snippets.

@metalagman
Last active February 9, 2016 05:13
Show Gist options
  • Save metalagman/815ee61e3a8190d1b59b to your computer and use it in GitHub Desktop.
Save metalagman/815ee61e3a8190d1b59b to your computer and use it in GitHub Desktop.
<?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