6
有没有一个工具从现有的类生成PHP接口?有一个类似Netbeans的自动getter/setter创建工具,但是用于接口会很好。生成PHP接口
有没有一个工具从现有的类生成PHP接口?有一个类似Netbeans的自动getter/setter创建工具,但是用于接口会很好。生成PHP接口
对于编程使用有InterfaceDistiller
,使您可以从现有的类派生这样的接口:
$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界面:
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.
我不是意识到任何为php提供这种功能的IDE。
你在说什么?接口的Getters/Setter没有任何意义,因为接口不能具有属性。你应该澄清你的问题 – KingCrunch
@KingCrunch'很高兴有一个像Netbeans自动获取/设置器创建的工具'Netbeans提供了一个“从类属性特性中自动生成getter和setter,他希望类似于接口。”从类“ – edorian
啊,我明白了,可能edorian已经给出了答案,但通常(按照“按合同设计”),你应该总是先接口并根据它们的签名创建类(只是想提一下) – KingCrunch