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 ();أتمنى أن تجدكم هذه المكتبة مفيدة.
يرجى مشاركتها وتعطيني ردود الفعل :)
توماس