1. Go to this page and download the library: Download dvictorjhg/braidphp 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/ */
dvictorjhg / braidphp example snippets
declare(strict_types=1);
p;
use dvictorjhg\braidphp\Core\Attributes\Module;
use dvictorjhg\braidphp\Router\Attributes\Get;
use dvictorjhg\braidphp\Router\Attributes\Route;
use dvictorjhg\braidphp\Router\Http\Request;
use dvictorjhg\braidphp\Router\HttpModule;
final class Greeter
{
public function greeting(string $name): string
{
return "Hello $name!";
}
}
#[Route(path: '/api')]
final class GreetingController
{
public function __construct(private Greeter $greeter)
{
}
#[Get('/hello/:name', pathMatch: 'full')]
public function hello(Request $request): string
{
return $this->greeter->greeting($request->getRouteParam('name') ?? '');
}
}
#[Module(
imports: [HttpModule::class],
providers: [Greeter::class],
controllers: [GreetingController::class],
)]
final class AppModule
{
}
$app = new App();
$app->bootstrapModule(new AppModule());
$app->listen(address: '0.0.0.0', port: '8000');