hamlet-framework / http-message
Hamlet Framework / HTTP / Request
Installs: 22 659
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7 || ^8
- psr/http-factory: ^1
- psr/http-message: ^1
Requires (Dev)
- hamlet-framework/http-message-spec: @stable
- php-parallel-lint/php-parallel-lint: @stable
- phpunit/phpunit: ^6 || ^7 || ^8 || ^9
- squizlabs/php_codesniffer: @stable
- symfony/polyfill-mbstring: <=1.20.0
- vimeo/psalm: @stable
Provides
This package is auto-updated.
Last update: 2024-10-29 05:22:44 UTC
README
PSR-7 and PSR-17 implementation.
This library generally provides you with three ways of creating objects.
Step-wise adjustments
The standard approach is to create an object through a series of adjustments.
$message = Message::empty() ->withProtocolVersion('1.1') ->withHeader('Host', 'example.net');
Note, that all with*
methods are validating and in the example above we're creating 2 intermediate objects along the way.
Validating builders
We can avoid creating multiple objects by using a validating builder
$message = Message::validatingBuilder() ->withProtocolVersion('1.1') ->withBody($body) ->withHeaders($headers) ->build();
It offers the same level of validation as the previous method.
Non-validating builders
When creating messages within you application's secure boundaries, there is a way to avoid redundant argument validation by using non-validating builders
$message = Message::nonValidatingBuilder() ->withProtocolVersion('1.1') ->withBody($body) ->withHeaders($headers) ->build();
When in doubt use validating builders.
Outstanding tasks
- Adapt tests from https://github.com/Sporkmonger/Addressable/blob/master/spec/addressable/uri_spec.rb
- Expand test coverage