Coder Social home page Coder Social logo

jester0027 / reactorx Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 25 KB

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

Home Page: https://packagist.org/packages/reactorx/reactorx

License: MIT License

PHP 100.00%
php php-framework php8 reactphp

reactorx's Introduction

๐Ÿ—๏ธ 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

reactorx's People

Contributors

jester0027 avatar

Stargazers

Loรฏc Melebeck avatar JL avatar

Watchers

 avatar

reactorx's Issues

feat(controller): Parse route parameters from the `Route` attribute path

test cases:

  • for /api/v1/posts/{id}

    • โŒ /
    • โŒ /api/v1/posts
    • โœ… /api/v1/posts/hello
    • โœ… /api/v1/posts/123456
    • โŒ /api/v1/posts/123456/archive
  • for /api/v1/posts/{id}/archive

    • โŒ /
    • โŒ /api/v1/posts
    • โŒ /api/v1/posts/hello
    • โŒ /api/v1/posts/123456
    • โœ… /api/v1/posts/123456/archive
    • โœ… /api/v1/posts/hello/archive

feat(di-container): Implement `Configuration` components

Configuration classes are components instantiated at application startup and are responsible configuring or defining other components or services (as a factory method) within the application.
For instance, if the framework has multiple implementations of the same interface, the developer can choose which implementation to use, or provide its own.
It could also be used to register external libraries classes in the service container.

Example use case:

<?php

namespace Jester0027\Examples\Configuration;

use Jester0027\Examples\Services\FakeCrudService;
use Jester0027\Examples\Services\SomeService;
use Jester0027\Examples\Services\SomeServiceInterface;
use Jester0027\Phuck\Attributes\Component;
use Jester0027\Phuck\Attributes\Configuration;

/**
 * This class is instantiated once during startup and is used for configuration.<br>
 * Other dependencies can be injected since it is part of the service container
 */
#[Configuration]
final class ApplicationConfig
{
    /**
     * This method registers the <code>SomeServiceInterface<code> in the service container with the return value of the method as the implementation.<br><br>
     *
     * The service is then injected by the return type of the configuration method as shown below:
     * <code>
     * class OtherService
     * {
     *     public function __construct(private SomeServiceInterface someService)
     *     {
     *     }
     *
     *     public function returnStuff(): string
     *     {
     *         return $this->someService->doStuff();
     *     }
     * }
     * </code>
     */
    #[Component]
    public function configureSomeService(): SomeServiceInterface
    {
        return new SomeService();
    }
}

feat(controller): Create attributes for the http request

Attributes to implement

FromBody

Deserializes the request body and injects it as a method parameter

File

Parses a file or array of files as a method parameter

FromHeader(string? $name)

Injects the header value as a method parameter

FromQuery(string? $name)

Injects the query parameter value as a method parameter

FromRoute(string? $name)

Injects the route parameter value from the uri as a method parameter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.