PHP code example of jacksonsr45 / radiante-php

1. Go to this page and download the library: Download jacksonsr45/radiante-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jacksonsr45 / radiante-php example snippets




use Jacksonsr45\RadiantPHP\ServerRequestFactory;



$pathToRoute = __DIR__ . '/routes.php';

$request = ServerRequestFactory::createServerRequest($pathToRoute);
$response = ServerRequestFactory::handleRequest($request);

ServerRequestFactory::sendHttpResponse($response);



use Jacksonsr45\RadiantPHP\ServerRequestFactory;

ry::build();

$pathToRoute = __DIR__ . '/routes.php';
$request = ServerRequestFactory::createServerRequest($pathToRoute, $container);
$response = ServerRequestFactory::handleRequest($request);
ServerRequestFactory::sendHttpResponse($response);



use Jacksonsr45\RadiantPHP\Http\Route;

Route::get('/user', [UserController::class, 'list']);



use Jacksonsr45\RadiantPHP\Http\Route;

Route::get('/user/<int:id>', [UserController::class, 'show']);



use Jacksonsr45\RadiantPHP\Http\Route;

Route::post('/user', [UserController::class, 'create']);



use Jacksonsr45\RadiantPHP\Http\Route;

Route::delete('/user/<int:id>', [UserController::class, 'delete']);



use Jacksonsr45\RadiantPHP\Http\Route;

Route::put('/user', [UserController::class, 'update']);

$container->set(ResponseInterface::class, create(Response::class));

use Jacksonsr45\RadiantPHP\Http\Message\Interfaces\ResponseInterface;

class UserController
{
    public function __construct(
        private readonly ResponseInterface $response
    ) {}

    public function index(): ResponseInterface
    {
        return $response->withStatus(200)->write('Hello World!');
    }
}
bash
composer