php-pico/http-link
Composer 安装命令:
composer require php-pico/http-link
包简介
A PSR-13 compliant HTTP Hypermedia Link package.
README 文档
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-07