Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Update docs (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Jun 2, 2017
1 parent 3aa2239 commit 279ff67
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,18 +18,18 @@ file or json response.

## Installation

```sh
```bash
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
Expand All @@ -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)
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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()`

0 comments on commit 279ff67

Please sign in to comment.