|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link http://vistart.name/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 vistart |
|
10
|
|
|
* @license http://vistart.name/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace vistart\Models\models; |
|
14
|
|
|
|
|
15
|
|
|
use vistart\Models\queries\BaseRedisEntityQuery; |
|
16
|
|
|
use vistart\Models\traits\EntityTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Description of BaseRedisEntityModel |
|
20
|
|
|
* |
|
21
|
|
|
* @version 2.0 |
|
22
|
|
|
* @author vistart <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class BaseRedisEntityModel extends \yii\redis\ActiveRecord |
|
25
|
|
|
{ |
|
26
|
|
|
use EntityTrait; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initialize new entity. |
|
30
|
|
|
*/ |
|
31
|
6 |
|
public function init() |
|
32
|
|
|
{ |
|
33
|
6 |
|
if ($this->skipInit) { |
|
34
|
1 |
|
return; |
|
35
|
|
|
} |
|
36
|
6 |
|
$this->initEntityEvents(); |
|
37
|
6 |
|
parent::init(); |
|
38
|
6 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritdoc |
|
42
|
|
|
* @return \vistart\Models\queries\BaseRedisEntityQuery the newly created [[BaseEntityQuery]] or its sub-class instance. |
|
43
|
|
|
*/ |
|
44
|
6 |
|
public static function find() |
|
45
|
|
|
{ |
|
46
|
6 |
|
$self = static::buildNoInitModel(); |
|
47
|
6 |
|
if (!is_string($self->queryClass)) { |
|
48
|
1 |
|
$self->queryClass = BaseRedisEntityQuery::className(); |
|
49
|
1 |
|
} |
|
50
|
6 |
|
$queryClass = $self->queryClass; |
|
51
|
6 |
|
return new $queryClass(get_called_class(), ['noInitModel' => $self]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
6 |
|
public function attributes() |
|
55
|
|
|
{ |
|
56
|
6 |
|
return $this->enabledFields(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function primaryKey() |
|
60
|
|
|
{ |
|
61
|
|
|
$model = static::buildNoInitModel(); |
|
62
|
|
|
if (is_string($model->guidAttribute)) { |
|
63
|
|
|
return [$model->guidAttribute]; |
|
64
|
|
|
} |
|
65
|
|
|
return [$model->idAttribute]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|