1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-03-14 19:29:49 +01:00

Updating to use RingPHP and s/adapter/handle/g

This commit is contained in:
Michael Dowling 2014-10-12 18:27:08 -07:00
parent eb78bc1af1
commit 2c2f1d7c47
24 changed files with 165 additions and 163 deletions

View File

@ -1,10 +1,10 @@
all: clean coverage docs
start-server:
cd vendor/guzzlehttp/ring && make start-server
cd vendor/guzzlehttp/ringphp && make start-server
stop-server:
cd vendor/guzzlehttp/ring && make stop-server
cd vendor/guzzlehttp/ringphp && make stop-server
test: start-server
vendor/bin/phpunit
@ -47,4 +47,4 @@ burgomaster:
mkdir -p build/artifacts
curl -s https://raw.githubusercontent.com/mtdowling/Burgomaster/0.0.1/src/Burgomaster.php > build/artifacts/Burgomaster.php
.PHONY: doc burgomaster
.PHONY: docs burgomaster

View File

@ -14,9 +14,7 @@
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/ring": "~1.0@dev",
"guzzlehttp/streams": "~3.0",
"react/promise": "~2.0"
"guzzlehttp/ringphp": "~1.0"
},
"require-dev": {
"ext-curl": "*",

View File

@ -1,43 +0,0 @@
=============
Ring Adapters
=============
Guzzle uses Guzzle-Ring adapters to send HTTP requests over the wire.
Guzzle-Ring provides a low-level library that can be used to "glue" Guzzle with
any transport method you choose. By default, Guzzle utilizes cURL and PHP's
stream wrappers to send HTTP requests.
Guzzle-Ring adapters makes it extremely simple to integrate Guzzle with any
HTTP transport. For example, you could quite easily bridge Guzzle and React
to use Guzzle in React's event loop.
Using an Adapter
----------------
You can change the adapter used by a client using the `adapter` option in the
``GuzzleHttp\Client`` constructor.
.. code-block:: php
use GuzzleHttp\Client;
use GuzzleHttp\Ring\Client\MockAdapter;
// Create a mock adapter that always returns a 200 response.
$adapter = new MockAdapter(['status' => 200]);
// Configure to client to use the mock adapter.
$client = new Client(['adapter' => $adapter]);
At its core, adapters are simply PHP callables that accept a request array
and return a ``GuzzleHttp\Ring\Future\FutureArrayInterface``. This future array
can be used just like a normal PHP array, causing it to block, or you can use
the promise interface using the ``then()`` method of the future. Guzzle hooks
up to the Guzzle-Ring project using a very simple bridge class
(``GuzzleHttp\RingBridge``).
Creating an Adapter
-------------------
See the `Guzzle-Ring <http://guzzle-ring.readthedocs.org>`_ project
documentation for more information on creating custom adapters that can be
used with Guzzle clients.

View File

@ -3,7 +3,7 @@ Clients
=======
Clients are used to create requests, create transactions, send requests
through an HTTP adapter, and return a response. You can add default request
through an HTTP handler, and return a response. You can add default request
options to a client that are applied to every request (e.g., default headers,
default query string parameters, etc.), and you can add event listeners and
subscribers to every request created by a client.
@ -29,10 +29,10 @@ base_url
`Absolute URLs <http://tools.ietf.org/html/rfc3986#section-4.3>`_ sent
through a client will not use the base URL of the client.
adapter
Configures the `Guzzle-Ring adapter <http://guzzle-ring.readthedocs.org>`_
handler
Configures the `RingPHP handler <http://ringphp.readthedocs.org>`_
used to transfer the HTTP requests of a client. Guzzle will, by default,
utilize a stacked adapter that chooses the best adapter to use based on the
utilize a stacked handlers that chooses the best handler to use based on the
provided request options and based on the extensions available in the
environment.
@ -140,7 +140,7 @@ Asynchronous Requests
---------------------
You can send asynchronous requests by setting the ``future`` request option
to ``true`` (or a string that your adapter understands). This creates a
to ``true`` (or a string that your handler understands). This creates a
``GuzzleHttp\Message\FutureResponse`` object that has not yet completed. Once
you have a future response, you can use a promise object obtained by calling
the ``then`` method of the response to take an action when the response has
@ -587,14 +587,14 @@ basic
digest
Use `digest authentication <http://www.ietf.org/rfc/rfc2069.txt>`_ (must be
supported by the HTTP adapter).
supported by the HTTP handler).
.. code-block:: php
$client->get('/get', ['auth' => ['username', 'password', 'digest']]);
*This is currently only supported when using the cURL adapter, but creating
a replacement that can be used with any HTTP adapter is planned.*
*This is currently only supported when using the cURL handler, but creating
a replacement that can be used with any HTTP handler is planned.*
.. important::
@ -653,7 +653,7 @@ Adapter Specific Authentication Schemes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you need to use authentication methods provided by cURL (e.g., NTLM, GSS,
etc.), then you need to specify a curl adapter option in the ``options``
etc.), then you need to specify a curl handler option in the ``options``
request option array. See :ref:`config-option` for more information.
.. _cookies-option:
@ -754,7 +754,7 @@ handled. By default, ``decode_content`` is set to true, meaning any gzipped
or deflated response will be decoded by Guzzle.
When set to ``false``, the body of a response is never decoded, meaning the
bytes pass through the adapter unchanged.
bytes pass through the handler unchanged.
.. code-block:: php
@ -927,9 +927,9 @@ connect_timeout
.. note::
This setting must be supported by the HTTP adapter used to send a request.
This setting must be supported by the HTTP handler used to send a request.
``connect_timeout`` is currently only supported by the built-in cURL
adapter.
handler.
.. _verify-option:
@ -1029,9 +1029,9 @@ ssl_key
.. note::
``ssl_key`` is implemented by HTTP adapters. This is currently only
supported by the cURL adapter, but might be supported by other third-part
adapters.
``ssl_key`` is implemented by HTTP handlers. This is currently only
supported by the cURL handler, but might be supported by other third-part
handlers.
.. _proxy-option:
@ -1074,7 +1074,7 @@ debug
-----
:Summary: Set to ``true`` or set to a PHP stream returned by ``fopen()`` to
enable debug output with the adapter used to send a request. For example,
enable debug output with the handler used to send a request. For example,
when using cURL to transfer requests, cURL's verbose of ``CURLOPT_VERBOSE``
will be emitted. When using the PHP stream wrapper, stream wrapper
notifications will be emitted. If set to true, the output is written to
@ -1129,10 +1129,10 @@ stream
.. note::
Streaming response support must be implemented by the HTTP adapter used by
a client. This option might not be supported by every HTTP adapter, but the
Streaming response support must be implemented by the HTTP handler used by
a client. This option might not be supported by every HTTP handler, but the
interface of the response object remains the same regardless of whether or
not it is supported by the adapter.
not it is supported by the handler.
.. _expect-option:
@ -1160,7 +1160,7 @@ the body of a request is greater than 1 MB and a request is using HTTP/1.1.
This option only takes effect when using HTTP/1.1. The HTTP/1.0 and
HTTP/2.0 protocols do not support the "Expect: 100-Continue" header.
Support for handling the "Expect: 100-Continue" workflow must be
implemented by Guzzle HTTP adapters used by a client.
implemented by Guzzle HTTP handlers used by a client.
.. _version-option:
@ -1185,7 +1185,7 @@ config
:Summary: Associative array of config options that are forwarded to a request's
configuration collection. These values are used as configuration options
that can be consumed by plugins and adapters.
that can be consumed by plugins and handlers.
:Types: array
:Default: None
@ -1195,7 +1195,7 @@ config
echo $request->getConfig('foo');
// 'bar'
Some HTTP adapters allow you to specify custom adapter-specific settings. For
Some HTTP handlers allow you to specify custom handler-specific settings. For
example, you can pass custom cURL options to requests by passing an associative
array in the ``config`` request option under the ``curl`` key.
@ -1225,13 +1225,13 @@ future
By default, Guzzle requests should be synchronous. You can create asynchronous
future responses by passing the ``future`` request option as ``true``. The
response will only be executed when it is used like a normal response, the
``wait()`` method of the response is called, or the corresponding adapter that
``wait()`` method of the response is called, or the corresponding handler that
created the response is destructing and there are futures that have not been
resolved.
.. important::
This option only has an effect if your adapter can create and return future
This option only has an effect if your handler can create and return future
responses. However, even if a response is completed synchronously, Guzzle
will ensure that a FutureResponse object is returned for API consistency.
@ -1278,7 +1278,7 @@ Guzzle exposes a few environment variables that can be used to customize the
behavior of the library.
``GUZZLE_CURL_SELECT_TIMEOUT``
Controls the duration in seconds that a curl_multi_* adapter will use when
Controls the duration in seconds that a curl_multi_* handler will use when
selecting on curl handles using ``curl_multi_select()``. Some systems
have issues with PHP's implementation of ``curl_multi_select()`` where
calling this function always results in waiting for the maximum duration of

