定制 lmc/http-constants 二次开发

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

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

lmc/http-constants

最新稳定版本:1.2.0

Composer 安装命令:

composer require lmc/http-constants

包简介

HTTP Header Fields Constants

README 文档

README

Latest Stable Version GitHub Actions Build Status Total Downloads

The missing PHP constants definition for header fields of your HTTP requests and responses.

Stop repeating string identifiers and placing typos of HTTP headers in your code!

Could be used when interacting with headers using pure PHP, Guzzle, Symfony HttpFoundation, Zend HTTP, Zend Diactoros etc.

Contains all ~200 constants for headers defined in IANA list (both Permanent and Provisional) and some common non-standard headers based on Wikipedia list.

Install

$ composer require lmc/http-constants

Note you will need to have Composer installed to do this.

Usage

<?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

For latest changes see CHANGELOG.md file. We follow Semantic Versioning.

License

The library is open source software licensed under the MIT license.

统计信息

  • 总下载量: 316.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 1
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

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