Skip to content

Commit 2aaa252

Browse files
committed
1.0.0 release
* Add badges to README.md * Switch README from .rst to .md format * Update dependencies * Add commmand to handler call
1 parent 77be930 commit 2aaa252

7 files changed

+152
-142
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.idea
2-
.DS_STORE
31
build/
42
phpunit.xml
53
composer.lock

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 1.1.0 - 2016-11-24
4+
5+
* Add badges to README.md
6+
* Switch README from .rst to .md format
7+
* Update dependencies
8+
* Add command to handler call to provide support for GuzzleServices
9+
310
## 0.9.0 - 2016-01-30
411

512
* Updated to use Guzzle 6 and PSR-7.

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ test:
66
coverage:
77
vendor/bin/phpunit --coverage-html=build/artifacts/coverage
88

9+
coverage-clover:
10+
vendor/bin/phpunit --coverage-clover=build/artifacts/coverage.xml
11+
912
coverage-show:
1013
open build/artifacts/coverage/index.html
1114

README.md

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Guzzle Commands
2+
3+
[![License](https://poser.pugx.org/guzzlehttp/command/license)](https://packagist.org/packages/guzzlehttp/command)
4+
[![Build Status](https://travis-ci.org/guzzle/command.svg?branch=master)](https://travis-ci.org/guzzle/command)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/guzzle/command/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/guzzle/command/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/guzzle/command/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/guzzle/command/?branch=master)
7+
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/7a93338e-50cd-42f7-9299-17c44d92148f/mini.png)](https://insight.sensiolabs.com/projects/7a93338e-50cd-42f7-9299-17c44d92148f)
8+
[![Latest Stable Version](https://poser.pugx.org/guzzlehttp/command/v/stable)](https://packagist.org/packages/guzzlehttp/command)
9+
[![Latest Unstable Version](https://poser.pugx.org/guzzlehttp/command/v/unstable)](https://packagist.org/packages/guzzlehttp/command)
10+
[![Total Downloads](https://poser.pugx.org/guzzlehttp/command/downloads)](https://packagist.org/packages/guzzlehttp/command)
11+
12+
This library uses Guzzle (``guzzlehttp/guzzle``, version 6.x) and provides the
13+
foundations to create fully-featured web service clients by abstracting Guzzle
14+
HTTP **requests** and **responses** into higher-level **commands** and
15+
**results**. A **middleware** system, analogous to — but separate from — the one
16+
in the HTTP layer may be used to customize client behavior when preparing
17+
commands into requests and processing responses into results.
18+
19+
### Commands
20+
21+
Key-value pair objects representing an operation of a web service. Commands have a name and a set of parameters.
22+
23+
### Results
24+
25+
Key-value pair objects representing the processed result of executing an operation of a web service.
26+
27+
## Installing
28+
29+
This project can be installed using Composer:
30+
31+
``composer require guzzlehttp/command``
32+
33+
For **Guzzle 5**, use ``composer require guzzlehttp/command:0.8.*``. The source
34+
code for the Guzzle 5 version is available on the
35+
`0.8 branch <https://github.com/guzzle/command/tree/0.8>`_.
36+
37+
**Note:** If Composer is not
38+
`installed globally <https://getcomposer.org/doc/00-intro.md#globally>`_,
39+
then you may need to run the preceding Composer commands using
40+
``php composer.phar`` (where ``composer.phar`` is the path to your copy of
41+
Composer), instead of just ``composer``.
42+
43+
## Service Clients
44+
45+
Service Clients are web service clients that implement the
46+
``GuzzleHttp\Command\ServiceClientInterface`` and use an underlying Guzzle HTTP
47+
client (``GuzzleHttp\Client``) to communicate with the service. Service clients
48+
create and execute **commands** (``GuzzleHttp\Command\CommandInterface``),
49+
which encapsulate operations within the web service, including the operation
50+
name and parameters. This library provides a generic implementation of a service
51+
client: the ``GuzzleHttp\Command\ServiceClient`` class.
52+
53+
## Instantiating a Service Client
54+
55+
@TODO Add documentation
56+
57+
* ``ServiceClient``'s constructor
58+
* Transformer functions (``$commandToRequestTransformer`` and ``$responseToResultTransformer``)
59+
* The ``HandlerStack``
60+
61+
## Executing Commands
62+
63+
Service clients create command objects using the ``getCommand()`` method.
64+
65+
```php
66+
$commandName = 'foo';
67+
$arguments = ['baz' => 'bar'];
68+
$command = $client->getCommand($commandName, $arguments);
69+
70+
```
71+
72+
After creating a command, you may execute the command using the ``execute()``
73+
method of the client.
74+
75+
```php
76+
$result = $client->execute($command);
77+
```
78+
79+
The result of executing a command will be a ``GuzzleHttp\Command\ResultInterface``
80+
object. Result objects are ``ArrayAccess``-ible and contain the data parsed from
81+
HTTP response.
82+
83+
Service clients have magic methods that act as shortcuts to executing commands
84+
by name without having to create the ``Command`` object in a separate step
85+
before executing it.
86+
87+
```php
88+
$result = $client->foo(['baz' => 'bar']);
89+
```
90+
91+
## Asynchronous Commands
92+
93+
@TODO Add documentation
94+
95+
* ``-Async`` suffix for client methods
96+
* Promises
97+
98+
```php
99+
// Create and execute an asynchronous command.
100+
$command = $command = $client->getCommand('foo', ['baz' => 'bar']);
101+
$promise = $client->executeAsync($command);
102+
103+
// Use asynchronous commands with magic methods.
104+
$promise = $client->fooAsync(['baz' => 'bar']);
105+
```
106+
107+
@TODO Add documentation
108+
109+
* ``wait()``-ing on promises.
110+
111+
```php
112+
$result = $promise->wait();
113+
114+
echo $result['fizz']; //> 'buzz'
115+
```
116+
117+
## Concurrent Requests
118+
119+
@TODO Add documentation
120+
121+
* ``executeAll()``
122+
* ``executeAllAsync()``.
123+
* Options (``fulfilled``, ``rejected``, ``concurrency``)
124+
125+
## Middleware: Extending the Client
126+
127+
Middleware can be added to the service client or underlying HTTP client to
128+
implement additional behavior and customize the ``Command``-to-``Result`` and
129+
``Request``-to-``Response`` lifecycles, respectively.
130+
131+
## Todo
132+
133+
* Middleware system and command vs request layers
134+
* The ``HandlerStack``

README.rst

-135
This file was deleted.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php": ">=5.5.0",
19-
"guzzlehttp/guzzle": "^6.1.1",
20-
"guzzlehttp/promises": "~1.0",
19+
"guzzlehttp/guzzle": "^6.2",
20+
"guzzlehttp/promises": "~1.3",
2121
"guzzlehttp/psr7": "~1.0"
2222
},
2323
"require-dev": {

src/ServiceClient.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private function createCommandHandler()
174174

175175
// Create a result from the response.
176176
$response = (yield $promise);
177-
yield $this->transformResponseToResult($response, $request);
177+
yield $this->transformResponseToResult($response, $request, $command);
178178
} catch (\Exception $e) {
179179
throw CommandException::fromPrevious($command, $e);
180180
}
@@ -195,20 +195,23 @@ private function transformCommandToRequest(CommandInterface $command)
195195
return $transform($command);
196196
}
197197

198+
198199
/**
199200
* Transforms a Response object, also using data from the Request object,
200201
* into a Result object.
201202
*
202203
* @param ResponseInterface $response
203204
* @param RequestInterface $request
205+
* @param CommandInterface $command
204206
* @return ResultInterface
205207
*/
206208
private function transformResponseToResult(
207209
ResponseInterface $response,
208-
RequestInterface $request
210+
RequestInterface $request,
211+
CommandInterface $command
209212
) {
210213
$transform = $this->responseToResultTransformer;
211214

212-
return $transform($response, $request);
215+
return $transform($response, $request, $command);
213216
}
214217
}

0 commit comments

Comments
 (0)