View File

@ -17,12 +17,12 @@ around with cURL options, stream contexts, or sockets.
Guzzle allows you to send both asynchronous and synchronous requests using the
same interface and no direct dependency on an event loop. This flexibility
allows Guzzle to send an HTTP request using the most appropriate HTTP adapter
allows Guzzle to send an HTTP request using the most appropriate HTTP handler
based on the request being sent. For example, when sending synchronous
requests, Guzzle will by default send requests using cURL easy handles to
ensure you're using the fastest possible method for serially transferring HTTP
requests. When sending asynchronous requests, Guzzle might use cURL's multi
interface or any other asynchronous adapter you configure. When you request
interface or any other asynchronous handler you configure. When you request
streaming data, Guzzle will by default use PHP's stream wrapper.
**Streams**
@ -51,7 +51,7 @@ sent over the wire, and anything else you might need.
Another important aspect of Guzzle is that it's really
:doc:`easy to test clients <testing>`. You can mock HTTP responses and when
testing an adapter implementation, Guzzle provides a mock node.js web server.
testing an handler implementation, Guzzle provides a mock node.js web server.
**Ecosystem**
@ -70,10 +70,10 @@ an HTTP response into a more meaningful model object.
Does Guzzle require cURL?
=========================
No. Guzzle can use any HTTP adapter to send requests. This means that Guzzle
No. Guzzle can use any HTTP handler to send requests. This means that Guzzle
can be used with cURL, PHP's stream wrapper, sockets, and non-blocking libraries
like `React <http://reactphp.org/>`_. You just need to configure a
`Guzzle-Ring <http://guzzle-ring.readthedocs.org/en/latest/>`_ adapter to use a
`RingPHP <http://guzzle-ring.readthedocs.org/en/latest/>`_ handler to use a
different method of sending requests.
.. note::
@ -82,7 +82,7 @@ different method of sending requests.
an amazing HTTP client (arguably the best), and Guzzle will continue to use
it by default when it is available. It is rare, but some developers don't
have cURL installed on their systems or run into version specific issues.
By allowing swappable HTTP adapters, Guzzle is now much more customizable
By allowing swappable HTTP handlers, Guzzle is now much more customizable
and able to adapt to fit the needs of more developers.
Can Guzzle send asynchronous requests?
@ -115,7 +115,7 @@ How can I add custom cURL options?
==================================
cURL offer a huge number of `customizable options <http://us1.php.net/curl_setopt>`_.
While Guzzle normalizes many of these options across different adapters, there
While Guzzle normalizes many of these options across different handlers, there
are times when you need to set custom cURL options. This can be accomplished
by passing an associative array of cURL settings in the **curl** key of the
**config** request option.

