Componere
Componere
Componere(라틴어로 "compose", 즉 조합하다)는 **운영 환경(production)**을 겨냥한 확장이에요. 클래스의 조합(composition), 몽키 패칭(monkey patching), 캐스팅(casting)을 위한 API를 제공합니다. 이 페이지에서는 Componere가 제공하는 핵심 기능들을 개괄해요.
출처: Componere
본문
Componere는 클래스 조합, 몽키 패칭, 캐스팅이라는 세 가지 큰 축으로 나눌 수 있어요.
조합(Composition): Componere\Definition을 사용하면 런타임에 클래스를 정의(또는 재정의)할 수 있습니다. 그 뒤 클래스를 등록할 수 있고, 재정의의 경우에는 Componere\Definition이 존재하는 한 원래 클래스를 대체해요. 생성자는 다음과 같은 시그니처들을 받습니다.
public function Componere\Definition::__construct ( string $name )
public function Componere\Definition::__construct ( string $name , string $parent )
public function Componere\Definition::__construct ( string $name , array $interfaces )
public function Componere\Definition::__construct ( string $name , string $parent , array $interfaces )
패칭(Patching): Componere\Patch는 특정 객체 인스턴스의 클래스를 런타임에 바꾸는 데 사용해요. 패치를 적용하면 Componere\Patch가 존재하는 동안 적용 상태가 유지되고, 명시적으로 되돌릴(revert) 수도 있습니다.
public function Componere\Patch::__construct ( object $instance )
public function Componere\Patch::__construct ( object $instance , array $interfaces )
캐스팅(Casting): Componere의 캐스팅 함수는 사용자 정의 호환 타입 간에 캐스팅을 수행합니다. 여기서 "호환(compatible)"이란 대상 타입이 객체 타입의 하위(sub) 또는 상위(super) 타입이라는 뜻이에요.
function Componere\cast ( string $type , object $object ): object
function Componere\cast_by_ref ( string $type , object $object ): object
Componere가 제공하는 클래스와 함수는 아래와 같아요.
- Componere\Abstract\Definition —
addInterface,addMethod,addTrait,getReflector - Componere\Definition —
__construct,addConstant,addProperty,register,isRegistered,getClosure,getClosures - Componere\Patch —
__construct,apply,revert,isApplied,derive,getClosure,getClosures - Componere\Method —
__construct,setPrivate,setProtected,setStatic,getReflector - Componere\Value —
__construct,setPrivate,setProtected,setStatic,isPrivate,isProtected,isStatic,hasDefault - Componere 함수 —
Componere\cast,Componere\cast_by_ref