首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >生成PHP接口

问生成PHP接口
EN

Stack Overflow用户
提问于 2011-11-24 02:47:36
回答 2查看 1.6K关注 0票数 7

有没有从现有类生成php接口的工具?如果能有一个像Netbeans这样的工具自动创建getter/setter接口,那就太好了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-24 02:52:19

对于编程用法,有一个允许您从现有的类派生接口,如下所示:

代码语言:javascript
复制
$distiller = new InterfaceDistiller;
$distiller
    ->methodsWithModifiers(\ReflectionMethod::IS_PUBLIC)
    ->extendInterfaceFrom('Iterator, SeekableIterator')
    ->excludeImplementedMethods()
    ->excludeInheritedMethods()
    ->excludeMagicMethods()
    ->excludeOldStyleConstructors()
    ->filterMethodsByPattern('(^get)')
    ->saveAs(new SplFileObject('MyInterface.php'))
    ->distill('SomeFoo', 'MyInterface');

它还具有CLI接口:

代码语言:javascript
复制
Usage: phpdistill [options] <classname> <interfacename>

  --bootstrap                           Path to File containing your bootstrap and autoloader

  --methodsWithModifiers <number>       A ReflectionMethod Visibility BitMask. Defaults to Public.
  --extendInterfaceFrom  <name,...>     Comma-separated list of Interfaces to extend.
  --excludeImplementedMethods           Will exclude all implemented methods.
  --excludeInheritedMethods             Will exclude all inherited methods.
  --excludeMagicMethods                 Will exclude all magic methods.
  --excludeOldStyleConstructors         Will exclude Legacy Constructors.
  --filterMethodsByPattern <pattern>    Only include methods matching PCRE pattern.
  --saveAs                              Filename to save new Interface to. STDOUT if omitted.

我不知道有任何IDE为php提供了这样的功能。

票数 15
EN

Stack Overflow用户

发布于 2014-06-11 08:02:14

目前PHPStorm 8可以做到这一点,也许以前的版本也是如此。

步骤:

  1. 将光标放在类名上,然后选择: Refactor
  2. -> ->
  3. Fill the options

done。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8247482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档