PHPMagicAnnotations
Release 0.8.3
PHP에는 어떤 종류의 기본 주석이 없으므로 (.NET World의 일명 속성)가 없으므로 자신의 주석 프레임 워크를 구현하려면 먼저 사용하고 시간을 절약 할 수 있습니다.
작곡가를 사용하는 것은 매우 간단합니다. 다음 명령 만 실행합니다.
$ composer require thomas-squall/php-magic-annotations
먼저 새 클래스를 만들어야합니다. 이 예에서는 클래스를 mycustomannotation 이라고합니다
class MyCustomAnnotation
{
}그런 다음 라이브러리에서 주석 클래스를 연장해야합니다.
use PHPAnnotations Annotations Annotation ;
class MyCustomAnnotation extends Annotation
{
}그것에 논리를 추가하십시오
use PHPAnnotations Annotations Annotation ;
class MyCustomAnnotation extends Annotation
{
private $ name ;
private $ surname ;
public function __constructor ( $ name , $ surname )
{
$ this -> name = $ name ;
$ this -> surname = $ surname ;
}
public function GetFullName ()
{
return " $ this -> name $ this -> surname " ;
}
}이제 우리의 아름다운 주석이 갈 준비가되었습니다!
주석을 테스트하는 데 사용되는 클래스를 만듭니다
class MyTestClass
{
}문서를 통해 주석을 추가하십시오
/**
* @MyCustom(name = "Thomas", surname = "Cocchiara")
**/
class MyTestClass
{
}이제 우리는 그것을 테스트 할 준비가되었습니다!
use use PHPAnnotations Reflection Reflector ;
$ myObject = new MyTestClass ();
$ reflector = new Reflector ( $ myObject );
echo $ reflector -> getClass ()-> getAnnotation ( " MyCustom " )-> GetFullName ();이 라이브러리가 유용하다는 것을 알기를 바랍니다.
그것을 공유하고 나에게 피드백을주십시오 :)
도마