krak/http-message

Psr7 Http 消息工具类

v0.1.3 2017-04-27 14:41 UTC

This package is auto-updated.

Last update: 2024-09-18 17:37:46 UTC


README

psr http 消息(psr7)规范的工具类。

头部

我们提供了解析特殊头部的几个工具类。

每个头部类都按照特定的 HTTP 头部命名,并具有以下解析和签名的功能。

以下是一个使用 AcceptHeader 类的示例

<?php

use Krak\HttpMessage;

// grab from a psr http message
$accept_header = HttpMessage\AcceptHeader::fromHttpMessage($psr_req);
// parse from a string
$accept_header = HttpMessage\AcceptHeader::fromString('text/*;q=0.1,text/html;q=0.2');

// You can then sign an http message with the header, which will write the value of the header into the req.
$req = $accept_header->signHttpMessage($req);

// You can also export the header as a string
echo $accept_header;

我们以下列类提供抽象

  • Krak\HttpMessage\AuthorizationHeader
  • Krak\HttpMessage\AcceptHeader
  • Krak\HttpMessage\ContentTypeHeader

匹配器

Krak\HttpMessage\Match 目录包含用于创建 HTTP 消息请求匹配器的功能工具。