nexphant/framework
The application layer. Wraps the persistent runtime into a usable HTTP, WebSocket, and SSE application framework with routing, attributes, and middleware pipelines.
Install
composer require nexphant/frameworkApp Bootstrap
Nexphant\App serves as the entry point class. Under the hood, it instantiates the central Nexphant\Application.
use Nexphant\App;
$app = App::create([
'base_path' => getcwd(),
'workers' => 4,
]);
$app->get('/', fn () => ['status' => 'ok']);
$app->listen(port: 8080);App::create(array $config = []) accepts boot-time configuration for paths, workers, runtime profiles, event loop/socket backends, runtime safety, metrics, database query behavior, optimization, and server limits. See App Reference for the parameter list.
Routing & Middleware
You can define standard HTTP routes, assign middleware, and group routes under prefixes:
// Standard HTTP route
$app->get('/health', fn () => ['ok' => true]);
// Route with route-specific middleware
$app->post('/users', function ($request) {
return ['created' => true];
}, new AuthMiddleware());
// Route groups
$app->group('/api/v1', function ($app) {
$app->get('/users', fn () => ['users' => []]);
$app->get('/posts', fn () => ['posts' => []]);
}, new ApiRateLimitMiddleware());
// Register global middleware
$app->use(new SecurityHeadersMiddleware());WebSockets & SSE
nexphant/framework provides built-in support for persistent connections (WebSockets and Server-Sent Events):
// WebSocket Route
$app->ws('/chat',
onMessage: function ($conn, $message) {
$conn->send("Received: " . $message);
},
onOpen: function ($conn) {
// connection opened
},
onClose: function ($conn) {
// connection closed
}
);
// Server-Sent Events Route
$app->sse('/events');
// Broadcast to SSE clients from anywhere in the application
$app->broadcastSse('/events', ['alert' => 'new-notification'], event: 'alert');Attribute-based Routing
Controllers can register their routes using attributes:
use Nexphant\Get;
use Nexphant\Post;
class UserController
{
#[Get('/users')]
public function index()
{
return ['users' => []];
}
}
// Register controller annotations
$app->annotations(UserController::class);Runtime Tuning & Configuration
Tune process counts, event loop backends, and supervisors directly via the Application instance:
$app->workers(4)
->supervisor(true)
->runtimeMode('throughput')
->eventLoop('event')
->socketDriver('native')
->maxAcceptPerTick(32)
->tune(['keep_alive_timeout' => 30])
->static(base_path('public'));Telemetry Endpoints
Expose server telemetry and runtime performance metrics endpoints automatically:
// Exposes /api/live, /api/ready, /api/health, and /api/metrics.
$app->runtime('/api');Fast Responses
For static hot endpoints, register direct fast responses:
$app->fastJson('GET', '/health', ['status' => 'ok']);
$app->fastText('GET', '/robots.txt', "User-agent: *\nAllow: /\n");
$app->fastRaw('GET', '/raw', $rawHttpResponse);Fast responses are skipped for parameterized paths and are best for fixed health checks, metadata, and small static payloads.
