生成PHP接口 [英] Generate PHP Interfaces

查看:78
本文介绍了生成PHP接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有工具从现有类生成php接口?有一个像Netbeans自动getter / setter创建但是用于接口的工具会很好。

Is there a tool the generate php interface from existing classes? It would be nice to have a tool like Netbeans automatic getter/setter creation but for interfaces.

推荐答案

对于程序化用法,有< a href =https://github.com/gooh/InterfaceDistiller =nofollow> InterfaceDistiller 从这样的现有类派生接口:

For programmatic usage there is InterfaceDistiller that allows you to derive interfaces from existing classes like this:

$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界面:

It also has a CLI interface:

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的这种功能。


I'm not aware of any IDE that offers such functionality for php.

这篇关于生成PHP接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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