PhpStorm中的ZF2视图助手的自动补全 [英] Autocompletion for ZF2 view helpers in PhpStorm

查看:115
本文介绍了PhpStorm中的ZF2视图助手的自动补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道PHPStorm是否对视图助手自动完成功能有内置的支持,或者是否有可能为其编写插件. 我不想为此使用内联var定义,因为如果我使用很多视图助手,这样做会很麻烦

Does anyone know if PHPStorm has some builtin support for view helper autocompletion or a possibility to write a plugin for it. I don't want to use inline var definitions for this as this would be cumbersome to do if I use a lot of view helpers

$this->inlineScript()-> //I want some autocomplete here.

$this->translate('some translation')-> //Please give me autocompletion

如果我使用var定义,它将最终变成这样,但它确实会使我的视线混乱:

If I use var definitions it will end up as something like this, but it will really clutter up my view:

/* @var $inlineScript \Zend\View\Helper\InlineScript */
$inlineScript = $this->inlineScript();
$inlineScript-> //Now I have autocompletion goodness

/* @var $translate \Zend\I18n\View\Helper\Translate */
$translate = $this->translate();
$translate('some translation')-> //Now I have autocompletion goodness

推荐答案

注意.我将评论中讨论的方法作为答案发布.

NOTE I'm posting my method discussed in the comments as answer.

要提示不存在的方法,语法如下:

To typehint non-existing methods, the syntax is as following:

/**
 * @method \Zend\Mvc\Controller\Plugin\Url url(string $route = null, array $params = null)
 */
class MyClass
{
}

这使我们可以对识别为MyClass的任何变量使用方法url的类型提示:

This allows us to use have a type-hint for method url on any variable recognized as MyClass:

/* @var $a \MyClass */
$a->// typehint!

您需要一个这样的伪"类,然后使用以下命令启动视图脚本:

You need such a "fake" class and then start your view scripts with:

/* @var $this \MyFakeClass */

这将为您提供视图脚本中$this上的类型提示. 理想情况下,您可以使用类似于 https://github.com/zendframework/zf2 发出拉取请求. https://github.com/zendframework/zf2/pull/3438">https://github.com/zendframework/zf2/pull/3438

That will give you type-hints on $this within your view script. You could ideally open a pull request against https://github.com/zendframework/zf2 with something similar to https://github.com/zendframework/zf2/pull/3438

这篇关于PhpStorm中的ZF2视图助手的自动补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