Conia Core
Note
This library is under active development, some of its features are still experimental and subject to change. Large parts of the documentation are missing.
A lightweight web framework which utilizes PSR components.
Basic usage
use Conia\Core\App;
use Conia\Core\Factory;
use Conia\Core\Factory\Guzzle;
use Conia\Core\Request;
use Conia\Core\Response;
use Conia\Route\After;
$factory = new Guzzle();
$afterHandler = new class ($factory) implements After {
public function __construct(protected Factory $factory)
{
}
public function handle(mixed $data): mixed
{
return Response::create($this->factory)->body($data);
}
public function replace(After $handler): bool
{
return false;
}
};
$app = App::create($factory);
$app->get('/{param}', function (string $param) {
return $param;
})->after($afterHandler);
$app->get('/', function (Request $request, Factory $factory) {
$response = $factory->response();
$response->getBody()->write($request->origin());
return $response;
});
$response = $app->run(
$factory->serverRequest()->withUri(
$factory->uri('https://example.org/')
)
);
assert((string)$response->getBody() === 'https://example.org');
$response = $app->run(
$factory->serverRequest()->withUri(
$factory->uri('https://example.com/test-string')
)
);
assert((string)$response->getBody() === 'test-string');