PHP code example of lmc / http-constants

1. Go to this page and download the library: Download lmc/http-constants library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lmc / http-constants example snippets




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');
    }
}