bytic / http
Php Framework
2.0.7
2026-04-06 19:20 UTC
Requires
- php: ^8.0
- bytic/logger: ^1.0|^2.0
- bytic/request-detective: ^1.0
- bytic/utility: ^1.0
- nyholm/psr7: ^1.3
- oscarotero/middleland: ^1.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0|^2.0
- symfony/http-foundation: ^6.0|^7.0
- symfony/http-kernel: ^6.0|^7.0
Requires (Dev)
- ext-json: *
- bytic/application: ^1.0|^2.0
- bytic/config: ^1.0|^2.0
- bytic/container: ^1.0|^2.0
- bytic/debug: ^1.0|^2.0
- bytic/phpqatools: ^1.0
- bytic/router: ^1.0|^2.0
- filp/whoops: ^2.4
- mockery/mockery: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 2.0.7
- 2.0.6
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.x-dev
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- dev-copilot/create-symfony-compliant-repo
- dev-develop
This package is auto-updated.
Last update: 2026-10-25 18:17:17 UTC
README
ByTIC HTTP component - A Symfony-compliant HTTP kernel with PSR-7/PSR-15 middleware support
Features
- Symfony-compliant HTTP Kernel - Implements Symfony's HttpKernelInterface with full event dispatching
- PSR-7/PSR-15 Middleware Support - Backward compatible with existing PSR middleware
- Event-Driven Architecture - Dispatch kernel events (REQUEST, RESPONSE, EXCEPTION, TERMINATE)
- Request Stack Management - Track main and sub-requests like Symfony
- Controller Resolution - Symfony-style controller and argument resolvers
- Exception Handling - Flexible exception handling with event subscribers
- Fully Backward Compatible - Works with existing middleware-based code
Installation
composer require bytic/http
Usage
Basic Kernel Usage
use Nip\Http\Kernel\Kernel; use Nip\Application\Application; use Nip\Router\Router; use Symfony\Component\HttpFoundation\Request; // Create kernel $app = new Application(); $router = new Router(); $kernel = new Kernel($app, $router); // Handle request $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); // Terminate kernel $kernel->terminate($request, $response);
Event Subscribers (Symfony Way)
use Nip\Http\Kernel\Event\ResponseEvent; use Nip\Http\Kernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ResponseHeadersSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ KernelEvents::RESPONSE => ['onKernelResponse', 0], ]; } public function onKernelResponse(ResponseEvent $event): void { if (!$event->isMainRequest()) { return; } $response = $event->getResponse(); $response->headers->set('X-Powered-By', 'ByTIC HTTP Kernel'); } } // Register subscriber $kernel->getEventDispatcher()->addSubscriber(new ResponseHeadersSubscriber());
Available Kernel Events
KernelEvents::REQUEST- Dispatched at the start of request handlingKernelEvents::CONTROLLER- Dispatched before controller executionKernelEvents::RESPONSE- Dispatched before sending the responseKernelEvents::EXCEPTION- Dispatched when an exception occursKernelEvents::TERMINATE- Dispatched after response is sent
Middleware (Backward Compatible)
The kernel still supports PSR-15 middleware:
$kernel->pushMiddleware(MyMiddleware::class); $kernel->prependMiddleware(AnotherMiddleware::class);
Request Stack
Access the current request anywhere:
$currentRequest = $kernel->getRequestStack()->getCurrentRequest(); $mainRequest = $kernel->getRequestStack()->getMainRequest();
Migration from PSR-15 to Event Listeners
The new event system runs alongside the existing middleware, so you can migrate gradually:
Before (Middleware)
class MyMiddleware implements ServerMiddlewareInterface { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { // Modify request $request = $request->withAttribute('foo', 'bar'); // Get response $response = $handler->handle($request); // Modify response $response = $response->withHeader('X-Custom', 'value'); return $response; } }
After (Event Subscriber)
class MyEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['onRequest', 10], KernelEvents::RESPONSE => ['onResponse', 10], ]; } public function onRequest(RequestEvent $event): void { $request = $event->getRequest(); $request->attributes->set('foo', 'bar'); } public function onResponse(ResponseEvent $event): void { $response = $event->getResponse(); $response->headers->set('X-Custom', 'value'); } }
Architecture
This package follows Symfony's kernel architecture:
- Request Event - Early request processing, can short-circuit with a response
- Controller Resolution - Determine which controller to execute
- Middleware Stack - Execute PSR-15 middleware (backward compatible)
- Response Event - Modify the response before sending
- Terminate Event - Clean up after response is sent
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.