milpa / http-symfony
Symfony HttpFoundation adapter for the Milpa PHP framework: the HTTP response value objects and the base controller a host's routing invokes.
Requires
- php: >=8.3
- milpa/core: >=0.6.2 <1.0
- psr/log: ^3.0
- symfony/http-foundation: ^7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.65
- phpstan/phpdoc-parser: ^2.3
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Milpa HTTP Symfony
The Symfony HttpFoundation adapter for the Milpa PHP framework — the response value objects and the base controller a host's routing invokes.
milpa/http describes routes and handlers without committing to any HTTP implementation. This
package is one implementation of the other half: what a controller returns, for a host that
speaks Symfony's HttpFoundation.
It is deliberately small. A host resolves a route to a controller method, calls it with an
HttpFoundation Request, and gets back an HttpResponse. That is the whole contract.
Install
composer require milpa/http-symfony
What lives here
| Class | Responsibility |
|---|---|
HttpResponse |
The response a controller returns — a Symfony Response with the framework's own type, so a host can tell "a Milpa controller answered" from "something else did". |
BlobResponse |
A binary/file response with the download headers already set. |
BaseController |
What a controller extends: the container, plus the shorthands for the answers controllers actually give — json(), cleanResponse(), redirect(), download(). |
Quick example
use Milpa\Http\HttpMethod; use Milpa\Http\Routing\Route; use Milpa\Http\Symfony\BaseController; use Milpa\Http\Symfony\HttpResponse; use Symfony\Component\HttpFoundation\Request; final class HealthController extends BaseController { #[Route(path: '/health', methods: HttpMethod::GET, name: 'health')] public function show(Request $request, array $params = []): HttpResponse { return $this->json(['status' => 'ok']); } }
The #[Route] attribute and HttpMethod in that example come from
milpa/http, which this package does not require —
see Requirements. A host that routes with it already has it; the controller base
class and the responses below work the same without it.
What is NOT here, and why
View rendering. A responder that turns a template into a response needs a template engine, and
that engine is not published yet. Shipping the class anyway would put code in your vendor/ that
cannot run — a package that can only fail is worse than one that is missing a feature. It lives
host-side until the engine earns its own release.
PSR-7. This is the HttpFoundation adapter. A host that speaks PSR-7 end to end does not need it:
milpa/runtime's kernel and milpa/http's router are already PSR-7 native.
Requirements
- PHP ≥ 8.3
symfony/http-foundation^7.4milpa/core>=0.6.2 <1.0psr/log^3.0
milpa/http is not one of them, and that is the point of the split. This package is the other
half of the sentence, not a layer on top of it: the router describes where a request goes, these
classes are what the controller hands back, and no line here implements, extends or imports any
contract of milpa/http — its interfaces (RouterInterface, HandlerResolverInterface,
MiddlewareResolverInterface, UrlGeneratorInterface) are PSR-7/PSR-15 seams a host kernel fills,
and it declares nothing at all about responses. A host that routes with milpa/http requires it
directly; a host that routes some other way pays nothing for it here.
Contributing
Contributions are welcome — see CONTRIBUTING.md. Please report security issues via SECURITY.md, and note that this project follows a Code of Conduct.
License
Apache-2.0 © Rodrigo Vicente - TeamX Agency.
Milpa is designed, built, and maintained by Rodrigo Vicente - TeamX Agency.