Skip to content

Commit 53e499d

Browse files
committed
feature: user identity stubs
1 parent 3bf31cf commit 53e499d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Yii::$app stubs generator for Yii 2
55
[![Latest Unstable Version](https://poser.pugx.org/bazilio/yii2-stubs-generator/v/unstable)](https://packagist.org/packages/bazilio/yii2-stubs-generator)
66
[![License](https://poser.pugx.org/bazilio/yii2-stubs-generator/license)](https://packagist.org/packages/bazilio/yii2-stubs-generator)
77

8-
This extension provides no-more-butthurt components autocomplete generator command for Yii 2.
8+
This extension provides no-more-butthurt components & user identity autocomplete generator command for Yii 2.
99

1010
![in action](https://monosnap.com/file/oHUjBSw7oIJHYAEpQKs4mVVJLfMLrM.png)
1111

StubsController.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,26 @@ class ConsoleApplication extends yii\console\Application
4646
TPL;
4747
}
4848

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+
4962
public function actionIndex()
5063
{
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';
5266

5367
$components = [];
68+
$userIdentities = [];
5469

5570
foreach (\Yii::$app->requestedParams as $configPath) {
5671
if (!file_exists($configPath)) {
@@ -64,20 +79,38 @@ public function actionIndex()
6479
continue;
6580
}
6681

82+
if ($name === 'user' && isset($component['identityClass'])) {
83+
$userIdentities[] = $component['identityClass'];
84+
}
85+
6786
$components[$name][] = $component['class'];
6887
}
6988
}
7089

7190
$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+
72104
foreach ($components as $name => $classes) {
73105
$classes = implode('|', array_unique($classes));
74106
$stubs .= "\n * @property {$classes} \$$name";
75107
}
76108

77109
$content = str_replace('{stubs}', $stubs, $this->getTemplate());
78110
$content = str_replace('{time}', date(DATE_ISO8601), $content);
111+
$content .= $userStubs;
79112

80-
if($content!=@file_get_contents($path)) {
113+
if ($content != @file_get_contents($path)) {
81114
file_put_contents($path, $content);
82115
}
83116
}

0 commit comments

Comments
 (0)