43
docs/handlers.rst Normal file
View File

@ -0,0 +1,43 @@
================
RingPHP Handlers
================
Guzzle uses RingPHP handlers to send HTTP requests over the wire.
RingPHP provides a low-level library that can be used to "glue" Guzzle with
any transport method you choose. By default, Guzzle utilizes cURL and PHP's
stream wrappers to send HTTP requests.
RingPHP handlers makes it extremely simple to integrate Guzzle with any
HTTP transport. For example, you could quite easily bridge Guzzle and React
to use Guzzle in React's event loop.
Using a handler
---------------
You can change the handler used by a client using the ``handler`` option in the
``GuzzleHttp\Client`` constructor.
.. code-block:: php
use GuzzleHttp\Client;
use GuzzleHttp\Ring\Client\MockHandler;
// Create a mock handler that always returns a 200 response.
$handler = new MockHandler(['status' => 200]);
// Configure to client to use the mock handler.
$client = new Client(['handler' => $handler]);
At its core, handlers are simply PHP callables that accept a request array
and return a ``GuzzleHttp\Ring\Future\FutureArrayInterface``. This future array
can be used just like a normal PHP array, causing it to block, or you can use
the promise interface using the ``then()`` method of the future. Guzzle hooks
up to the RingPHP project using a very simple bridge class
(``GuzzleHttp\RingBridge``).
Creating a handler
------------------
See the `RingPHP <http://guzzle-ring.readthedocs.org>`_ project
documentation for more information on creating custom handlers that can be
used with Guzzle clients.

