php-pico/http-link

A PSR-13 compliant HTTP Hypermedia Link package.

Maintainers

Package info

github.com/php-pico/http-link

pkg:composer/php-pico/http-link

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-07-07 08:57 UTC

This package is auto-updated.

Last update: 2026-07-07 09:00:23 UTC


README

A PSR-13 compliant HTTP Hypermedia Link package.

Implements psr/link: Link implements LinkInterface and EvolvableLinkInterface; LinkProvider implements LinkProviderInterface and EvolvableLinkProviderInterface. Both classes are immutable — every with*/without* method returns a new instance.

This package only represents links as PHP objects (data + metadata). It does not render them — turning a Link/LinkProvider into a Link HTTP header, HTML <link> tag, or HAL/JSON:API payload is out of scope and left to your application or a separate serialization library.

Requirements

  • PHP ^8.5

Installation

composer require php-pico/http-link

Usage

Link

use PhpPico\Http\Link\Link;

$link = new Link(
    href: '/api/users/{id}',
    rels: ['next'],
    attributes: ['type' => 'application/json'],
);

$link->getHref();       // '/api/users/{id}'
$link->isTemplated();   // true (href contains '{')
$link->getRels();       // ['next']
$link->getAttributes(); // ['type' => 'application/json']

// Evolvable methods return new instances
$link = $link->withRel('prev');
$link = $link->withoutRel('next');
$link = $link->withAttribute('hreflang', 'en');
$link = $link->withoutAttribute('type');
$link = $link->withHref('/api/users/42');

LinkProvider

use PhpPico\Http\Link\Link;
use PhpPico\Http\Link\LinkProvider;

$provider = new LinkProvider([
    new Link('/api/users', ['self']),
    new Link('/api/users/{id}', ['item']),
]);

$provider->getLinks();             // iterable<LinkInterface>
$provider->getLinksByRel('item');  // iterable<LinkInterface> matching the rel

// Evolvable methods return new instances
$provider = $provider->withLink(new Link('/api/users?page=2', ['next']));
$provider = $provider->withoutLink($link);

Development

composer install

composer test   # run the test suite (PHPUnit)
composer mago   # static analysis (Mago)
composer format # format code (Mago)
composer qa     # format, analyze, and test

License

MIT