| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | class SnowflakeBehavior extends AttributeBehavior |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | public $attribute = 'id'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @inheritdoc |
||
| 31 | */ |
||
| 32 | public $value; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string|Snowflake |
||
| 36 | */ |
||
| 37 | protected $snowflake = 'snowflake'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @inheritdoc |
||
| 41 | */ |
||
| 42 | public function init() |
||
| 43 | { |
||
| 44 | parent::init(); |
||
| 45 | if (empty($this->attributes)) { |
||
| 46 | $this->attributes = [BaseActiveRecord::EVENT_BEFORE_INSERT => [$this->attribute],]; |
||
| 47 | } |
||
| 48 | if ($this->attribute === null) { |
||
| 49 | throw new InvalidConfigException('Either "attribute" property must be specified.'); |
||
| 50 | } |
||
| 51 | $this->snowflake = Instance::ensure($this->snowflake, 'yuncms\base\Snowflake'); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @inheritdoc |
||
| 56 | */ |
||
| 57 | protected function getValue($event) |
||
| 63 | } |
||
| 64 | } |