Skip to content

ReactorX is a simple PHP framework, built on top of ReactPHP, which provides flexibility for configuration and architecture

License

Notifications You must be signed in to change notification settings

Jester0027/ReactorX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏗️ Work in progress


Installation

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();

Ping request example

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

About

ReactorX is a simple PHP framework, built on top of ReactPHP, which provides flexibility for configuration and architecture

Topics

Resources

License

Stars

Watchers

Forks

Languages