lmc / http-constants
HTTP头部字段常量
1.2.0
2020-09-01 11:14 UTC
Requires
- php: ^7.2 || ^8.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.8
- lmc/coding-standard: ^2.0.3
- php-parallel-lint/php-parallel-lint: ^1.2
- phpunit/phpunit: ^8.1 || ^9.0
README
缺少PHP常量定义,用于您的HTTP请求和响应的头部字段。
停止在代码中重复字符串标识符和放置HTTP头部的错别字!
当使用纯PHP、Guzzle、Symfony HttpFoundation、Zend HTTP、Zend Diactoros等进行头部交互时可以使用。
包含所有约200个在IANA列表(包括永久和临时)中定义的头部常量,以及基于维基百科列表的一些常用非标准头部。
安装
$ composer require lmc/http-constants
注意,您需要安装Composer才能完成此操作。
使用方法
<?php namespace My; use Lmc\HttpConstants\Header; class Example { public function exampleWithGuzzle() { $client = new \GuzzleHttp\Client(); $response = $client->request( 'GET', 'https://api.foo/bar', ['headers' => [Header::ACCEPT_ENCODING => 'gzip']] ); echo $response->getHeaderLine(Header::CONTENT_TYPE); } public function exampleWithSymfonyHttpFoundation() { $response = new \Symfony\Component\HttpFoundation\Response(); $response->headers->set(Header::ACCESS_CONTROL_ALLOW_ORIGIN, 'www.jobs.cz'); } public function exampleWithPurePhp() { header(Header::CONTENT_TYPE . ': application/pdf'); header(Header::CACHE_CONTROL . ': no-cache, must-revalidate'); } }
变更日志
查看最新的更改,请参阅CHANGELOG.md文件。我们遵循语义版本控制。
许可证
该库是开源软件,许可协议为MIT许可证。