定制 php-pico/http-link 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固