View File

@ -338,10 +338,10 @@ Request Config
--------------
Request messages contain a configuration collection that can be used by
event listeners and HTTP adapters to modify how a request behaves or is
event listeners and HTTP handlers to modify how a request behaves or is
transferred over the wire. For example, many of the request options that are
specified when creating a request are actually set as config options that are
only acted upon by adapters and listeners when the request is sent.
only acted upon by handlers and listeners when the request is sent.
You can get access to the request's config object using the ``getConfig()``
method of a request.
@ -371,9 +371,9 @@ access. You can also modify and remove values using array like access.
var_export($config['foo']);
// NULL
HTTP adapters and event listeners can expose additional customization options
HTTP handlers and event listeners can expose additional customization options
through request config settings. For example, in order to specify custom cURL
options to the cURL adapter, you need to specify an associative array in the
options to the cURL handler, you need to specify an associative array in the
``curl`` ``config`` request option.
.. code-block:: php
@ -387,7 +387,7 @@ options to the cURL adapter, you need to specify an associative array in the
]
]);
Consult the HTTP adapters and event listeners you are using to see if they
Consult the HTTP handlers and event listeners you are using to see if they
allow customization through request configuration options.
Event Emitter

View File

@ -12,7 +12,7 @@ trivial to integrate with web services.
files, and abstracts away the underlying HTTP transport layer.
- Can send both synchronous and asynchronous requests using the same interface
without requiring a dependency on a specific event loop.
- Pluggable HTTP adapters allows Guzzle to integrate with any method you choose
- Pluggable HTTP handlers allows Guzzle to integrate with any method you choose
for sending HTTP requests over the wire (e.g., cURL, sockets, PHP's stream
wrapper, non-blocking event loops like `React <http://reactphp.org/>`_, etc.).
- Guzzle makes it so that you no longer need to fool around with cURL options,
@ -50,7 +50,7 @@ User guide
http-messages
events
streams
adapters
handlers
testing
faq

View File

@ -6,16 +6,16 @@ Requirements
============
#. PHP 5.4.0
#. To use the PHP stream adapter, ``allow_url_fopen`` must be enabled in your
#. To use the PHP stream handler, ``allow_url_fopen`` must be enabled in your
system's php.ini.
#. To use the cURL adapter, you must have a recent version of cURL >= 7.16.2
#. To use the cURL handler, you must have a recent version of cURL >= 7.16.2
compiled with OpenSSL and zlib.
.. note::
Guzzle no longer requires cURL in order to send HTTP requests. Guzzle will
use the PHP stream wrapper to send HTTP requests if cURL is not installed.
Alternatively, you can provide your own HTTP adapter used to send requests.
Alternatively, you can provide your own HTTP handler used to send requests.
.. _installation:
@ -130,7 +130,7 @@ binary:
.. note::
You'll need to install node.js v0.5.0 or newer in order to perform
integration tests on Guzzle's HTTP adapters.
integration tests on Guzzle's HTTP handlers.
Reporting a security vulnerability
==================================

View File

