- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
你可以传递任何东西给Zend_Registry::set('myWidget', $someWidget)
, so that it's available later on .
但是,当您在别处检索它时,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
在 ->doBazFlurgle()
调用上让我收到“无法找到要转到的声明”。
/** @var AwesomeWidget $awesome */
注释,但这需要在相当大的代码库中的许多地方进行编辑Find In Path...
搜索字符串 doBazFlurgle
,但这并不十分方便(需要多次击键而不是一次 Ctrl+单击) 我注意到 NetBeans 能够在这种确切情况下跳转到方法定义;有没有一种简单的方法可以在 PHPStorm 中执行相同的操作而无需通过“在整个代码库中搜索 doBazFlurgle
”?我搜索了可用的 IDE 操作、插件和论坛;一切都是徒劳的。
最佳答案
有一种方法:正如@LazyOne指出的那样,列出“从哪里返回的内容”有助于 IDE 理解此类代码;这是somewhat documented on Jetbrains' website :
<?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
)已经解决了这个问题。此文件不是有效的 PHP - PhpStorm 仅将其用于类型提示。这样,Zend_Registry::get('awesome')->doBazFlurgle()
被正确解析为调用 \AwesomeWidget
实例上的方法。
关于php - 通过 Zend_Registry::get() 类型提示 - 如何让 PhpStorm 可以理解导航到声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34317265/
我有一个 Zend MVC 应用程序。我之前在应用程序中为 Zend Registry 设置了其他变量,它运行得非常好。然而这一次它不起作用。当我调用操作 setmanuel 时,脚本会回显测试。但是
假设我有一个这样的 Php 函数: private function verification($isXLSFile = false) { if ($isXLSFile) {
你找到Zend_Registry了吗?有用吗? 它应该用于哪些任务?哪个不是? 变量的全局状态不是一个好习惯。主要对象可以通过 $front->setParam('paramName', $objec
嘿,我想知道在应用程序中访问 Zend_Registry 时是否需要包含 getInstance() ,如果需要,为什么? 例如 Zend_Registry::getInstance()->g
我正在测试我的 Zend Framework 应用程序,并想测试当注册表中未设置特定键时会发生什么。这是我正在测试的功能: protected function getDomainFromConfig
你可以传递任何东西给Zend_Registry::set('myWidget', $someWidget), so that it's available later on . 但是,当您在别处检索它
我是一名优秀的程序员,十分优秀!