webservco / http-request-service
A PHP component/library. Helpers for reading the method, body, headers, Accept list and route parts of a request.
v2.3.0
2026-10-11 16:34 UTC
Requires
- php: ^8.4
- fig/http-message-util: ^1
- psr/http-message: ^2
- webservco/data: ^2
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^6
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^3
- phpstan/phpstan: ^2
- phpstan/phpstan-deprecation-rules: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^13
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^4
- vimeo/psalm: ^6
- webservco/coding-standards: ^2
- webservco/component-common: ^2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
Helpers for reading the method, body, headers, Accept list and route parts of a request.
- Related:
webservco/dependency-container(getRequestServiceContainer()),webservco/middleware(sets the route parts read here)
Installation
composer require webservco/http-request-service
Usage
Get the services from the container instead of creating them one by one.
// \WebServCo\Http\Contract\Message\Request\Container\RequestServiceContainerInterface $requestServiceContainer = $applicationDependencyContainer->getRequestServiceContainer(); // Route /example/test/foo: part 1 is "example", part 3 is "foo", missing parts are null. $id = $requestServiceContainer->getServerRequestAttributeService()->getRoutePart(3, $request); $contentType = $requestServiceContainer->getRequestHeaderService()->getHeaderValue('Content-Type', $request); $hasBody = $requestServiceContainer->getRequestBodyService()->canHaveRequestBody($request);
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\Message\Request\Container\RequestServiceContainerInterface |
Container\Message\Request\RequestServiceContainer |
Access to all the services below. |
Contract\Message\Request\Server\ServerRequestAttributeServiceInterface |
Service\Message\Request\Server\ServerRequestAttributeService |
getRoutePart() from the routePart.N request attributes. |
Contract\Message\Request\Server\ServerHeadersAcceptServiceInterface |
Service\Message\Request\Server\ServerHeadersAcceptService |
Reads the Accept header, sorts it by quality and drops types with q=0. |
Contract\Message\Request\RequestHeaderServiceInterface |
Service\Message\Request\RequestHeaderService |
First value of a header. Throws an UnexpectedValueException if the header is missing. |
Contract\Message\Request\RequestBodyServiceInterface |
Service\Message\Request\RequestBodyService |
Whether the method allows a body. |
Contract\Message\Request\Method\RequestMethodServiceInterface |
Service\Message\Request\Method\RequestMethodService |
Validates the HTTP method. |
Namespaces are relative to WebServCo\Http\.
Development
# Start project. ddev start # Install dependencies. ddev c u # Run all validations. ddev c c # Run unit tests. ddev c test:dox