{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/16261","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/16261/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/16261/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/16261/events","html_url":"https://github.com/yiisoft/yii2/issues/16261","id":322013665,"number":16261,"title":"IDE auto-completion of module methods","user":{"login":"rugabarbo","id":6429469,"avatar_url":"https://avatars0.githubusercontent.com/u/6429469?v=4","gravatar_id":"","url":"https://api.github.com/users/rugabarbo","html_url":"https://github.com/rugabarbo","followers_url":"https://api.github.com/users/rugabarbo/followers","following_url":"https://api.github.com/users/rugabarbo/following{/other_user}","gists_url":"https://api.github.com/users/rugabarbo/gists{/gist_id}","starred_url":"https://api.github.com/users/rugabarbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rugabarbo/subscriptions","organizations_url":"https://api.github.com/users/rugabarbo/orgs","repos_url":"https://api.github.com/users/rugabarbo/repos","events_url":"https://api.github.com/users/rugabarbo/events{/privacy}","received_events_url":"https://api.github.com/users/rugabarbo/received_events","type":"User","site_admin":false},"labels":[{"id":33241821,"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:under%20discussion","name":"status:under discussion","color":"f7c6c7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2018-05-10T17:25:53Z","updated_at":"2018-05-13T20:47:49Z","closed_at":"2018-05-12T12:25:19Z","author_association":"CONTRIBUTOR","body":"## What I'm using now\r\n\r\n1. I created my **own component**:\r\n\r\n```php\r\nuse yii\\base\\Component;\r\nuse yii\\helpers\\Inflector;\r\n\r\nclass ModuleAccessor extends Component\r\n{\r\n    private $_modules = [];\r\n\r\n    public function __get($name)\r\n    {\r\n        if (!array_key_exists($name, $this->_modules)) {\r\n            $moduleId = Inflector::camel2id($name);\r\n            $this->_modules[$name] = \\Yii::$app->getModule($moduleId);\r\n        }\r\n\r\n        return $this->_modules[$name];\r\n    }\r\n}\r\n```\r\n\r\n2. Added the following lines to the **app configuration**:\r\n\r\n```php\r\n   'components' => [\r\n        'mod' => [\r\n            'class' => \\rugabarbo\\packagename\\components\\ModuleAccessor::class,\r\n        ],\r\n   ]\r\n```\r\n\r\n3. Added the following lines to the **[autocompletion.php](https://github.com/samdark/yii2-cookbook/blob/master/book/ide-autocompletion.md)**:\r\n\r\n```php\r\n/**\r\n * @property \\rugabarbo\\packagename\\modules\\Email\\EmailModule $email\r\n */\r\nclass ModuleAccessor\r\n{\r\n}\r\n\r\n/**\r\n * @property ModuleAccessor $mod\r\n */\r\nabstract class BaseApplication extends yii\\base\\Application\r\n{\r\n}\r\n```\r\n\r\n4. And now I call **module methods** like this:\r\n\r\n```php\r\n\\Yii::$app->mod->email->queue($to, $subject, $body, $params);\r\n```\r\n\r\n## Why?\r\n\r\nNeed IDE autocompletion for module methods. Using of the syntax `\\Yii::$app->getModule('...')->` does not give such an opportunity. \r\n\r\n## What I suggest\r\n\r\nImplement something similar to my **ModuleAccessor** at the kernel level ☺️ "},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/388654895","html_url":"https://github.com/yiisoft/yii2/issues/16261#issuecomment-388654895","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/16261","id":388654895,"user":{"login":"samdark","id":47294,"avatar_url":"https://avatars2.githubusercontent.com/u/47294?v=4","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"created_at":"2018-05-13T20:47:49Z","updated_at":"2018-05-13T20:47:49Z","author_association":"OWNER","body":"Думаю, если так делать, придётся переделать много чего... Пока не вижу нормального способа. Твой — дублирование конфига, по сути. Не очень нравится."}}
{"actor":{"display_login":"samdark"}}