bakame/http-structured-fields

Structured Field Values for HTTP manipulation in PHP

0.5.0 2022-05-13 20:15 UTC

This package is auto-updated.

Last update: 2022-09-20 14:35:23 UTC


README

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

The package uses value objects to parse, serialize and build HTTP Structured Fields in PHP.

HTTP Structured fields are intended for use by specifications of new HTTP fields that wish to use a common syntax that is more restrictive than traditional HTTP field values or could be used to retrofit current headers to have them compliant with the new syntax.

The package can be used to:

  • parse and serialize HTTP Structured Fields
  • build or update HTTP Structured Fields in a predicable way;
use Bakame\Http\StructuredFields;

$field = StructuredFields\Item::from("/terms", ['rel' => 'copyright', 'anchor' => '#foo']);
echo $field->toHttpValue();              // display "/terms";rel="copyright";anchor="#foo"
echo $field->value();                    // display "/terms"
echo $field->parameters()['rel']->value(); // display "copyright"

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

or download the library and:

  • use any other PSR-4 compatible autoloader.
  • use the bundle autoloader script as shown below:
require 'path/to/http-structured-fields/repo/autoload.php';

use Bakame\Http\StructuredFields;

$list = StructuredFields\OrderedList::fromHttpValue('"/member/*/author", "/member/*/comments"');
echo $list[-1]->value(); // returns '/member/*/comments'

Documentation

Full documentation can be found in the docs.

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.