bakame / http-structured-fields
Structured Field Values for HTTP manipulation in PHP
Fund package maintenance!
nyamsprod
Requires
- php: ^8.1
- ext-json: *
Requires (Dev)
- bakame/aide-base32: dev-main
- friendsofphp/php-cs-fixer: ^v3.45.0
- httpwg/structured-field-tests: *@dev
- phpbench/phpbench: ^1.2.15
- phpstan/phpstan: ^1.10.50
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-phpunit: ^1.3.15
- phpstan/phpstan-strict-rules: ^1.5.2
- phpunit/phpunit: ^10.5.5
- symfony/var-dumper: ^6.4.0
README
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'; $container = OuterList::fromRfc9651($fieldValue); $container[1]->value()->toString(); // returns 'application/xhtml+xml' $container[1]->parameterByName(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
- The documentation for version 2.x for the upcoming v2 release
- The documentation for version 1.x for the current stable version.
Contributing
Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CODE OF CONDUCT for details.
Testing
The library:
- has a PHPUnit test suite
- has a coding style compliance test suite using PHP CS Fixer.
- has a code analysis compliance test suite using PHPStan.
- is compliant with the language agnostic HTTP Structured Fields Test suite.
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.