lmc / http-constants
HTTP Header Fields Constants
Installs: 241 893
Dependents: 8
Suggesters: 0
Security: 0
Stars: 25
Watchers: 7
Forks: 1
Open Issues: 2
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
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.