ReactorX is a simple PHP framework, built on top of ReactPHP, which provides flexibility for configuration and architecture
MIT License
Install the project with composer
composer require reactorx/reactorx:dev-master
Create an entry file, configure and start the server
<?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();
Anywhere in the src
directory, create a PingController.php
class.
The startup process will automatically pick up the class and register it in the DI container as a controller.
<?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"
);
}
}
Now sending a request to /ping
should respond with "pong"
GET http://localhost:3000/ping