@@ -46,11 +46,26 @@ class ConsoleApplication extends yii\console\Application
46
46
TPL ;
47
47
}
48
48
49
+ protected function getUserTemplate ()
50
+ {
51
+ return <<<TPL
52
+
53
+ /**
54
+ * @property {user_identities} \$identity
55
+ */
56
+ class User extends \yii\web\User {
57
+ }
58
+ TPL ;
59
+ }
60
+
61
+
49
62
public function actionIndex ()
50
63
{
51
- $ path = $ this ->outputFile ? $ this ->outputFile : \Yii::$ app ->getVendorPath () . DIRECTORY_SEPARATOR . 'Yii.php ' ;
64
+ $ path = $ this ->outputFile ? $ this ->outputFile :
65
+ \Yii::$ app ->getVendorPath () . DIRECTORY_SEPARATOR . 'Yii.php ' ;
52
66
53
67
$ components = [];
68
+ $ userIdentities = [];
54
69
55
70
foreach (\Yii::$ app ->requestedParams as $ configPath ) {
56
71
if (!file_exists ($ configPath )) {
@@ -64,20 +79,38 @@ public function actionIndex()
64
79
continue ;
65
80
}
66
81
82
+ if ($ name === 'user ' && isset ($ component ['identityClass ' ])) {
83
+ $ userIdentities [] = $ component ['identityClass ' ];
84
+ }
85
+
67
86
$ components [$ name ][] = $ component ['class ' ];
68
87
}
69
88
}
70
89
71
90
$ stubs = '' ;
91
+ $ userStubs = '' ;
92
+
93
+ if (sizeof ($ userIdentities )) {
94
+ $ components ['user ' ][] = 'User ' ;
95
+
96
+ $ userIdentities = implode ('| ' , array_unique ($ userIdentities ));
97
+ $ userStubs = str_replace (
98
+ '{user_identities} ' ,
99
+ $ userIdentities ,
100
+ $ this ->getUserTemplate ()
101
+ );
102
+ }
103
+
72
104
foreach ($ components as $ name => $ classes ) {
73
105
$ classes = implode ('| ' , array_unique ($ classes ));
74
106
$ stubs .= "\n * @property {$ classes } \$$ name " ;
75
107
}
76
108
77
109
$ content = str_replace ('{stubs} ' , $ stubs , $ this ->getTemplate ());
78
110
$ content = str_replace ('{time} ' , date (DATE_ISO8601 ), $ content );
111
+ $ content .= $ userStubs ;
79
112
80
- if ($ content!= @file_get_contents ($ path )) {
113
+ if ($ content != @file_get_contents ($ path )) {
81
114
file_put_contents ($ path , $ content );
82
115
}
83
116
}
0 commit comments