翻译进度
4
分块数量
2
参与人数

PSR-13 超媒体链接 - 说明文档

这是一篇协同翻译的文章,你可以点击『我来翻译』按钮来参与翻译。

链接定义元文档

1. 总结

HTML 和各种 API 格式的上下文中,超媒体链接已经变成 Web 越来越重要的一部分。然而遗憾的是,没有一种通用单一的超媒体格式,也没有一种通用的方式来表示链接间的格式。

该规范旨在为 PHP 开发人员提供一种简单的、通用的方式来表示一个独立于所使用的序列化格式的超媒体链接。 这反过来又允许系统将超媒体链接的响应序列化为一种或多种有线格式,而不依赖于决定这些链接应该是什么的过程。

imajinyun 翻译于 1个月前

2. 范围

2.1 目标

  • 本规范旨在提取和标准化不同格式之间的超媒体链接表示。

2.2 非目标

  • 本规范不寻求去标准化或偏爱任何特定超媒体序列化的格式

3. 设计决策

为什么没有增加方法

本规范的主要目标之一是 PSR-7 响应对象。设计的响应对象必须是不可变的。其他 value-object 的实现可能也需要一个不可变的接口。

此外,一些链接提供者对象可能不是值对象,而是一个给定域中的其它对象,这个对象能够动态生成链接,可能是在数据库结果或其他底层表示之外。在这些情况下,与可写的提供者定义是不兼容的。

imajinyun 翻译于 1个月前

Therefore, this specification splits accessor methods and evolvable methods into separate interfaces, allowing objects to implement just the read-only or evolvable versions as appropriate to their use case.

Why is rel on a Link object multi-value?

Different hypermedia standards handle multiple links with the same relationship differently. Some have a single link that has multiple rel's defined. Others have a single rel entry that then contains multiple links.

Defining each Link uniquely but allowing it to have multiple rels provides a most-compatible-denominator definition. A single LinkInterface object may be serialized to one or more link entries in a given hypermedia format, as appropriate. However, specifying multiple link objects each with a single rel yet the same URI is also legal, and a hypermedia format can serialize that as appropriate, too.

Why is a LinkProviderInterface needed?

In many contexts, a set of links will be attached to some other object. Those objects may be used in situations where all that is relevant is their links, or some subset of their links. For example, various different value objects may be defined that represent different REST formats such as HAL, JSON-LD, or Atom. It may be useful to extract those links from such an object uniformly for further processing. For instance, next/previous links may be extracted from an object and added to a PSR-7 Response object as Link headers. Alternatively, many links would make sense to represent with a "preload" link relationship, which would indicate to an HTTP 2-compatible web server that the linked resources should be streamed to a client in anticipation of a subsequent request.

All of those cases are independent of the payload or encoding of the object. By providing a common interface to access such links, we enable generic handling of the links themselves regardless of the value object or domain object that is producing them.

4. People

4.1 Editor(s)

  • Larry Garfield

4.2 Sponsors

  • Matthew Weier O'Phinney (coordinator)
  • Marc Alexander

4.3 Contributors

  • Evert Pot

5. Votes

6. Relevant links

本文章首发在 Laravel China 社区
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。

参与译者:2
讨论数量: 0
发起讨论


暂无话题~