From 1c4233bb5985990b93cb65774f338acd121319d4 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Wed, 1 Aug 2018 11:48:38 -0400 Subject: [PATCH] Update readme --- README.md | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 28e6ab4..b206e93 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,170 @@ -# http-factory +# PSR-17 HTTP Factory library [![Build Status](https://travis-ci.org/bulldogcreative/http-factory.svg?branch=master)](https://travis-ci.org/bulldogcreative/http-factory) -## install +This library aims to provide a simple implementation of PSR-17 (HTTP Factories). +It current supports Guzzle/Psr7 and Zend Diactoros. Installation and usage +examples are below, but if you have any questions or issues, please +create an issue. + +## Installation ```bash composer require bulldog/http-factory ``` + +## Usage + +You can use the [FactoryBuilder](src/FactoryBuilder.php) class to create the +HTTP Factory of your choice, or you can instantiate them directly. Currently +your choices are `guzzle` and `zend`. Each factory implements +[HttpFactoryInterface](src/Interfaces/HttpFactoryInterface.php). Since this +library uses PSR-17 all of the individual factories returned will implement +their corresponding PSR-17 interface. For more detailed usage, please see +the [tests](tests/) folder. + +### FactoryBuilder + +```php +requestFactory(); +$r = $requestFactory->createRequest('GET', 'http://localhost'); +``` + +#### Guzzle + +You'll notice the only difference between the example above and the one below +is we specify `guzzle` as the parameter to the `get` method. + +```php +requestFactory(); +$r = $requestFactory->createRequest('GET', 'http://localhost'); +``` + +#### Without FactoryBuilder + +You don't have to use `FactoryBuilder` to get an HTTP Factory. See below. + +```php +requestFactory(); +$r = $requestFactory->createRequest('GET', 'http://localhost'); +``` + +### ResponseFactory + +In the rest of the examples, I'll only show one example using `zend` with the `FactoryBuilder`. + +```php +responseFactory(); +$r = $responseFactory->createResponse(200, 'OK'); +``` + +### ServerRequestFactory + +```php +serverRequestFactory(); +$params = ['name' => 'value']; +$r = $reqFactory->createServerRequest('GET', '/', $params); +``` + +### StreamFactory + +```php +streamFactory(); +$params = ['name' => 'value']; +$r = $factory->createStream('php://memory'); +``` + +### UploadedFileFactory + +```php +streamFactory(); +$resource = $streamFactory->createStream('php://temp'); + +$factory = $httpFactory->uploadedFileFactory(); +$params = ['name' => 'value']; +$r = $factory->createUploadedFile( + $resource, + 1, + \UPLOAD_ERR_OK, + 'filename.txt', + 'txt' +); +``` + +### UriFactory + +```php +uriFactory(); +$r = $factory->createUri('/'); +``` + +## Links + +* [guzzle/psr7](https://github.com/guzzle/psr7) +* [zendframework/zend-diactoros](https://github.com/zendframework/zend-diactoros)