@ -6,7 +6,7 @@ Guzzle provides several tools that will enable you to easily mock the HTTP
layer without needing to send requests over the internet.
* Mock subscriber
* Mock adapter
* Mock handler
* Node.js web server for integration testing
Mock Subscriber
@ -134,15 +134,15 @@ Mock Adapter
============
In addition to using the Mock subscriber, you can use the
``GuzzleHttp\Ring\Client\MockAdapter`` as the adapter of a client to return the
``GuzzleHttp\Ring\Client\MockAdapter`` as the handler of a client to return the
same response over and over or return the result of a callable function.
Test Web Server
===============
Using mock responses is almost always enough when testing a web service client.
When implementing custom :doc:`HTTP adapters <adapters>`, you'll need to send
actual HTTP requests in order to sufficiently test the adapter. However, a
When implementing custom :doc:`HTTP handlers <handlers>`, you'll need to send
actual HTTP requests in order to sufficiently test the handler. However, a
best practice is to contact a local web server rather than a server over the
internet.
@ -156,7 +156,7 @@ Using the test server
.. warning::
The following functionality is provided to help developers of Guzzle
develop HTTP adapters. There is no promise of backwards compatibility
develop HTTP handlers. There is no promise of backwards compatibility
when it comes to the node.js test server or the ``GuzzleHttp\Tests\Server``
class. If you are using the test server or ``Server`` class outside of
guzzlehttp/guzzle, then you will need to configure autoloading and
@ -165,7 +165,7 @@ Using the test server
.. hint::
You almost never need to use this test web server. You should only ever
consider using it when developing HTTP adapters. The test web server
consider using it when developing HTTP handlers. The test web server
is not necessary for mocking requests. For that, please use the
Mock subcribers and History subscriber.

View File

