1 | <?php |
||
2 | |||
3 | namespace graychen\yii2\basic\auth\models; |
||
4 | |||
5 | use yii; |
||
6 | use yii\db\ActiveRecord; |
||
7 | use yii\web\IdentityInterface; |
||
8 | use yii\base\NotSupportedException; |
||
9 | use yii\web\UploadedFile; |
||
10 | use yii\behaviors\TimestampBehavior; |
||
11 | use graychen\yii2\basic\auth\models\AppQuery; |
||
12 | use Ramsey\Uuid\Uuid; |
||
13 | use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; |
||
14 | |||
15 | /** |
||
16 | * This is the models class for table "{{%app}}". |
||
17 | * |
||
18 | * @property integer $id |
||
19 | * @property string $app_name |
||
20 | * @property string $app_icon |
||
21 | * @property string $app_description |
||
22 | * @property string $app_key |
||
23 | * @property string $app_secret |
||
24 | * @property integer $created_at |
||
25 | * @property integer $updated_at |
||
26 | * @property integer $status |
||
27 | * @property string $package_name |
||
28 | * @property boolean $deploy_status |
||
29 | * @property UploadedFile $imageFile |
||
30 | * @property \common\models\AppIosProfile $iosProfile |
||
31 | */ |
||
32 | class App extends ActiveRecord implements IdentityInterface |
||
33 | { |
||
34 | const STATUS_VALID = 1; //正常 |
||
35 | const STATUS_INVALID = -1; //禁用 |
||
36 | |||
37 | public $imageFile; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public static function tableName() |
||
43 | { |
||
44 | return '{{%app}}'; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | public function rules() |
||
51 | { |
||
52 | return [ |
||
53 | [['app_name'], 'required'], |
||
54 | [['created_at', 'updated_at', 'status'], 'integer'], |
||
55 | [['app_name'], 'string', 'max' => 36], |
||
56 | [['app_description'], 'string', 'max' => 125], |
||
57 | [['app_key'], 'string', 'max' => 36], |
||
58 | [['app_name', 'app_secret'], 'string', 'max' => 32], |
||
59 | [ |
||
60 | ['imageFile'], |
||
61 | 'file', |
||
62 | 'skipOnEmpty' => true, |
||
63 | 'extensions' => 'png, jpg', |
||
64 | 'maxFiles' => 1, |
||
65 | 'maxSize' => 300000 |
||
66 | ], |
||
67 | ['status', 'boolean'], |
||
68 | ]; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | public function attributeLabels() |
||
75 | { |
||
76 | return [ |
||
77 | 'id' => Yii::t('app', 'id'), |
||
78 | 'app_name' => Yii::t('app', 'app name'), |
||
79 | 'app_icon' => Yii::t('app', 'app icon'), |
||
80 | 'app_description' => Yii::t('app', 'description'), |
||
81 | 'app_key' => Yii::t('app', 'app key'), |
||
82 | 'app_secret' => Yii::t('app', 'app secret'), |
||
83 | 'created_at' => Yii::t('app', 'create time'), |
||
84 | 'updated_at' => Yii::t('app', 'update time'), |
||
85 | 'status' => Yii::t('app', 'status'), |
||
86 | 'imageFile' => '上传图标', |
||
87 | ]; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | public function behaviors() |
||
94 | { |
||
95 | return [ |
||
96 | 'timestamp' => [ |
||
97 | 'class' => TimestampBehavior::className(), |
||
0 ignored issues
–
show
|
|||
98 | ], |
||
99 | ]; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | * @return AppQuery the active query used by this AR class. |
||
105 | */ |
||
106 | public static function find() |
||
107 | { |
||
108 | return new AppQuery(get_called_class()); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | public static function findIdentity($id) |
||
115 | { |
||
116 | return static::findOne($id); |
||
0 ignored issues
–
show
|
|||
117 | } |
||
118 | |||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | public static function findIdentityByAccessToken($token, $type = null) |
||
124 | { |
||
125 | throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @inheritdoc |
||
130 | */ |
||
131 | public function getId() |
||
132 | { |
||
133 | return $this->getPrimaryKey(); |
||
0 ignored issues
–
show
|
|||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | public function getAuthKey() |
||
140 | { |
||
141 | return $this->auth_key; |
||
0 ignored issues
–
show
The property
auth_key does not exist on graychen\yii2\basic\auth\models\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | public function validateAuthKey($authKey) |
||
148 | { |
||
149 | return $this->getAuthKey() === $authKey; |
||
150 | } |
||
151 | |||
152 | public function beforeSave($insert) |
||
153 | { |
||
154 | if ($this->isNewRecord) { |
||
155 | try { |
||
156 | $uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, $this->app_name); |
||
157 | $this->app_key = $uuid->toString(); |
||
158 | } catch (UnsatisfiedDependencyException $e) { |
||
159 | $this->addError('app_name', $e->getMessage()); |
||
160 | return false; |
||
161 | } |
||
162 | $this->app_secret = Yii::$app->security->generateRandomString(); |
||
163 | $this->status = self::STATUS_VALID; |
||
164 | } |
||
165 | return parent::beforeSave($insert); |
||
166 | } |
||
167 | |||
168 | public static function getStatusList() |
||
169 | { |
||
170 | return [ |
||
171 | [0=>'开发状态'], |
||
172 | [1=>'部署状态'] |
||
173 | ]; |
||
174 | } |
||
175 | } |
||
176 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.