bakame/http-structured-fields

Structured Field Values for HTTP manipulation in PHP

1.3.0 2024-01-04 23:05 UTC

This package is auto-updated.

Last update: 2024-11-13 19:30:49 UTC


README

Author Software License Build Latest Version Total Downloads Sponsor development of this project

bakame/http-structured-fields is a framework-agnostic PHP library that allows you to parse, serialize create, update and validate HTTP Structured Fields in PHP according to the RFC9651.

Once installed you will be able to do the following:

use Bakame\Http\StructuredFields\OuterList;

//1 - parsing an Accept Header
$fieldValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
$field = OuterList::fromRfc9651($fieldValue);
$field[1]->value()->toString(); // returns 'application/xhtml+xml'
$field[1]->parameterByKey(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined

System Requirements

PHP >= 8.1 is required but the latest stable version of PHP is recommended.

Installation

Use composer:

composer require bakame/http-structured-fields

Documentation

Warning

The documentation for v2 is still not fully finished. Please refers to version 1.x for the most recent and stable documentation.

The documentation for v2 is a work in progress you can read here

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CODE OF CONDUCT for details.

Testing

The library:

To run the tests, run the following command from the project folder.

composer test

Security

If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.

Credits

Attribution

The package internal parser is heavily inspired by previous work done by Gapple on Structured Field Values for PHP.

License

The MIT License (MIT). Please see License File for more information.