|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\models\base; |
|
4
|
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2ActiveRecordInterface; |
|
6
|
|
|
use rhertogh\Yii2Oauth2Server\models\behaviors\BooleanBehavior; |
|
7
|
|
|
use rhertogh\Yii2Oauth2Server\models\behaviors\TimestampBehavior; |
|
8
|
|
|
use rhertogh\Yii2Oauth2Server\models\traits\Oauth2ActiveRecordTrait; |
|
9
|
|
|
use yii\db\ActiveRecord; |
|
10
|
|
|
use yii\helpers\Inflector; |
|
11
|
|
|
use yii\helpers\StringHelper; |
|
12
|
|
|
|
|
13
|
|
|
abstract class Oauth2BaseActiveRecord extends ActiveRecord implements Oauth2ActiveRecordInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use Oauth2ActiveRecordTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string|null The name for the table |
|
19
|
|
|
*/ |
|
20
|
|
|
public static $tableName = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
116 |
|
public static function tableName() |
|
26
|
|
|
{ |
|
27
|
116 |
|
if (!empty(static::$tableName)) { |
|
28
|
2 |
|
return static::$tableName; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
115 |
|
return '{{%' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_') . '}}'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
117 |
|
public function behaviors() |
|
38
|
|
|
{ |
|
39
|
117 |
|
return [ |
|
40
|
117 |
|
'timestampBehavior' => [ |
|
41
|
117 |
|
'class' => TimestampBehavior::class, |
|
42
|
117 |
|
'createdAtAttribute' => $this->hasAttribute('created_at') ? 'created_at' : false, |
|
43
|
117 |
|
'updatedAtAttribute' => $this->hasAttribute('updated_at') ? 'updated_at' : false, |
|
44
|
117 |
|
], |
|
45
|
117 |
|
'booleanBehavior' => BooleanBehavior::class, |
|
46
|
117 |
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
117 |
|
public function init() |
|
50
|
|
|
{ |
|
51
|
117 |
|
parent::init(); |
|
52
|
117 |
|
$this->loadDefaultValues(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
7 |
|
public function getDirtyAttributes($names = null) |
|
56
|
|
|
{ |
|
57
|
|
|
/** @var BooleanBehavior $booleanBehavior */ |
|
58
|
7 |
|
$booleanBehavior = $this->getBehavior('booleanBehavior'); |
|
59
|
|
|
|
|
60
|
7 |
|
$booleanBehavior && $booleanBehavior->boolToInt(); |
|
61
|
7 |
|
$dirtyAttributes = parent::getDirtyAttributes(); |
|
62
|
7 |
|
$booleanBehavior && $booleanBehavior->intToBool(); |
|
63
|
|
|
|
|
64
|
7 |
|
return $dirtyAttributes; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|