PHPMagicAnnotations
Release 0.8.3
PHP tidak memiliki anotasi asli (alias atribut dari .NET World) jadi jika Anda ingin menerapkan kerangka kerja anotasi Anda sendiri, pikirkan untuk menggunakan ini terlebih dahulu dan hemat waktu.
Menggunakan komposer cukup sederhana, cukup jalankan perintah berikut:
$ composer require thomas-squall/php-magic-annotations
Pertama, Anda harus membuat kelas baru. Dalam contoh ini kelas akan disebut mycustomannotation
class MyCustomAnnotation
{
}Maka Anda harus memperpanjang kelas anotasi dari perpustakaan
use PHPAnnotations Annotations Annotation ;
class MyCustomAnnotation extends Annotation
{
}Tambahkan beberapa logika ke dalamnya
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 " ;
}
}Sekarang anotasi indah kami siap untuk pergi!
Buat kelas untuk digunakan untuk menguji anotasi
class MyTestClass
{
}Dan tambahkan anotasi melalui dokumen
/**
* @MyCustom(name = "Thomas", surname = "Cocchiara")
**/
class MyTestClass
{
}Sekarang kami siap mengujinya!
use use PHPAnnotations Reflection Reflector ;
$ myObject = new MyTestClass ();
$ reflector = new Reflector ( $ myObject );
echo $ reflector -> getClass ()-> getAnnotation ( " MyCustom " )-> GetFullName ();Semoga kalian menemukan perpustakaan ini bermanfaat.
Tolong bagikan dan beri saya umpan balik :)
Thomas