@ -7,9 +7,9 @@ use GuzzleHttp\Message\MessageFactoryInterface;
use GuzzleHttp\Message\RequestInterface;
use GuzzleHttp\Message\FutureResponse;
use GuzzleHttp\Ring\Client\Middleware;
use GuzzleHttp\Ring\Client\CurlMultiAdapter;
use GuzzleHttp\Ring\Client\CurlAdapter;
use GuzzleHttp\Ring\Client\StreamAdapter;
use GuzzleHttp\Ring\Client\CurlMultiHandler;
use GuzzleHttp\Ring\Client\CurlHandler;
use GuzzleHttp\Ring\Client\StreamHandler;
use GuzzleHttp\Ring\Core;
use GuzzleHttp\Ring\Future\FutureInterface;
use GuzzleHttp\Exception\RequestException;
@ -59,7 +59,7 @@ class Client implements ClientInterface
* Can be a string or an array that contains a URI template followed
* by an associative array of expansion variables to inject into the
* URI template.
* - adapter: callable adapter used to transfer requests
* - handler: callable RingPHP handler used to transfer requests
* - message_factory: Factory used to create request and response object
* - defaults: Default request options to apply to each request
* - emitter: Event emitter used for request events
@ -84,19 +84,23 @@ class Client implements ClientInterface
if (isset($config['fsm'])) {
$this->fsm = $config['fsm'];
} else {
$this->fsm = new RequestFsm(
isset($config['adapter']) ? $config['adapter'] : self::getDefaultAdapter(),
$this->messageFactory
);
if (isset($config['handler'])) {
$handler = $config['handler'];
} elseif (isset($config['Handler'])) {
$handler = $config['Handler'];
} else {
$handler = static::getDefaultHandler();
}
$this->fsm = new RequestFsm($handler, $this->messageFactory);
}
}
/**
* Create a default adapter to use based on the environment
* Create a default handler to use based on the environment
*
* @throws \RuntimeException if no viable adapter is available.
* @throws \RuntimeException if no viable Handler is available.
*/
public static function getDefaultAdapter()
public static function getDefaultHandler()
{
$default = $future = $streaming = null;
@ -107,19 +111,19 @@ class Client implements ClientInterface
if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) {
$config['max_handles'] = $maxHandles;
}
$future = new CurlMultiAdapter($config);
$future = new CurlMultiHandler($config);
if (function_exists('curl_reset')) {
$default = new CurlAdapter();
$default = new CurlHandler();
}
}
if (ini_get('allow_url_fopen')) {
$streaming = new StreamAdapter();
$streaming = new StreamHandler();
}
if (!($default = ($default ?: $future) ?: $streaming)) {
throw new \RuntimeException('Guzzle requires cURL, the '
. 'allow_url_fopen ini setting, or a custom HTTP adapter.');
. 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
$handler = $default;

View File

@ -112,7 +112,7 @@ interface ClientInterface extends HasEmitterInterface
* @param RequestInterface $request Request to send
*
* @return \GuzzleHttp\Message\ResponseInterface
* @throws \LogicException When the adapter does not populate a response
* @throws \LogicException When the handler does not populate a response
* @throws RequestException When an error is encountered
*/
public function send(RequestInterface $request);

View File

@ -21,9 +21,9 @@ class AbstractRetryableEvent extends AbstractTransferEvent
*
* @param int $afterDelay If specified, the amount of time in milliseconds
* to delay before retrying. Note that this must
* be supported by the underlying Guzzle-Ring
* adapter to work properly. Set to 0 or provide no
* value to retry immediately.
* be supported by the underlying RingPHP handler
* to work properly. Set to 0 or provide no value
* to retry immediately.
*/
public function retry($afterDelay = 0)
{

View File

@ -54,7 +54,7 @@ interface MessageFactoryInterface
* - cert: Path a SSL cert or array of (path, pwd)
* - ssl_key: Path to a private SSL key or array of (path, pwd)
* - proxy: Specify an HTTP proxy or hash of protocols to proxies
* - debug: Set to true or a resource to view adapter specific debug info
* - debug: Set to true or a resource to view handler specific debug info
* - stream: Set to true to stream a response body rather than download it all up front
* - expect: true/false/integer Controls the "Expect: 100-Continue" header
* - config: Associative array of request config collection options

View File

@ -25,8 +25,8 @@ use React\Promise\PromiseInterface;
* requested pool size is always filled as much as possible.
*
* IMPORTANT: Do not provide a pool size greater that what the utilized
* underlying Guzzle Ring adapter can support. This will result is extremely
* poor performance.
* underlying RingPHP handler can support. This will result is extremely poor
* performance.
*/
class Pool implements FutureInterface
{

View File

@ -16,7 +16,7 @@ use GuzzleHttp\Ring\Future\FutureInterface;
*/
class RequestFsm
{
private $adapter;
private $handler;
private $mf;
private $maxTransitions;
@ -29,7 +29,7 @@ class RequestFsm
'error' => 'error'
],
// The complete and error events are handled using the "then" of
// the Guzzle-Ring request, so we exit the FSM.
// the RingPHP request, so we exit the FSM.
'send' => ['error' => 'error'],
'complete' => [
'success' => 'end',
@ -45,13 +45,13 @@ class RequestFsm
];
public function __construct(
callable $adapter,
callable $handler,
MessageFactoryInterface $messageFactory,
$maxTransitions = 200
) {
$this->mf = $messageFactory;
$this->maxTransitions = $maxTransitions;
$this->adapter = $adapter;
$this->handler = $handler;
}
/**
@ -133,7 +133,7 @@ class RequestFsm
private function send(Transaction $trans)
{
$fn = $this->adapter;
$fn = $this->handler;
$trans->response = FutureResponse::proxy(
$fn(RingBridge::prepareRingRequest($trans)),
function ($value) use ($trans) {

View File

@ -19,7 +19,7 @@ class RingBridge
*
* This function does not hook up the "then" and "progress" events that
* would be required for actually sending a Guzzle request through a
* ring adapter.
* RingPHP handler.
*
* @param RequestInterface $request Request to convert.
*
@ -150,8 +150,8 @@ class RingBridge
}
/**
* Get an exception that can be used when a ring adapter does not populate
* a response.
* Get an exception that can be used when a RingPHP handler does not
* populate a response.
*
* @param RequestInterface $request
*
@ -162,8 +162,8 @@ class RingBridge
$message = <<<EOT
Sending the request did not return a response, exception, or populate the
transaction with a response. This is most likely due to an incorrectly
implemented Guzzle-Ring adapter. If you are simply trying to mock responses,
then it is recommneded to use the GuzzleHttp\Ring\Client\MockAdapter.
implemented RingPHP handler. If you are simply trying to mock responses,
then it is recommneded to use the GuzzleHttp\Ring\Client\MockHandler.
EOT;
return new RequestException($message, $request);
}

View File

@ -46,8 +46,8 @@ class Transaction
public $exception;
/**
* Associative array of adapter specific transfer statistics and custom
* key value pair information. When providing similar information, adapters
* Associative array of handler specific transfer statistics and custom
* key value pair information. When providing similar information, handlers
* should follow the same key value pair naming conventions as PHP's
* curl_getinfo() (http://php.net/manual/en/function.curl-getinfo.php).
*

View File

@ -7,7 +7,7 @@ use GuzzleHttp\Event\ErrorEvent;
use GuzzleHttp\Message\MessageFactory;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Ring\Client\MockAdapter;
use GuzzleHttp\Ring\Client\MockHandler;
use GuzzleHttp\Ring\Future\FutureArray;
use GuzzleHttp\Subscriber\History;
use GuzzleHttp\Subscriber\Mock;
@ -74,9 +74,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase
* @expectedException \Exception
* @expectedExceptionMessage Foo
*/
public function testCanSpecifyAdapter()
public function testCanSpecifyHandler()
{
$client = new Client(['adapter' => function () {
$client = new Client(['handler' => function () {
throw new \Exception('Foo');
}]);
$client->get('http://httpbin.org');
@ -301,8 +301,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testClientSendsRequests()
{
$mock = new MockAdapter(['status' => 200, 'headers' => []]);
$client = new Client(['adapter' => $mock]);
$mock = new MockHandler(['status' => 200, 'headers' => []]);
$client = new Client(['handler' => $mock]);
$response = $client->get('http://test.com');
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('http://test.com', $response->getEffectiveUrl());
@ -311,7 +311,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testSendingRequestCanBeIntercepted()
{
$response = new Response(200);
$client = new Client(['adapter' => $this->ma]);
$client = new Client(['handler' => $this->ma]);
$client->getEmitter()->on(
'before',
function (BeforeEvent $e) use ($response) {
@ -328,8 +328,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
*/
public function testEnsuresResponseIsPresentAfterSending()
{
$adapter = function () {};
$client = new Client(['adapter' => $adapter]);
$handler = function () {};
$client = new Client(['handler' => $handler]);
$client->get('http://httpbin.org');
}
@ -340,13 +340,13 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testEnsuresResponseIsPresentAfterDereferencing()
{
$deferred = new Deferred();
$adapter = new MockAdapter(function () use ($deferred) {
$handler = new MockHandler(function () use ($deferred) {
return new FutureArray(
$deferred->promise(),
function () {}
);
});
$client = new Client(['adapter' => $adapter]);
$client = new Client(['handler' => $handler]);
$response = $client->get('http://httpbin.org');
$response->wait();
}
@ -403,8 +403,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$deferred->resolve(['error' => new \Exception('Noo!')]);
}
);
$mock = new MockAdapter($future);
$client = new Client(['adapter' => $mock]);
$mock = new MockHandler($future);
$client = new Client(['handler' => $mock]);
$called = 0;
$response = $client->get('http://localhost:123/foo', [
'future' => true,
@ -433,8 +433,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$deferred->resolve(['status' => 201, 'headers' => []]);
}
);
$mock = new MockAdapter($future);
$client = new Client(['adapter' => $mock]);
$mock = new MockHandler($future);
$client = new Client(['handler' => $mock]);
$response = $client->get('http://localhost:123/foo', ['future' => true]);
$this->assertFalse($called);
$this->assertInstanceOf('GuzzleHttp\Message\FutureResponse', $response);
@ -453,7 +453,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$deferred->resolve(['error' => new \Exception('Noop!')]);
}
);
$client = new Client(['adapter' => new MockAdapter($future)]);
$client = new Client(['handler' => new MockHandler($future)]);
try {
$res = $client->get('http://localhost:123/foo', ['future' => true]);
$res->wait();
@ -470,7 +470,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testThrowsExceptionsSynchronously()
{
$client = new Client([
'adapter' => new MockAdapter(['error' => new \Exception('Noo!')])
'handler' => new MockHandler(['error' => new \Exception('Noo!')])
]);
$client->get('http://localhost:123/foo');
}
@ -546,7 +546,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testReturnsFutureForErrorWhenRequested()
{
$client = new Client(['adapter' => new MockAdapter(['status' => 404])]);
$client = new Client(['handler' => new MockHandler(['status' => 404])]);
$request = $client->createRequest('GET', 'http://localhost:123/foo', [
'future' => true
]);
@ -562,7 +562,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testReturnsFutureForResponseWhenRequested()
{
$client = new Client(['adapter' => new MockAdapter(['status' => 200])]);
$client = new Client(['handler' => new MockHandler(['status' => 200])]);
$request = $client->createRequest('GET', 'http://localhost:123/foo', [
'future' => true
]);

View File

@ -4,7 +4,7 @@ namespace GuzzleHttp\Tests;
use GuzzleHttp\Client;
use GuzzleHttp\Event\RequestEvents;
use GuzzleHttp\Pool;
use GuzzleHttp\Ring\Client\MockAdapter;
use GuzzleHttp\Ring\Client\MockHandler;
use GuzzleHttp\Ring\Future\FutureArray;
use GuzzleHttp\Subscriber\History;
use GuzzleHttp\Event\BeforeEvent;
@ -108,12 +108,12 @@ class PoolTest extends \PHPUnit_Framework_TestCase
}
);
return new Client(['adapter' => new MockAdapter($future)]);
return new Client(['handler' => new MockHandler($future)]);
}
public function testBatchesRequests()
{
$client = new Client(['adapter' => function () {
$client = new Client(['handler' => function () {
throw new \RuntimeException('No network access');
}]);
@ -167,7 +167,7 @@ class PoolTest extends \PHPUnit_Framework_TestCase
public function testEmitsProgress()
{
$client = new Client(['adapter' => function () {
$client = new Client(['handler' => function () {
throw new \RuntimeException('No network access');
}]);

View File

@ -9,7 +9,7 @@ use GuzzleHttp\Stream\Stream;
use GuzzleHttp\Transaction;
use GuzzleHttp\Message\Request;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Ring\Client\MockAdapter;
use GuzzleHttp\Ring\Client\MockHandler;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Event\ErrorEvent;
use GuzzleHttp\RequestFsm;
@ -75,7 +75,7 @@ class RingBridgeTest extends \PHPUnit_Framework_TestCase
public function testGetsResponseProtocolVersionAndEffectiveUrlAndReason()
{
$client = new Client([
'adapter' => new MockAdapter([
'handler' => new MockHandler([
'status' => 200,
'reason' => 'test',
'headers' => [],
@ -96,7 +96,7 @@ class RingBridgeTest extends \PHPUnit_Framework_TestCase
fwrite($res, 'foo');
rewind($res);
$client = new Client([
'adapter' => new MockAdapter([
'handler' => new MockHandler([
'status' => 200,
'headers' => [],
'body' => $res
@ -207,7 +207,7 @@ class RingBridgeTest extends \PHPUnit_Framework_TestCase
RingBridge::completeRingResponse($trans, [], $f, $fsm);
} catch (RequestException $e) {
$this->assertSame($trans->request, $e->getRequest());
$this->assertContains('Guzzle-Ring', $e->getMessage());
$this->assertContains('RingPHP', $e->getMessage());
}
}
}

View File

@ -9,7 +9,7 @@ use GuzzleHttp\RingBridge;
use GuzzleHttp\Tests\Ring\Client\Server as TestServer;
/**
* Placeholder for the Guzzle-Ring-Client server that makes it easier to use.
* Placeholder for the RingPHP-Client server that makes it easier to use.
*/
class Server
{

View File

@ -1,6 +1,6 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/guzzlehttp/ring/tests/Client/Server.php';
require __DIR__ . '/../vendor/guzzlehttp/ringphp/tests/Client/Server.php';
use GuzzleHttp\Tests\Server;

View File

@ -13,7 +13,7 @@ require __DIR__ . '/bootstrap.php';
use GuzzleHttp\Client;
use GuzzleHttp\Tests\Server;
use GuzzleHttp\Ring\Client\CurlMultiAdapter;
use GuzzleHttp\Ring\Client\CurlMultiHandler;
use GuzzleHttp\Pool;
// Wait until the server is responding
@ -48,8 +48,8 @@ $perRequest = ($totalTime / $total) * 1000;
printf("Batch: %f (%f ms / request) %d total with %d in parallel\n",
$totalTime, $perRequest, $total, $parallel);
$adapter = new CurlMultiAdapter(['max_handles' => $parallel]);
$client = new Client(['adapter' => $adapter, 'base_url' => Server::$url]);
$handler = new CurlMultiHandler(['max_handles' => $parallel]);
$client = new Client(['handler' => $handler, 'base_url' => Server::$url]);
$t = microtime(true);
for ($i = 0; $i < $total; $i++) {
$client->get('/guzzle-server/perf');