From 279ff67be5b3bd0229326a917c3e262c644b98d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Fri, 2 Jun 2017 11:18:25 +0100 Subject: [PATCH] Update docs (#20) --- CONTRIBUTING.md | 16 ++++++++++++++++ README.md | 43 +++++++++++++++++++++++++++---------------- UPGRADE.md | 8 ++++++++ 3 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 UPGRADE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..facd379 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,16 @@ +## Contributing + +Set up: + +* Clone the project +* `composer install && composer bin all install` + +The project provides a `Makefile` in which the most common commands have been +registered such as fixing the coding style or running the test. + +```bash +make +# or +make help +=> will print the list of available commands +``` diff --git a/README.md b/README.md index f704bed..2729e83 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # humbug_get_contents -[![Build Status](https://travis-ci.org/humbug/file_get_contents.svg)](https://travis-ci.org/humbug/file_get_contents) +[![Package version](https://img.shields.io/packagist/v/padraic/humbug_get_contents.svg?style=flat-square)](https://packagist.org/packages/padraic/humbug_get_contents) +[![Build Status](https://img.shields.io/travis/humbug/file_get_contents.svg?branch=master&style=flat-square)](https://travis-ci.org/humbug/file_get_contents?branch=master) +[![Slack](https://img.shields.io/badge/slack-%23humbug-red.svg?style=flat-square)](https://symfony.com/slack-invite) +[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat-square)](LICENSE) -Defines a `humbug_get_contents()` function that will transparently call `file_get_contents()`, +Defines a `Humbug\get_contents()` function that will transparently call `file_get_contents()`, except for HTTPS URIs where it will inject a context configured to enable secure -SSL/TLS requests on all versions of PHP less than 5.6. +SSL/TLS requests on all versions of PHP 5.3+. All versions of PHP below 5.6 not only disable SSL/TLS protections by default, but have most other default options set insecurely. This has led to @@ -15,7 +18,7 @@ file or json response. ## Installation -```sh +```bash composer require padraic/humbug_get_contents ``` @@ -23,10 +26,10 @@ composer require padraic/humbug_get_contents ## Usage ```php -$content = humbug_get_contents('https://www.howsmyssl.com/a/check'); +$content = Humbug\get_contents('https://www.howsmyssl.com/a/check'); ``` -You can use this function as an immediate alternative to file_get_contents() in any code +You can use this function as an immediate alternative to `file_get_contents()` in any code location where HTTP requests are probable. This solution was originally implemented within the Composer Installer, so this is a @@ -51,22 +54,30 @@ here as a convenience. If your needs are going to extend this, you should use a more complete solution and double check that it fully enables and supports TLS. ```php -/** - * Don't end headers with \r\n when setting via array - */ -humbug_set_headers(array( +// Don't end headers with \r\n when setting via array +Humbug\set_headers([ 'Accept-Language: da', - 'User-Agent: Humbug' -)); -$response = humbug_get_contents('http://www.example.com'); + 'User-Agent: Humbug', +]); + +$response = Humbug\get_contents('http://www.example.com'); ``` Request headers are emptied when used, so you would need to reset on each -`humbug_get_contents()` call. +`Humbug\get_contents()` call. To retrieve an array of the last response headers: ```php -$response = humbug_get_contents('http://www.example.com'); -$headers = humbug_get_headers(); +$response = Humbug\get_contents('http://www.example.com'); +$headers = Humbug\get_headers(); ``` + +## Upgrade + +[Upgrade Guide](UPGRADE.md) + + +## Contributing + +[Contribution Guide](CONTRIBUTING.md) diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..eaf52b2 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,8 @@ +## Upgrade from 1.x to 2.x + +The functions previously registered in the global namespace have been +moved to the `Humbug` namespace: + +* `humbug_get_contents()` => `Humbug\get_contents()` +* `humbug_set_headers()` => `Humbug\set_headers()` +* `humbug_get_headers()` => `Humbug\get_headers()`