2011-11-23 3 views
6

기존 클래스의 PHP 인터페이스 생성 도구가 있습니까? Netbeans 자동 getter/setter 생성과 같은 도구가 있지만 인터페이스 용으로 좋을 것입니다. 프로그램 사용에 대한PHP 인터페이스 생성

+2

무슨 말씀 이세요? 인터페이스에 대한 Getters/Setters는 의미가 없지만 인터페이스에는 속성이 없어야합니다. 당신의 질문을 명확히해야합니다 – KingCrunch

+1

@KingCrunch 'Netbeans 자동 getter/setter 생성과 같은 도구를 가지고 있으면 좋겠다.'Netbeans는 "클래스 속성에서 getter 및 setter를 자동 생성합니다. 그는 인터페이스와 비슷한 것을 원합니다." " – edorian

+0

아마도 edorian은 이미 답을 줄지도 모릅니다.하지만 대개 ("디자인 별 계약"에 따라) 항상 인터페이스가 먼저 있어야하며 서명에 따라 클래스를 만들어야합니다. – KingCrunch

답변

15

은이 같은 기존 클래스에서 인터페이스를 도출 할 수 있습니다 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를 알고 있어야합니다.

3

현재 PHPStorm 8은 이전 버전 일 수도 있습니다.

단계 : 클래스 이름

  • 에 커서가 선택

    1. 장소 : 리팩터링 -> 추출 -> 인터페이스
    2. 는 옵션과 수행을 작성합니다.