你可以将任何东西传递给Zend_Registry::set('myWidget', $someWidget)
, 以便稍后可用 http://framework.zend.com/manual/1.12/en/zend.registry.using.html.
但是,当您在其他地方检索它时,PhpStorm IDE 没有任何关于“myWidget”类型的线索。
<?php
class AwesomeWidget {
public function doBazFlurgle() {
// doesn't matter what exactly happens here
return mt_rand();
}
}
?>
<?php
class FooController {
public function init() {
$someWidget = new AwesomeWidget();
Zend_Registry::set('awesome', $someWidget);
}
public function barAction() {
$this->init();
$awesome = Zend_Registry::get('awesome');
$awesomeNumber = $awesome->doBazFlurgle();
}
}
Navigate to declaration
on the ->doBazFlurgle()
打电话给我一个“找不到要前往的声明”。
-
我可以添加 https://stackoverflow.com/questions/14663336/phpstorm-intellisense-code-completion-for-inherited-properties?rq=1 a
/** @var AwesomeWidget $awesome */
注释,但这需要在相当大的代码库中的许多地方进行编辑
-
I could https://stackoverflow.com/questions/27465980/phpstorm-code-completion-not-working-on-php-methods/27531847#27531847 also 添加返回类型 https://stackoverflow.com/questions/20992123/phpstorm-annotation-for-inherited-method-return-typeZend_Registry 的注释,但这看起来不太可维护(有许多不同类的实例以这种方式存储)。
- 我可以搜索字符串
doBazFlurgle
通过Find In Path...
,但这并不完全方便(与单个 Ctrl+单击相比,需要多次击键)
我注意到 NetBeans 能够在这种情况下跳转到方法定义;有没有一种简单的方法可以在 PHPStorm 中执行相同的操作,而无需通过“搜索整个代码库来查找doBazFlurgle
“?我已经搜索了可用的 IDE 操作、插件和论坛;但都是徒劳。
有一种方法:正如指出的@LazyOne https://stackoverflow.com/users/783119/lazyone,列出“从哪里返回什么”有助于 IDE 理解此类代码;这是Jetbrains 网站上有一些记录 https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata:
<?php
/** @link https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata */
// note that this is not valid PHP code, just a stub for the IDE
namespace PHPSTORM_META {
$STATIC_METHOD_TYPES = [
\Zend_Registry::get('') => [
'awesome' instanceof \AwesomeWidget, // this is the class as seen in the question
'fooSetting' instanceof \Zend_Config, // this came in from application settings
'quuxData' instanceof \ArrayAccess, // an arraylike object
]
];
}
包括这个文件(名为.phpstorm.meta.php
按照惯例)在项目中已经解决了这个问题。这个文件是not有效的 PHP - PhpStorm 仅将其用于类型提示。那样,Zend_Registry::get('awesome')->doBazFlurgle()
被正确解析为在实例上调用该方法\AwesomeWidget
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)