使用服务定位器为PHP Storm提供更快,更好,更有效的类型提示 [英] Faster, better, and more efficient type hinting for PHP Storm with service locators

查看:70
本文介绍了使用服务定位器为PHP Storm提供更快,更好,更有效的类型提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月来,我一直在寻找一种实现此目的的方法.我是喜欢自动完成的开发人员之一.对于zend Framework 2中的每个Service Locator调用,我键入以下内容:

I have been looking for a way to do this for months. I am one of those developers that loves autocompletion. For every Service Locator call in zend framework 2 I type hint with the following:

/** @var \Module\Service\SuperService $superService */ 
$superService => $this->getServiceLocator()>get('\Module\Service\SuperService');
$superService->coolFunction();

这有效,但是当您在单个Controller中开始获得2-4服务时,代码可能会变得混乱.我正在尝试找到一种更好的方法来使用PHP Storm并为服务定位器调用键入提示

This works, but the code can get messy when you start getting 2-4 Services in a single Controller. I am trying to find a better way to use PHP Storm and type hinting for service locator calls

推荐答案

虽然这现在对您无济于事,但您知道我们即将开箱即用,但有一些附带条件,这对您很有用: /p>

While this doesn't help you now, it's useful for you to know that we are close to supporting this out of the box, with a few provisos:

  1. 容器需要实现ZF2的ServiceManager已经完成的Container Interop项目的Container\Interop\ContainerInterface.

您需要使用::class super-global-hyper-magic-contant命名和检索您的类.就您而言,只需将get调用中的字符串替换为Module\Service\SuperService::class(可用于PHP 5.4及更高版本).

You need to use the ::class super-global-hyper-magic-contant to name and retrieve your classes. In your case, simply replace the string in your get call with Module\Service\SuperService::class (available from PHP 5.4 and above).

我希望此功能将在我们的下一个版本PhpStorm 2016.2中提供,该版本将于夏季前后发布.

I'm expecting this functionality to be available in our next release, PhpStorm 2016.2 which is due around the summer.

加里

这篇关于使用服务定位器为PHP Storm提供更快,更好,更有效的类型提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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