lsr / request
Laser framework core - Requests.
Requires
- php: >= 8.4
- lsr/helpers: ^0.3
- lsr/interfaces: ^0.3.1
- lsr/object-validation: ^0.3.1
- nyholm/psr7: ^1.8
- nyholm/psr7-server: ^1.1
- psr/http-message: ^2
- symfony/property-access: ^8|^7
- symfony/serializer: ^8|^7
- zircote/swagger-php: ^6|^5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- lsr/serializer: ^0.3
- nette/di: ^3.2
- phpstan/phpstan: ^2
- phpunit/phpunit: ^12
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-08 12:22:05 UTC
README
lsr/request provides the Laser framework's PSR-7 request decorator, request/response/stream factories and request-to-object validation integration. Its namespace is Lsr\Core\Requests.
Requirements
- PHP
>= 8.4. - PSR HTTP Message
^2, Nyholm PSR-7^1.8and PSR-7 Server^1.1. - Symfony Serializer and PropertyAccess
^8|^7, Swagger PHP^6|^5, and LSR helpers, interfaces and object-validation packages. See composer.json for exact constraints. - No PHP extensions are declared directly; dependencies may impose additional platform requirements.
- Optional Nette DI integration requires
nette/di(listed inrequire-dev, not runtimerequire). The request validation mapper requiresLsr\Serializer\Mapperfromlsr/serializer; applications using that integration must provide it explicitly if it is not already installed.
Installation
composer require lsr/request
Wrapping a PSR-7 server request
require __DIR__ . '/vendor/autoload.php'; use Lsr\Core\Requests\Request; use Nyholm\Psr7\ServerRequest; $psrRequest = (new ServerRequest('GET', 'https://example.com/users')) ->withQueryParams(['page' => '2']); $request = new Request($psrRequest); echo $request->getQueryParams()['page']; // 2
Request delegates the PSR-7 message API to the wrapped request and adds route parameters, path segments, notices and previous-request state. Its constructor wraps the request as supplied; it does not decode a JSON body.
For incoming HTTP requests, inject a RequestFactory configured with a Symfony Serializer and a JSON decoder. getHttpRequest() builds from PHP globals; fromPsrRequest() wraps an existing server request and decodes bodies whose content type is application/json into the parsed body. Invalid JSON raises an LSR DispatchBreakException carrying a bad-request response, so the application must configure the exception's response factory and handle that dispatch mechanism.
Framework integration
Lsr\Core\Requests\DI\RequestExtension registers request, response and stream factories in Nette DI and configures the response factory used by DispatchBreakException. It accepts replacement requestFactory, responseFactory and streamFactory class names, checked against their PSR factory interfaces. The application must supply the Symfony serializer service used by the default factories.
RequestValidationMapper takes an Lsr\Serializer\Mapper. Call setRequest() before mapBodyToObject() or mapQueryToObject(); these methods denormalize into the requested class, apply object-validation attributes and invoke the object's validate() method when present. Handle serializer errors and Lsr\ObjectValidation\Exceptions\ValidationException (including multiple validation errors) at the application boundary. Mapping is not performed automatically by constructing a request.
Static-file helpers on Request use the application's ROOT constant. Configure that filesystem boundary before using them; it is not needed for the wrapping example above.
Development
GitHub Actions runs CS, PHPStan and PHPUnit on PHP 8.4 and 8.5. Run the same checks locally after installing development dependencies:
composer install --prefer-dist --no-interaction --no-progress composer cs vendor/bin/phpstan analyse --no-progress vendor/bin/phpunit --no-coverage
See phpstan.neon and phpunit.xml. The mapping tests use the lsr/serializer development dependency; no external services or coverage driver are required in CI. composer test remains available for coverage runs with a compatible driver.
Run composer cs to check PHP coding style and composer cs:fix (or composer cbf) to apply fixes with PHP CS Fixer. The rules and source paths are defined in .php-cs-fixer.php.
AI coding assistance
See LSR Skills for AI agent skills for working with the LSR framework.
License
Licensed under the MIT License.