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にリクエストを送信する必要があります「ポン」で応答するはずです
GET http://localhost:3000/ping