ReactorX
1.0.0
تثبيت المشروع مع الملحن
composer require reactorx/reactorx:dev-masterقم بإنشاء ملف إدخال ، وتكوين وبدء الخادم
<?php
use ReactorX HttpKernel ;
use ReactorX HttpKernelConfiguration ;
// Don't forget the autoloader
require_once __DIR__ . ' /vendor/autoload.php ' ;
$ config = new HttpKernelConfiguration (
// Scan the classes in the "./src" directory
projectDir: __DIR__ . " /src "
);
// Create the server and pass it the configuration
$ server = HttpKernel:: createServer ( $ config );
$ server -> run (); في أي مكان في دليل src ، قم بإنشاء فئة PingController.php .
ستقوم عملية بدء التشغيل تلقائيًا بالتقاط الفئة وتسجيلها في حاوية DI كوحدة تحكم.
<?php
use ReactorX Attributes { Controller , HttpGet };
use React Http Message Response ;
#[Controller]
final class PingController
{
#[HttpGet( " ping " )]
public final function ping (): Response
{
return new Response (
200 ,
[ ' Content-Type ' => ' text/plain ' ],
" pong "
);
}
} الآن إرسال طلب إلى /ping يجب أن يستجيب بـ "Pong"
GET http://localhost:3000/ping