Skip to content

hamlet-framework/http-message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hamlet / HTTP / Message

CI Status Packagist Packagist Coverage Status Psalm coverage

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

About

Hamlet Framework / HTTP / Message

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages