diff --git a/README.md b/README.md index 87f6a9e..b864d16 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Yii::$app stubs generator for Yii 2 [![Latest Unstable Version](https://poser.pugx.org/bazilio/yii2-stubs-generator/v/unstable)](https://packagist.org/packages/bazilio/yii2-stubs-generator) [![License](https://poser.pugx.org/bazilio/yii2-stubs-generator/license)](https://packagist.org/packages/bazilio/yii2-stubs-generator) -This extension provides no-more-butthurt components autocomplete generator command for Yii 2. +This extension provides no-more-butthurt components & user identity autocomplete generator command for Yii 2. ![in action](https://monosnap.com/file/oHUjBSw7oIJHYAEpQKs4mVVJLfMLrM.png) diff --git a/StubsController.php b/StubsController.php index 5cf357f..b1e8aa5 100644 --- a/StubsController.php +++ b/StubsController.php @@ -46,11 +46,26 @@ class ConsoleApplication extends yii\console\Application TPL; } + protected function getUserTemplate() + { + return <<outputFile ? $this->outputFile : \Yii::$app->getVendorPath() . DIRECTORY_SEPARATOR . 'Yii.php'; + $path = $this->outputFile ? $this->outputFile : + \Yii::$app->getVendorPath() . DIRECTORY_SEPARATOR . 'Yii.php'; $components = []; + $userIdentities = []; foreach (\Yii::$app->requestedParams as $configPath) { if (!file_exists($configPath)) { @@ -64,11 +79,28 @@ public function actionIndex() continue; } + if ($name === 'user' && isset($component['identityClass'])) { + $userIdentities[] = $component['identityClass']; + } + $components[$name][] = $component['class']; } } $stubs = ''; + $userStubs = ''; + + if (sizeof($userIdentities)) { + $components['user'][] = 'User'; + + $userIdentities = implode('|', array_unique($userIdentities)); + $userStubs = str_replace( + '{user_identities}', + $userIdentities, + $this->getUserTemplate() + ); + } + foreach ($components as $name => $classes) { $classes = implode('|', array_unique($classes)); $stubs .= "\n * @property {$classes} \$$name"; @@ -76,8 +108,9 @@ public function actionIndex() $content = str_replace('{stubs}', $stubs, $this->getTemplate()); $content = str_replace('{time}', date(DATE_ISO8601), $content); + $content .= $userStubs; - if($content!=@file_get_contents($path)) { + if ($content != @file_get_contents($path)) { file_put_contents($path, $content); } }