| 1 | Guzzle Upgrade Guide
|
|---|
| 2 | ====================
|
|---|
| 3 |
|
|---|
| 4 | 5.0 to 6.0
|
|---|
| 5 | ----------
|
|---|
| 6 |
|
|---|
| 7 | Guzzle now uses [PSR-7](http://www.php-fig.org/psr/psr-7/) for HTTP messages.
|
|---|
| 8 | Due to the fact that these messages are immutable, this prompted a refactoring
|
|---|
| 9 | of Guzzle to use a middleware based system rather than an event system. Any
|
|---|
| 10 | HTTP message interaction (e.g., `GuzzleHttp\Message\Request`) need to be
|
|---|
| 11 | updated to work with the new immutable PSR-7 request and response objects. Any
|
|---|
| 12 | event listeners or subscribers need to be updated to become middleware
|
|---|
| 13 | functions that wrap handlers (or are injected into a
|
|---|
| 14 | `GuzzleHttp\HandlerStack`).
|
|---|
| 15 |
|
|---|
| 16 | - Removed `GuzzleHttp\BatchResults`
|
|---|
| 17 | - Removed `GuzzleHttp\Collection`
|
|---|
| 18 | - Removed `GuzzleHttp\HasDataTrait`
|
|---|
| 19 | - Removed `GuzzleHttp\ToArrayInterface`
|
|---|
| 20 | - The `guzzlehttp/streams` dependency has been removed. Stream functionality
|
|---|
| 21 | is now present in the `GuzzleHttp\Psr7` namespace provided by the
|
|---|
| 22 | `guzzlehttp/psr7` package.
|
|---|
| 23 | - Guzzle no longer uses ReactPHP promises and now uses the
|
|---|
| 24 | `guzzlehttp/promises` library. We use a custom promise library for three
|
|---|
| 25 | significant reasons:
|
|---|
| 26 | 1. React promises (at the time of writing this) are recursive. Promise
|
|---|
| 27 | chaining and promise resolution will eventually blow the stack. Guzzle
|
|---|
| 28 | promises are not recursive as they use a sort of trampolining technique.
|
|---|
| 29 | Note: there has been movement in the React project to modify promises to
|
|---|
| 30 | no longer utilize recursion.
|
|---|
| 31 | 2. Guzzle needs to have the ability to synchronously block on a promise to
|
|---|
| 32 | wait for a result. Guzzle promises allows this functionality (and does
|
|---|
| 33 | not require the use of recursion).
|
|---|
| 34 | 3. Because we need to be able to wait on a result, doing so using React
|
|---|
| 35 | promises requires wrapping react promises with RingPHP futures. This
|
|---|
| 36 | overhead is no longer needed, reducing stack sizes, reducing complexity,
|
|---|
| 37 | and improving performance.
|
|---|
| 38 | - `GuzzleHttp\Mimetypes` has been moved to a function in
|
|---|
| 39 | `GuzzleHttp\Psr7\mimetype_from_extension` and
|
|---|
| 40 | `GuzzleHttp\Psr7\mimetype_from_filename`.
|
|---|
| 41 | - `GuzzleHttp\Query` and `GuzzleHttp\QueryParser` have been removed. Query
|
|---|
| 42 | strings must now be passed into request objects as strings, or provided to
|
|---|
| 43 | the `query` request option when creating requests with clients. The `query`
|
|---|
| 44 | option uses PHP's `http_build_query` to convert an array to a string. If you
|
|---|
| 45 | need a different serialization technique, you will need to pass the query
|
|---|
| 46 | string in as a string. There are a couple helper functions that will make
|
|---|
| 47 | working with query strings easier: `GuzzleHttp\Psr7\parse_query` and
|
|---|
| 48 | `GuzzleHttp\Psr7\build_query`.
|
|---|
| 49 | - Guzzle no longer has a dependency on RingPHP. Due to the use of a middleware
|
|---|
| 50 | system based on PSR-7, using RingPHP and it's middleware system as well adds
|
|---|
| 51 | more complexity than the benefits it provides. All HTTP handlers that were
|
|---|
| 52 | present in RingPHP have been modified to work directly with PSR-7 messages
|
|---|
| 53 | and placed in the `GuzzleHttp\Handler` namespace. This significantly reduces
|
|---|
| 54 | complexity in Guzzle, removes a dependency, and improves performance. RingPHP
|
|---|
| 55 | will be maintained for Guzzle 5 support, but will no longer be a part of
|
|---|
| 56 | Guzzle 6.
|
|---|
| 57 | - As Guzzle now uses a middleware based systems the event system and RingPHP
|
|---|
| 58 | integration has been removed. Note: while the event system has been removed,
|
|---|
| 59 | it is possible to add your own type of event system that is powered by the
|
|---|
| 60 | middleware system.
|
|---|
| 61 | - Removed the `Event` namespace.
|
|---|
| 62 | - Removed the `Subscriber` namespace.
|
|---|
| 63 | - Removed `Transaction` class
|
|---|
| 64 | - Removed `RequestFsm`
|
|---|
| 65 | - Removed `RingBridge`
|
|---|
| 66 | - `GuzzleHttp\Subscriber\Cookie` is now provided by
|
|---|
| 67 | `GuzzleHttp\Middleware::cookies`
|
|---|
| 68 | - `GuzzleHttp\Subscriber\HttpError` is now provided by
|
|---|
| 69 | `GuzzleHttp\Middleware::httpError`
|
|---|
| 70 | - `GuzzleHttp\Subscriber\History` is now provided by
|
|---|
| 71 | `GuzzleHttp\Middleware::history`
|
|---|
| 72 | - `GuzzleHttp\Subscriber\Mock` is now provided by
|
|---|
| 73 | `GuzzleHttp\Handler\MockHandler`
|
|---|
| 74 | - `GuzzleHttp\Subscriber\Prepare` is now provided by
|
|---|
| 75 | `GuzzleHttp\PrepareBodyMiddleware`
|
|---|
| 76 | - `GuzzleHttp\Subscriber\Redirect` is now provided by
|
|---|
| 77 | `GuzzleHttp\RedirectMiddleware`
|
|---|
| 78 | - Guzzle now uses `Psr\Http\Message\UriInterface` (implements in
|
|---|
| 79 | `GuzzleHttp\Psr7\Uri`) for URI support. `GuzzleHttp\Url` is now gone.
|
|---|
| 80 | - Static functions in `GuzzleHttp\Utils` have been moved to namespaced
|
|---|
| 81 | functions under the `GuzzleHttp` namespace. This requires either a Composer
|
|---|
| 82 | based autoloader or you to include functions.php.
|
|---|
| 83 | - `GuzzleHttp\ClientInterface::getDefaultOption` has been renamed to
|
|---|
| 84 | `GuzzleHttp\ClientInterface::getConfig`.
|
|---|
| 85 | - `GuzzleHttp\ClientInterface::setDefaultOption` has been removed.
|
|---|
| 86 |
|
|---|
| 87 | ## Migrating to middleware
|
|---|
| 88 |
|
|---|
| 89 | The change to PSR-7 unfortunately required significant refactoring to Guzzle
|
|---|
| 90 | due to the fact that PSR-7 messages are immutable. Guzzle 5 relied on an event
|
|---|
| 91 | system from plugins. The event system relied on mutability of HTTP messages and
|
|---|
| 92 | side effects in order to work. With immutable messages, you have to change your
|
|---|
| 93 | workflow to become more about either returning a value (e.g., functional
|
|---|
| 94 | middlewares) or setting a value on an object. Guzzle v6 has chosen the
|
|---|
| 95 | functional middleware approach.
|
|---|
| 96 |
|
|---|
| 97 | Instead of using the event system to listen for things like the `before` event,
|
|---|
| 98 | you now create a stack based middleware function that intercepts a request on
|
|---|
| 99 | the way in and the promise of the response on the way out. This is a much
|
|---|
| 100 | simpler and more predictable approach than the event system and works nicely
|
|---|
| 101 | with PSR-7 middleware. Due to the use of promises, the middleware system is
|
|---|
| 102 | also asynchronous.
|
|---|
| 103 |
|
|---|
| 104 | v5:
|
|---|
| 105 |
|
|---|
| 106 | ```php
|
|---|
| 107 | use GuzzleHttp\Event\BeforeEvent;
|
|---|
| 108 | $client = new GuzzleHttp\Client();
|
|---|
| 109 | // Get the emitter and listen to the before event.
|
|---|
| 110 | $client->getEmitter()->on('before', function (BeforeEvent $e) {
|
|---|
| 111 | // Guzzle v5 events relied on mutation
|
|---|
| 112 | $e->getRequest()->setHeader('X-Foo', 'Bar');
|
|---|
| 113 | });
|
|---|
| 114 | ```
|
|---|
| 115 |
|
|---|
| 116 | v6:
|
|---|
| 117 |
|
|---|
| 118 | In v6, you can modify the request before it is sent using the `mapRequest`
|
|---|
| 119 | middleware. The idiomatic way in v6 to modify the request/response lifecycle is
|
|---|
| 120 | to setup a handler middleware stack up front and inject the handler into a
|
|---|
| 121 | client.
|
|---|
| 122 |
|
|---|
| 123 | ```php
|
|---|
| 124 | use GuzzleHttp\Middleware;
|
|---|
| 125 | // Create a handler stack that has all of the default middlewares attached
|
|---|
| 126 | $handler = GuzzleHttp\HandlerStack::create();
|
|---|
| 127 | // Push the handler onto the handler stack
|
|---|
| 128 | $handler->push(Middleware::mapRequest(function (RequestInterface $request) {
|
|---|
| 129 | // Notice that we have to return a request object
|
|---|
| 130 | return $request->withHeader('X-Foo', 'Bar');
|
|---|
| 131 | });
|
|---|
| 132 | // Inject the handler into the client
|
|---|
| 133 | $client = new GuzzleHttp\Client(['handler' => $handler]);
|
|---|
| 134 | ```
|
|---|
| 135 |
|
|---|
| 136 | ## POST Requests
|
|---|
| 137 |
|
|---|
| 138 | This version added the [`form_params`](http://guzzle.readthedocs.org/en/latest/request-options.html#form_params)
|
|---|
| 139 | and `multipart` request options. `form_params` is an associative array of
|
|---|
| 140 | strings or array of strings and is used to serialize an
|
|---|
| 141 | `application/x-www-form-urlencoded` POST request. The
|
|---|
| 142 | [`multipart`](http://guzzle.readthedocs.org/en/latest/request-options.html#multipart)
|
|---|
| 143 | option is now used to send a multipart/form-data POST request.
|
|---|
| 144 |
|
|---|
| 145 | `GuzzleHttp\Post\PostFile` has been removed. Use the `multipart` option to add
|
|---|
| 146 | POST files to a multipart/form-data request.
|
|---|
| 147 |
|
|---|
| 148 | The `body` option no longer accepts an array to send POST requests. Please use
|
|---|
| 149 | `multipart` or `form_params` instead.
|
|---|
| 150 |
|
|---|
| 151 | The `base_url` option has been renamed to `base_uri`.
|
|---|
| 152 |
|
|---|
| 153 | 4.x to 5.0
|
|---|
| 154 | ----------
|
|---|
| 155 |
|
|---|
| 156 | ## Rewritten Adapter Layer
|
|---|
| 157 |
|
|---|
| 158 | Guzzle now uses [RingPHP](http://ringphp.readthedocs.org/en/latest) to send
|
|---|
| 159 | HTTP requests. The `adapter` option in a `GuzzleHttp\Client` constructor
|
|---|
| 160 | is still supported, but it has now been renamed to `handler`. Instead of
|
|---|
| 161 | passing a `GuzzleHttp\Adapter\AdapterInterface`, you must now pass a PHP
|
|---|
| 162 | `callable` that follows the RingPHP specification.
|
|---|
| 163 |
|
|---|
| 164 | ## Removed Fluent Interfaces
|
|---|
| 165 |
|
|---|
| 166 | [Fluent interfaces were removed](http://ocramius.github.io/blog/fluent-interfaces-are-evil)
|
|---|
| 167 | from the following classes:
|
|---|
| 168 |
|
|---|
| 169 | - `GuzzleHttp\Collection`
|
|---|
| 170 | - `GuzzleHttp\Url`
|
|---|
| 171 | - `GuzzleHttp\Query`
|
|---|
| 172 | - `GuzzleHttp\Post\PostBody`
|
|---|
| 173 | - `GuzzleHttp\Cookie\SetCookie`
|
|---|
| 174 |
|
|---|
| 175 | ## Removed functions.php
|
|---|
| 176 |
|
|---|
| 177 | Removed "functions.php", so that Guzzle is truly PSR-4 compliant. The following
|
|---|
| 178 | functions can be used as replacements.
|
|---|
| 179 |
|
|---|
| 180 | - `GuzzleHttp\json_decode` -> `GuzzleHttp\Utils::jsonDecode`
|
|---|
| 181 | - `GuzzleHttp\get_path` -> `GuzzleHttp\Utils::getPath`
|
|---|
| 182 | - `GuzzleHttp\Utils::setPath` -> `GuzzleHttp\set_path`
|
|---|
| 183 | - `GuzzleHttp\Pool::batch` -> `GuzzleHttp\batch`. This function is, however,
|
|---|
| 184 | deprecated in favor of using `GuzzleHttp\Pool::batch()`.
|
|---|
| 185 |
|
|---|
| 186 | The "procedural" global client has been removed with no replacement (e.g.,
|
|---|
| 187 | `GuzzleHttp\get()`, `GuzzleHttp\post()`, etc.). Use a `GuzzleHttp\Client`
|
|---|
| 188 | object as a replacement.
|
|---|
| 189 |
|
|---|
| 190 | ## `throwImmediately` has been removed
|
|---|
| 191 |
|
|---|
| 192 | The concept of "throwImmediately" has been removed from exceptions and error
|
|---|
| 193 | events. This control mechanism was used to stop a transfer of concurrent
|
|---|
| 194 | requests from completing. This can now be handled by throwing the exception or
|
|---|
| 195 | by cancelling a pool of requests or each outstanding future request
|
|---|
| 196 | individually.
|
|---|
| 197 |
|
|---|
| 198 | ## headers event has been removed
|
|---|
| 199 |
|
|---|
| 200 | Removed the "headers" event. This event was only useful for changing the
|
|---|
| 201 | body a response once the headers of the response were known. You can implement
|
|---|
| 202 | a similar behavior in a number of ways. One example might be to use a
|
|---|
| 203 | FnStream that has access to the transaction being sent. For example, when the
|
|---|
| 204 | first byte is written, you could check if the response headers match your
|
|---|
| 205 | expectations, and if so, change the actual stream body that is being
|
|---|
| 206 | written to.
|
|---|
| 207 |
|
|---|
| 208 | ## Updates to HTTP Messages
|
|---|
| 209 |
|
|---|
| 210 | Removed the `asArray` parameter from
|
|---|
| 211 | `GuzzleHttp\Message\MessageInterface::getHeader`. If you want to get a header
|
|---|
| 212 | value as an array, then use the newly added `getHeaderAsArray()` method of
|
|---|
| 213 | `MessageInterface`. This change makes the Guzzle interfaces compatible with
|
|---|
| 214 | the PSR-7 interfaces.
|
|---|
| 215 |
|
|---|
| 216 | 3.x to 4.0
|
|---|
| 217 | ----------
|
|---|
| 218 |
|
|---|
| 219 | ## Overarching changes:
|
|---|
| 220 |
|
|---|
| 221 | - Now requires PHP 5.4 or greater.
|
|---|
| 222 | - No longer requires cURL to send requests.
|
|---|
| 223 | - Guzzle no longer wraps every exception it throws. Only exceptions that are
|
|---|
| 224 | recoverable are now wrapped by Guzzle.
|
|---|
| 225 | - Various namespaces have been removed or renamed.
|
|---|
| 226 | - No longer requiring the Symfony EventDispatcher. A custom event dispatcher
|
|---|
| 227 | based on the Symfony EventDispatcher is
|
|---|
| 228 | now utilized in `GuzzleHttp\Event\EmitterInterface` (resulting in significant
|
|---|
| 229 | speed and functionality improvements).
|
|---|
| 230 |
|
|---|
| 231 | Changes per Guzzle 3.x namespace are described below.
|
|---|
| 232 |
|
|---|
| 233 | ## Batch
|
|---|
| 234 |
|
|---|
| 235 | The `Guzzle\Batch` namespace has been removed. This is best left to
|
|---|
| 236 | third-parties to implement on top of Guzzle's core HTTP library.
|
|---|
| 237 |
|
|---|
| 238 | ## Cache
|
|---|
| 239 |
|
|---|
| 240 | The `Guzzle\Cache` namespace has been removed. (Todo: No suitable replacement
|
|---|
| 241 | has been implemented yet, but hoping to utilize a PSR cache interface).
|
|---|
| 242 |
|
|---|
| 243 | ## Common
|
|---|
| 244 |
|
|---|
| 245 | - Removed all of the wrapped exceptions. It's better to use the standard PHP
|
|---|
| 246 | library for unrecoverable exceptions.
|
|---|
| 247 | - `FromConfigInterface` has been removed.
|
|---|
| 248 | - `Guzzle\Common\Version` has been removed. The VERSION constant can be found
|
|---|
| 249 | at `GuzzleHttp\ClientInterface::VERSION`.
|
|---|
| 250 |
|
|---|
| 251 | ### Collection
|
|---|
| 252 |
|
|---|
| 253 | - `getAll` has been removed. Use `toArray` to convert a collection to an array.
|
|---|
| 254 | - `inject` has been removed.
|
|---|
| 255 | - `keySearch` has been removed.
|
|---|
| 256 | - `getPath` no longer supports wildcard expressions. Use something better like
|
|---|
| 257 | JMESPath for this.
|
|---|
| 258 | - `setPath` now supports appending to an existing array via the `[]` notation.
|
|---|
| 259 |
|
|---|
| 260 | ### Events
|
|---|
| 261 |
|
|---|
| 262 | Guzzle no longer requires Symfony's EventDispatcher component. Guzzle now uses
|
|---|
| 263 | `GuzzleHttp\Event\Emitter`.
|
|---|
| 264 |
|
|---|
| 265 | - `Symfony\Component\EventDispatcher\EventDispatcherInterface` is replaced by
|
|---|
| 266 | `GuzzleHttp\Event\EmitterInterface`.
|
|---|
| 267 | - `Symfony\Component\EventDispatcher\EventDispatcher` is replaced by
|
|---|
| 268 | `GuzzleHttp\Event\Emitter`.
|
|---|
| 269 | - `Symfony\Component\EventDispatcher\Event` is replaced by
|
|---|
| 270 | `GuzzleHttp\Event\Event`, and Guzzle now has an EventInterface in
|
|---|
| 271 | `GuzzleHttp\Event\EventInterface`.
|
|---|
| 272 | - `AbstractHasDispatcher` has moved to a trait, `HasEmitterTrait`, and
|
|---|
| 273 | `HasDispatcherInterface` has moved to `HasEmitterInterface`. Retrieving the
|
|---|
| 274 | event emitter of a request, client, etc. now uses the `getEmitter` method
|
|---|
| 275 | rather than the `getDispatcher` method.
|
|---|
| 276 |
|
|---|
| 277 | #### Emitter
|
|---|
| 278 |
|
|---|
| 279 | - Use the `once()` method to add a listener that automatically removes itself
|
|---|
| 280 | the first time it is invoked.
|
|---|
| 281 | - Use the `listeners()` method to retrieve a list of event listeners rather than
|
|---|
| 282 | the `getListeners()` method.
|
|---|
| 283 | - Use `emit()` instead of `dispatch()` to emit an event from an emitter.
|
|---|
| 284 | - Use `attach()` instead of `addSubscriber()` and `detach()` instead of
|
|---|
| 285 | `removeSubscriber()`.
|
|---|
| 286 |
|
|---|
| 287 | ```php
|
|---|
| 288 | $mock = new Mock();
|
|---|
| 289 | // 3.x
|
|---|
| 290 | $request->getEventDispatcher()->addSubscriber($mock);
|
|---|
| 291 | $request->getEventDispatcher()->removeSubscriber($mock);
|
|---|
| 292 | // 4.x
|
|---|
| 293 | $request->getEmitter()->attach($mock);
|
|---|
| 294 | $request->getEmitter()->detach($mock);
|
|---|
| 295 | ```
|
|---|
| 296 |
|
|---|
| 297 | Use the `on()` method to add a listener rather than the `addListener()` method.
|
|---|
| 298 |
|
|---|
| 299 | ```php
|
|---|
| 300 | // 3.x
|
|---|
| 301 | $request->getEventDispatcher()->addListener('foo', function (Event $event) { /* ... */ } );
|
|---|
| 302 | // 4.x
|
|---|
| 303 | $request->getEmitter()->on('foo', function (Event $event, $name) { /* ... */ } );
|
|---|
| 304 | ```
|
|---|
| 305 |
|
|---|
| 306 | ## Http
|
|---|
| 307 |
|
|---|
| 308 | ### General changes
|
|---|
| 309 |
|
|---|
| 310 | - The cacert.pem certificate has been moved to `src/cacert.pem`.
|
|---|
| 311 | - Added the concept of adapters that are used to transfer requests over the
|
|---|
| 312 | wire.
|
|---|
| 313 | - Simplified the event system.
|
|---|
| 314 | - Sending requests in parallel is still possible, but batching is no longer a
|
|---|
| 315 | concept of the HTTP layer. Instead, you must use the `complete` and `error`
|
|---|
| 316 | events to asynchronously manage parallel request transfers.
|
|---|
| 317 | - `Guzzle\Http\Url` has moved to `GuzzleHttp\Url`.
|
|---|
| 318 | - `Guzzle\Http\QueryString` has moved to `GuzzleHttp\Query`.
|
|---|
| 319 | - QueryAggregators have been rewritten so that they are simply callable
|
|---|
| 320 | functions.
|
|---|
| 321 | - `GuzzleHttp\StaticClient` has been removed. Use the functions provided in
|
|---|
| 322 | `functions.php` for an easy to use static client instance.
|
|---|
| 323 | - Exceptions in `GuzzleHttp\Exception` have been updated to all extend from
|
|---|
| 324 | `GuzzleHttp\Exception\TransferException`.
|
|---|
| 325 |
|
|---|
| 326 | ### Client
|
|---|
| 327 |
|
|---|
| 328 | Calling methods like `get()`, `post()`, `head()`, etc. no longer create and
|
|---|
| 329 | return a request, but rather creates a request, sends the request, and returns
|
|---|
| 330 | the response.
|
|---|
| 331 |
|
|---|
| 332 | ```php
|
|---|
| 333 | // 3.0
|
|---|
| 334 | $request = $client->get('/');
|
|---|
| 335 | $response = $request->send();
|
|---|
| 336 |
|
|---|
| 337 | // 4.0
|
|---|
| 338 | $response = $client->get('/');
|
|---|
| 339 |
|
|---|
| 340 | // or, to mirror the previous behavior
|
|---|
| 341 | $request = $client->createRequest('GET', '/');
|
|---|
| 342 | $response = $client->send($request);
|
|---|
| 343 | ```
|
|---|
| 344 |
|
|---|
| 345 | `GuzzleHttp\ClientInterface` has changed.
|
|---|
| 346 |
|
|---|
| 347 | - The `send` method no longer accepts more than one request. Use `sendAll` to
|
|---|
| 348 | send multiple requests in parallel.
|
|---|
| 349 | - `setUserAgent()` has been removed. Use a default request option instead. You
|
|---|
| 350 | could, for example, do something like:
|
|---|
| 351 | `$client->setConfig('defaults/headers/User-Agent', 'Foo/Bar ' . $client::getDefaultUserAgent())`.
|
|---|
| 352 | - `setSslVerification()` has been removed. Use default request options instead,
|
|---|
| 353 | like `$client->setConfig('defaults/verify', true)`.
|
|---|
| 354 |
|
|---|
| 355 | `GuzzleHttp\Client` has changed.
|
|---|
| 356 |
|
|---|
| 357 | - The constructor now accepts only an associative array. You can include a
|
|---|
| 358 | `base_url` string or array to use a URI template as the base URL of a client.
|
|---|
| 359 | You can also specify a `defaults` key that is an associative array of default
|
|---|
| 360 | request options. You can pass an `adapter` to use a custom adapter,
|
|---|
| 361 | `batch_adapter` to use a custom adapter for sending requests in parallel, or
|
|---|
| 362 | a `message_factory` to change the factory used to create HTTP requests and
|
|---|
| 363 | responses.
|
|---|
| 364 | - The client no longer emits a `client.create_request` event.
|
|---|
| 365 | - Creating requests with a client no longer automatically utilize a URI
|
|---|
| 366 | template. You must pass an array into a creational method (e.g.,
|
|---|
| 367 | `createRequest`, `get`, `put`, etc.) in order to expand a URI template.
|
|---|
| 368 |
|
|---|
| 369 | ### Messages
|
|---|
| 370 |
|
|---|
| 371 | Messages no longer have references to their counterparts (i.e., a request no
|
|---|
| 372 | longer has a reference to it's response, and a response no loger has a
|
|---|
| 373 | reference to its request). This association is now managed through a
|
|---|
| 374 | `GuzzleHttp\Adapter\TransactionInterface` object. You can get references to
|
|---|
| 375 | these transaction objects using request events that are emitted over the
|
|---|
| 376 | lifecycle of a request.
|
|---|
| 377 |
|
|---|
| 378 | #### Requests with a body
|
|---|
| 379 |
|
|---|
| 380 | - `GuzzleHttp\Message\EntityEnclosingRequest` and
|
|---|
| 381 | `GuzzleHttp\Message\EntityEnclosingRequestInterface` have been removed. The
|
|---|
| 382 | separation between requests that contain a body and requests that do not
|
|---|
| 383 | contain a body has been removed, and now `GuzzleHttp\Message\RequestInterface`
|
|---|
| 384 | handles both use cases.
|
|---|
| 385 | - Any method that previously accepts a `GuzzleHttp\Response` object now accept a
|
|---|
| 386 | `GuzzleHttp\Message\ResponseInterface`.
|
|---|
| 387 | - `GuzzleHttp\Message\RequestFactoryInterface` has been renamed to
|
|---|
| 388 | `GuzzleHttp\Message\MessageFactoryInterface`. This interface is used to create
|
|---|
| 389 | both requests and responses and is implemented in
|
|---|
| 390 | `GuzzleHttp\Message\MessageFactory`.
|
|---|
| 391 | - POST field and file methods have been removed from the request object. You
|
|---|
| 392 | must now use the methods made available to `GuzzleHttp\Post\PostBodyInterface`
|
|---|
| 393 | to control the format of a POST body. Requests that are created using a
|
|---|
| 394 | standard `GuzzleHttp\Message\MessageFactoryInterface` will automatically use
|
|---|
| 395 | a `GuzzleHttp\Post\PostBody` body if the body was passed as an array or if
|
|---|
| 396 | the method is POST and no body is provided.
|
|---|
| 397 |
|
|---|
| 398 | ```php
|
|---|
| 399 | $request = $client->createRequest('POST', '/');
|
|---|
| 400 | $request->getBody()->setField('foo', 'bar');
|
|---|
| 401 | $request->getBody()->addFile(new PostFile('file_key', fopen('/path/to/content', 'r')));
|
|---|
| 402 | ```
|
|---|
| 403 |
|
|---|
| 404 | #### Headers
|
|---|
| 405 |
|
|---|
| 406 | - `GuzzleHttp\Message\Header` has been removed. Header values are now simply
|
|---|
| 407 | represented by an array of values or as a string. Header values are returned
|
|---|
| 408 | as a string by default when retrieving a header value from a message. You can
|
|---|
| 409 | pass an optional argument of `true` to retrieve a header value as an array
|
|---|
| 410 | of strings instead of a single concatenated string.
|
|---|
| 411 | - `GuzzleHttp\PostFile` and `GuzzleHttp\PostFileInterface` have been moved to
|
|---|
| 412 | `GuzzleHttp\Post`. This interface has been simplified and now allows the
|
|---|
| 413 | addition of arbitrary headers.
|
|---|
| 414 | - Custom headers like `GuzzleHttp\Message\Header\Link` have been removed. Most
|
|---|
| 415 | of the custom headers are now handled separately in specific
|
|---|
| 416 | subscribers/plugins, and `GuzzleHttp\Message\HeaderValues::parseParams()` has
|
|---|
| 417 | been updated to properly handle headers that contain parameters (like the
|
|---|
| 418 | `Link` header).
|
|---|
| 419 |
|
|---|
| 420 | #### Responses
|
|---|
| 421 |
|
|---|
| 422 | - `GuzzleHttp\Message\Response::getInfo()` and
|
|---|
| 423 | `GuzzleHttp\Message\Response::setInfo()` have been removed. Use the event
|
|---|
| 424 | system to retrieve this type of information.
|
|---|
| 425 | - `GuzzleHttp\Message\Response::getRawHeaders()` has been removed.
|
|---|
| 426 | - `GuzzleHttp\Message\Response::getMessage()` has been removed.
|
|---|
| 427 | - `GuzzleHttp\Message\Response::calculateAge()` and other cache specific
|
|---|
| 428 | methods have moved to the CacheSubscriber.
|
|---|
| 429 | - Header specific helper functions like `getContentMd5()` have been removed.
|
|---|
| 430 | Just use `getHeader('Content-MD5')` instead.
|
|---|
| 431 | - `GuzzleHttp\Message\Response::setRequest()` and
|
|---|
| 432 | `GuzzleHttp\Message\Response::getRequest()` have been removed. Use the event
|
|---|
| 433 | system to work with request and response objects as a transaction.
|
|---|
| 434 | - `GuzzleHttp\Message\Response::getRedirectCount()` has been removed. Use the
|
|---|
| 435 | Redirect subscriber instead.
|
|---|
| 436 | - `GuzzleHttp\Message\Response::isSuccessful()` and other related methods have
|
|---|
| 437 | been removed. Use `getStatusCode()` instead.
|
|---|
| 438 |
|
|---|
| 439 | #### Streaming responses
|
|---|
| 440 |
|
|---|
| 441 | Streaming requests can now be created by a client directly, returning a
|
|---|
| 442 | `GuzzleHttp\Message\ResponseInterface` object that contains a body stream
|
|---|
| 443 | referencing an open PHP HTTP stream.
|
|---|
| 444 |
|
|---|
| 445 | ```php
|
|---|
| 446 | // 3.0
|
|---|
| 447 | use Guzzle\Stream\PhpStreamRequestFactory;
|
|---|
| 448 | $request = $client->get('/');
|
|---|
| 449 | $factory = new PhpStreamRequestFactory();
|
|---|
| 450 | $stream = $factory->fromRequest($request);
|
|---|
| 451 | $data = $stream->read(1024);
|
|---|
| 452 |
|
|---|
| 453 | // 4.0
|
|---|
| 454 | $response = $client->get('/', ['stream' => true]);
|
|---|
| 455 | // Read some data off of the stream in the response body
|
|---|
| 456 | $data = $response->getBody()->read(1024);
|
|---|
| 457 | ```
|
|---|
| 458 |
|
|---|
| 459 | #### Redirects
|
|---|
| 460 |
|
|---|
| 461 | The `configureRedirects()` method has been removed in favor of a
|
|---|
| 462 | `allow_redirects` request option.
|
|---|
| 463 |
|
|---|
| 464 | ```php
|
|---|
| 465 | // Standard redirects with a default of a max of 5 redirects
|
|---|
| 466 | $request = $client->createRequest('GET', '/', ['allow_redirects' => true]);
|
|---|
| 467 |
|
|---|
| 468 | // Strict redirects with a custom number of redirects
|
|---|
| 469 | $request = $client->createRequest('GET', '/', [
|
|---|
| 470 | 'allow_redirects' => ['max' => 5, 'strict' => true]
|
|---|
| 471 | ]);
|
|---|
| 472 | ```
|
|---|
| 473 |
|
|---|
| 474 | #### EntityBody
|
|---|
| 475 |
|
|---|
| 476 | EntityBody interfaces and classes have been removed or moved to
|
|---|
| 477 | `GuzzleHttp\Stream`. All classes and interfaces that once required
|
|---|
| 478 | `GuzzleHttp\EntityBodyInterface` now require
|
|---|
| 479 | `GuzzleHttp\Stream\StreamInterface`. Creating a new body for a request no
|
|---|
| 480 | longer uses `GuzzleHttp\EntityBody::factory` but now uses
|
|---|
| 481 | `GuzzleHttp\Stream\Stream::factory` or even better:
|
|---|
| 482 | `GuzzleHttp\Stream\create()`.
|
|---|
| 483 |
|
|---|
| 484 | - `Guzzle\Http\EntityBodyInterface` is now `GuzzleHttp\Stream\StreamInterface`
|
|---|
| 485 | - `Guzzle\Http\EntityBody` is now `GuzzleHttp\Stream\Stream`
|
|---|
| 486 | - `Guzzle\Http\CachingEntityBody` is now `GuzzleHttp\Stream\CachingStream`
|
|---|
| 487 | - `Guzzle\Http\ReadLimitEntityBody` is now `GuzzleHttp\Stream\LimitStream`
|
|---|
| 488 | - `Guzzle\Http\IoEmittyinEntityBody` has been removed.
|
|---|
| 489 |
|
|---|
| 490 | #### Request lifecycle events
|
|---|
| 491 |
|
|---|
| 492 | Requests previously submitted a large number of requests. The number of events
|
|---|
| 493 | emitted over the lifecycle of a request has been significantly reduced to make
|
|---|
| 494 | it easier to understand how to extend the behavior of a request. All events
|
|---|
| 495 | emitted during the lifecycle of a request now emit a custom
|
|---|
| 496 | `GuzzleHttp\Event\EventInterface` object that contains context providing
|
|---|
| 497 | methods and a way in which to modify the transaction at that specific point in
|
|---|
| 498 | time (e.g., intercept the request and set a response on the transaction).
|
|---|
| 499 |
|
|---|
| 500 | - `request.before_send` has been renamed to `before` and now emits a
|
|---|
| 501 | `GuzzleHttp\Event\BeforeEvent`
|
|---|
| 502 | - `request.complete` has been renamed to `complete` and now emits a
|
|---|
| 503 | `GuzzleHttp\Event\CompleteEvent`.
|
|---|
| 504 | - `request.sent` has been removed. Use `complete`.
|
|---|
| 505 | - `request.success` has been removed. Use `complete`.
|
|---|
| 506 | - `error` is now an event that emits a `GuzzleHttp\Event\ErrorEvent`.
|
|---|
| 507 | - `request.exception` has been removed. Use `error`.
|
|---|
| 508 | - `request.receive.status_line` has been removed.
|
|---|
| 509 | - `curl.callback.progress` has been removed. Use a custom `StreamInterface` to
|
|---|
| 510 | maintain a status update.
|
|---|
| 511 | - `curl.callback.write` has been removed. Use a custom `StreamInterface` to
|
|---|
| 512 | intercept writes.
|
|---|
| 513 | - `curl.callback.read` has been removed. Use a custom `StreamInterface` to
|
|---|
| 514 | intercept reads.
|
|---|
| 515 |
|
|---|
| 516 | `headers` is a new event that is emitted after the response headers of a
|
|---|
| 517 | request have been received before the body of the response is downloaded. This
|
|---|
| 518 | event emits a `GuzzleHttp\Event\HeadersEvent`.
|
|---|
| 519 |
|
|---|
| 520 | You can intercept a request and inject a response using the `intercept()` event
|
|---|
| 521 | of a `GuzzleHttp\Event\BeforeEvent`, `GuzzleHttp\Event\CompleteEvent`, and
|
|---|
| 522 | `GuzzleHttp\Event\ErrorEvent` event.
|
|---|
| 523 |
|
|---|
| 524 | See: http://docs.guzzlephp.org/en/latest/events.html
|
|---|
| 525 |
|
|---|
| 526 | ## Inflection
|
|---|
| 527 |
|
|---|
| 528 | The `Guzzle\Inflection` namespace has been removed. This is not a core concern
|
|---|
| 529 | of Guzzle.
|
|---|
| 530 |
|
|---|
| 531 | ## Iterator
|
|---|
| 532 |
|
|---|
| 533 | The `Guzzle\Iterator` namespace has been removed.
|
|---|
| 534 |
|
|---|
| 535 | - `Guzzle\Iterator\AppendIterator`, `Guzzle\Iterator\ChunkedIterator`, and
|
|---|
| 536 | `Guzzle\Iterator\MethodProxyIterator` are nice, but not a core requirement of
|
|---|
| 537 | Guzzle itself.
|
|---|
| 538 | - `Guzzle\Iterator\FilterIterator` is no longer needed because an equivalent
|
|---|
| 539 | class is shipped with PHP 5.4.
|
|---|
| 540 | - `Guzzle\Iterator\MapIterator` is not really needed when using PHP 5.5 because
|
|---|
| 541 | it's easier to just wrap an iterator in a generator that maps values.
|
|---|
| 542 |
|
|---|
| 543 | For a replacement of these iterators, see https://github.com/nikic/iter
|
|---|
| 544 |
|
|---|
| 545 | ## Log
|
|---|
| 546 |
|
|---|
| 547 | The LogPlugin has moved to https://github.com/guzzle/log-subscriber. The
|
|---|
| 548 | `Guzzle\Log` namespace has been removed. Guzzle now relies on
|
|---|
| 549 | `Psr\Log\LoggerInterface` for all logging. The MessageFormatter class has been
|
|---|
| 550 | moved to `GuzzleHttp\Subscriber\Log\Formatter`.
|
|---|
| 551 |
|
|---|
| 552 | ## Parser
|
|---|
| 553 |
|
|---|
| 554 | The `Guzzle\Parser` namespace has been removed. This was previously used to
|
|---|
| 555 | make it possible to plug in custom parsers for cookies, messages, URI
|
|---|
| 556 | templates, and URLs; however, this level of complexity is not needed in Guzzle
|
|---|
| 557 | so it has been removed.
|
|---|
| 558 |
|
|---|
| 559 | - Cookie: Cookie parsing logic has been moved to
|
|---|
| 560 | `GuzzleHttp\Cookie\SetCookie::fromString`.
|
|---|
| 561 | - Message: Message parsing logic for both requests and responses has been moved
|
|---|
| 562 | to `GuzzleHttp\Message\MessageFactory::fromMessage`. Message parsing is only
|
|---|
| 563 | used in debugging or deserializing messages, so it doesn't make sense for
|
|---|
| 564 | Guzzle as a library to add this level of complexity to parsing messages.
|
|---|
| 565 | - UriTemplate: URI template parsing has been moved to
|
|---|
| 566 | `GuzzleHttp\UriTemplate`. The Guzzle library will automatically use the PECL
|
|---|
| 567 | URI template library if it is installed.
|
|---|
| 568 | - Url: URL parsing is now performed in `GuzzleHttp\Url::fromString` (previously
|
|---|
| 569 | it was `Guzzle\Http\Url::factory()`). If custom URL parsing is necessary,
|
|---|
| 570 | then developers are free to subclass `GuzzleHttp\Url`.
|
|---|
| 571 |
|
|---|
| 572 | ## Plugin
|
|---|
| 573 |
|
|---|
| 574 | The `Guzzle\Plugin` namespace has been renamed to `GuzzleHttp\Subscriber`.
|
|---|
| 575 | Several plugins are shipping with the core Guzzle library under this namespace.
|
|---|
| 576 |
|
|---|
| 577 | - `GuzzleHttp\Subscriber\Cookie`: Replaces the old CookiePlugin. Cookie jar
|
|---|
| 578 | code has moved to `GuzzleHttp\Cookie`.
|
|---|
| 579 | - `GuzzleHttp\Subscriber\History`: Replaces the old HistoryPlugin.
|
|---|
| 580 | - `GuzzleHttp\Subscriber\HttpError`: Throws errors when a bad HTTP response is
|
|---|
| 581 | received.
|
|---|
| 582 | - `GuzzleHttp\Subscriber\Mock`: Replaces the old MockPlugin.
|
|---|
| 583 | - `GuzzleHttp\Subscriber\Prepare`: Prepares the body of a request just before
|
|---|
| 584 | sending. This subscriber is attached to all requests by default.
|
|---|
| 585 | - `GuzzleHttp\Subscriber\Redirect`: Replaces the RedirectPlugin.
|
|---|
| 586 |
|
|---|
| 587 | The following plugins have been removed (third-parties are free to re-implement
|
|---|
| 588 | these if needed):
|
|---|
| 589 |
|
|---|
| 590 | - `GuzzleHttp\Plugin\Async` has been removed.
|
|---|
| 591 | - `GuzzleHttp\Plugin\CurlAuth` has been removed.
|
|---|
| 592 | - `GuzzleHttp\Plugin\ErrorResponse\ErrorResponsePlugin` has been removed. This
|
|---|
| 593 | functionality should instead be implemented with event listeners that occur
|
|---|
| 594 | after normal response parsing occurs in the guzzle/command package.
|
|---|
| 595 |
|
|---|
| 596 | The following plugins are not part of the core Guzzle package, but are provided
|
|---|
| 597 | in separate repositories:
|
|---|
| 598 |
|
|---|
| 599 | - `Guzzle\Http\Plugin\BackoffPlugin` has been rewritten to be muchs simpler
|
|---|
| 600 | to build custom retry policies using simple functions rather than various
|
|---|
| 601 | chained classes. See: https://github.com/guzzle/retry-subscriber
|
|---|
| 602 | - `Guzzle\Http\Plugin\Cache\CachePlugin` has moved to
|
|---|
| 603 | https://github.com/guzzle/cache-subscriber
|
|---|
| 604 | - `Guzzle\Http\Plugin\Log\LogPlugin` has moved to
|
|---|
| 605 | https://github.com/guzzle/log-subscriber
|
|---|
| 606 | - `Guzzle\Http\Plugin\Md5\Md5Plugin` has moved to
|
|---|
| 607 | https://github.com/guzzle/message-integrity-subscriber
|
|---|
| 608 | - `Guzzle\Http\Plugin\Mock\MockPlugin` has moved to
|
|---|
| 609 | `GuzzleHttp\Subscriber\MockSubscriber`.
|
|---|
| 610 | - `Guzzle\Http\Plugin\Oauth\OauthPlugin` has moved to
|
|---|
| 611 | https://github.com/guzzle/oauth-subscriber
|
|---|
| 612 |
|
|---|
| 613 | ## Service
|
|---|
| 614 |
|
|---|
| 615 | The service description layer of Guzzle has moved into two separate packages:
|
|---|
| 616 |
|
|---|
| 617 | - http://github.com/guzzle/command Provides a high level abstraction over web
|
|---|
| 618 | services by representing web service operations using commands.
|
|---|
| 619 | - http://github.com/guzzle/guzzle-services Provides an implementation of
|
|---|
| 620 | guzzle/command that provides request serialization and response parsing using
|
|---|
| 621 | Guzzle service descriptions.
|
|---|
| 622 |
|
|---|
| 623 | ## Stream
|
|---|
| 624 |
|
|---|
| 625 | Stream have moved to a separate package available at
|
|---|
| 626 | https://github.com/guzzle/streams.
|
|---|
| 627 |
|
|---|
| 628 | `Guzzle\Stream\StreamInterface` has been given a large update to cleanly take
|
|---|
| 629 | on the responsibilities of `Guzzle\Http\EntityBody` and
|
|---|
| 630 | `Guzzle\Http\EntityBodyInterface` now that they have been removed. The number
|
|---|
| 631 | of methods implemented by the `StreamInterface` has been drastically reduced to
|
|---|
| 632 | allow developers to more easily extend and decorate stream behavior.
|
|---|
| 633 |
|
|---|
| 634 | ## Removed methods from StreamInterface
|
|---|
| 635 |
|
|---|
| 636 | - `getStream` and `setStream` have been removed to better encapsulate streams.
|
|---|
| 637 | - `getMetadata` and `setMetadata` have been removed in favor of
|
|---|
| 638 | `GuzzleHttp\Stream\MetadataStreamInterface`.
|
|---|
| 639 | - `getWrapper`, `getWrapperData`, `getStreamType`, and `getUri` have all been
|
|---|
| 640 | removed. This data is accessible when
|
|---|
| 641 | using streams that implement `GuzzleHttp\Stream\MetadataStreamInterface`.
|
|---|
| 642 | - `rewind` has been removed. Use `seek(0)` for a similar behavior.
|
|---|
| 643 |
|
|---|
| 644 | ## Renamed methods
|
|---|
| 645 |
|
|---|
| 646 | - `detachStream` has been renamed to `detach`.
|
|---|
| 647 | - `feof` has been renamed to `eof`.
|
|---|
| 648 | - `ftell` has been renamed to `tell`.
|
|---|
| 649 | - `readLine` has moved from an instance method to a static class method of
|
|---|
| 650 | `GuzzleHttp\Stream\Stream`.
|
|---|
| 651 |
|
|---|
| 652 | ## Metadata streams
|
|---|
| 653 |
|
|---|
| 654 | `GuzzleHttp\Stream\MetadataStreamInterface` has been added to denote streams
|
|---|
| 655 | that contain additional metadata accessible via `getMetadata()`.
|
|---|
| 656 | `GuzzleHttp\Stream\StreamInterface::getMetadata` and
|
|---|
| 657 | `GuzzleHttp\Stream\StreamInterface::setMetadata` have been removed.
|
|---|
| 658 |
|
|---|
| 659 | ## StreamRequestFactory
|
|---|
| 660 |
|
|---|
| 661 | The entire concept of the StreamRequestFactory has been removed. The way this
|
|---|
| 662 | was used in Guzzle 3 broke the actual interface of sending streaming requests
|
|---|
| 663 | (instead of getting back a Response, you got a StreamInterface). Streeaming
|
|---|
| 664 | PHP requests are now implemented throught the `GuzzleHttp\Adapter\StreamAdapter`.
|
|---|
| 665 |
|
|---|
| 666 | 3.6 to 3.7
|
|---|
| 667 | ----------
|
|---|
| 668 |
|
|---|
| 669 | ### Deprecations
|
|---|
| 670 |
|
|---|
| 671 | - You can now enable E_USER_DEPRECATED warnings to see if you are using any deprecated methods.:
|
|---|
| 672 |
|
|---|
| 673 | ```php
|
|---|
| 674 | \Guzzle\Common\Version::$emitWarnings = true;
|
|---|
| 675 | ```
|
|---|
| 676 |
|
|---|
| 677 | The following APIs and options have been marked as deprecated:
|
|---|
| 678 |
|
|---|
| 679 | - Marked `Guzzle\Http\Message\Request::isResponseBodyRepeatable()` as deprecated. Use `$request->getResponseBody()->isRepeatable()` instead.
|
|---|
| 680 | - Marked `Guzzle\Http\Message\Request::canCache()` as deprecated. Use `Guzzle\Plugin\Cache\DefaultCanCacheStrategy->canCacheRequest()` instead.
|
|---|
| 681 | - Marked `Guzzle\Http\Message\Request::canCache()` as deprecated. Use `Guzzle\Plugin\Cache\DefaultCanCacheStrategy->canCacheRequest()` instead.
|
|---|
| 682 | - Marked `Guzzle\Http\Message\Request::setIsRedirect()` as deprecated. Use the HistoryPlugin instead.
|
|---|
| 683 | - Marked `Guzzle\Http\Message\Request::isRedirect()` as deprecated. Use the HistoryPlugin instead.
|
|---|
| 684 | - Marked `Guzzle\Cache\CacheAdapterFactory::factory()` as deprecated
|
|---|
| 685 | - Marked `Guzzle\Service\Client::enableMagicMethods()` as deprecated. Magic methods can no longer be disabled on a Guzzle\Service\Client.
|
|---|
| 686 | - Marked `Guzzle\Parser\Url\UrlParser` as deprecated. Just use PHP's `parse_url()` and percent encode your UTF-8.
|
|---|
| 687 | - Marked `Guzzle\Common\Collection::inject()` as deprecated.
|
|---|
| 688 | - Marked `Guzzle\Plugin\CurlAuth\CurlAuthPlugin` as deprecated. Use
|
|---|
| 689 | `$client->getConfig()->setPath('request.options/auth', array('user', 'pass', 'Basic|Digest|NTLM|Any'));` or
|
|---|
| 690 | `$client->setDefaultOption('auth', array('user', 'pass', 'Basic|Digest|NTLM|Any'));`
|
|---|
| 691 |
|
|---|
| 692 | 3.7 introduces `request.options` as a parameter for a client configuration and as an optional argument to all creational
|
|---|
| 693 | request methods. When paired with a client's configuration settings, these options allow you to specify default settings
|
|---|
| 694 | for various aspects of a request. Because these options make other previous configuration options redundant, several
|
|---|
| 695 | configuration options and methods of a client and AbstractCommand have been deprecated.
|
|---|
| 696 |
|
|---|
| 697 | - Marked `Guzzle\Service\Client::getDefaultHeaders()` as deprecated. Use `$client->getDefaultOption('headers')`.
|
|---|
| 698 | - Marked `Guzzle\Service\Client::setDefaultHeaders()` as deprecated. Use `$client->setDefaultOption('headers/{header_name}', 'value')`.
|
|---|
| 699 | - Marked 'request.params' for `Guzzle\Http\Client` as deprecated. Use `$client->setDefaultOption('params/{param_name}', 'value')`
|
|---|
| 700 | - Marked 'command.headers', 'command.response_body' and 'command.on_complete' as deprecated for AbstractCommand. These will work through Guzzle 4.0
|
|---|
| 701 |
|
|---|
| 702 | $command = $client->getCommand('foo', array(
|
|---|
| 703 | 'command.headers' => array('Test' => '123'),
|
|---|
| 704 | 'command.response_body' => '/path/to/file'
|
|---|
| 705 | ));
|
|---|
| 706 |
|
|---|
| 707 | // Should be changed to:
|
|---|
| 708 |
|
|---|
| 709 | $command = $client->getCommand('foo', array(
|
|---|
| 710 | 'command.request_options' => array(
|
|---|
| 711 | 'headers' => array('Test' => '123'),
|
|---|
| 712 | 'save_as' => '/path/to/file'
|
|---|
| 713 | )
|
|---|
| 714 | ));
|
|---|
| 715 |
|
|---|
| 716 | ### Interface changes
|
|---|
| 717 |
|
|---|
| 718 | Additions and changes (you will need to update any implementations or subclasses you may have created):
|
|---|
| 719 |
|
|---|
| 720 | - Added an `$options` argument to the end of the following methods of `Guzzle\Http\ClientInterface`:
|
|---|
| 721 | createRequest, head, delete, put, patch, post, options, prepareRequest
|
|---|
| 722 | - Added an `$options` argument to the end of `Guzzle\Http\Message\Request\RequestFactoryInterface::createRequest()`
|
|---|
| 723 | - Added an `applyOptions()` method to `Guzzle\Http\Message\Request\RequestFactoryInterface`
|
|---|
| 724 | - Changed `Guzzle\Http\ClientInterface::get($uri = null, $headers = null, $body = null)` to
|
|---|
| 725 | `Guzzle\Http\ClientInterface::get($uri = null, $headers = null, $options = array())`. You can still pass in a
|
|---|
| 726 | resource, string, or EntityBody into the $options parameter to specify the download location of the response.
|
|---|
| 727 | - Changed `Guzzle\Common\Collection::__construct($data)` to no longer accepts a null value for `$data` but a
|
|---|
| 728 | default `array()`
|
|---|
| 729 | - Added `Guzzle\Stream\StreamInterface::isRepeatable`
|
|---|
| 730 | - Made `Guzzle\Http\Client::expandTemplate` and `getUriTemplate` protected methods.
|
|---|
| 731 |
|
|---|
| 732 | The following methods were removed from interfaces. All of these methods are still available in the concrete classes
|
|---|
| 733 | that implement them, but you should update your code to use alternative methods:
|
|---|
| 734 |
|
|---|
| 735 | - Removed `Guzzle\Http\ClientInterface::setDefaultHeaders(). Use
|
|---|
| 736 | `$client->getConfig()->setPath('request.options/headers/{header_name}', 'value')`. or
|
|---|
| 737 | `$client->getConfig()->setPath('request.options/headers', array('header_name' => 'value'))` or
|
|---|
| 738 | `$client->setDefaultOption('headers/{header_name}', 'value')`. or
|
|---|
| 739 | `$client->setDefaultOption('headers', array('header_name' => 'value'))`.
|
|---|
| 740 | - Removed `Guzzle\Http\ClientInterface::getDefaultHeaders(). Use `$client->getConfig()->getPath('request.options/headers')`.
|
|---|
| 741 | - Removed `Guzzle\Http\ClientInterface::expandTemplate()`. This is an implementation detail.
|
|---|
| 742 | - Removed `Guzzle\Http\ClientInterface::setRequestFactory()`. This is an implementation detail.
|
|---|
| 743 | - Removed `Guzzle\Http\ClientInterface::getCurlMulti()`. This is a very specific implementation detail.
|
|---|
| 744 | - Removed `Guzzle\Http\Message\RequestInterface::canCache`. Use the CachePlugin.
|
|---|
| 745 | - Removed `Guzzle\Http\Message\RequestInterface::setIsRedirect`. Use the HistoryPlugin.
|
|---|
| 746 | - Removed `Guzzle\Http\Message\RequestInterface::isRedirect`. Use the HistoryPlugin.
|
|---|
| 747 |
|
|---|
| 748 | ### Cache plugin breaking changes
|
|---|
| 749 |
|
|---|
| 750 | - CacheKeyProviderInterface and DefaultCacheKeyProvider are no longer used. All of this logic is handled in a
|
|---|
| 751 | CacheStorageInterface. These two objects and interface will be removed in a future version.
|
|---|
| 752 | - Always setting X-cache headers on cached responses
|
|---|
| 753 | - Default cache TTLs are now handled by the CacheStorageInterface of a CachePlugin
|
|---|
| 754 | - `CacheStorageInterface::cache($key, Response $response, $ttl = null)` has changed to `cache(RequestInterface
|
|---|
| 755 | $request, Response $response);`
|
|---|
| 756 | - `CacheStorageInterface::fetch($key)` has changed to `fetch(RequestInterface $request);`
|
|---|
| 757 | - `CacheStorageInterface::delete($key)` has changed to `delete(RequestInterface $request);`
|
|---|
| 758 | - Added `CacheStorageInterface::purge($url)`
|
|---|
| 759 | - `DefaultRevalidation::__construct(CacheKeyProviderInterface $cacheKey, CacheStorageInterface $cache, CachePlugin
|
|---|
| 760 | $plugin)` has changed to `DefaultRevalidation::__construct(CacheStorageInterface $cache,
|
|---|
| 761 | CanCacheStrategyInterface $canCache = null)`
|
|---|
| 762 | - Added `RevalidationInterface::shouldRevalidate(RequestInterface $request, Response $response)`
|
|---|
| 763 |
|
|---|
| 764 | 3.5 to 3.6
|
|---|
| 765 | ----------
|
|---|
| 766 |
|
|---|
| 767 | * Mixed casing of headers are now forced to be a single consistent casing across all values for that header.
|
|---|
| 768 | * Messages internally use a HeaderCollection object to delegate handling case-insensitive header resolution
|
|---|
| 769 | * Removed the whole changedHeader() function system of messages because all header changes now go through addHeader().
|
|---|
| 770 | For example, setHeader() first removes the header using unset on a HeaderCollection and then calls addHeader().
|
|---|
| 771 | Keeping the Host header and URL host in sync is now handled by overriding the addHeader method in Request.
|
|---|
| 772 | * Specific header implementations can be created for complex headers. When a message creates a header, it uses a
|
|---|
| 773 | HeaderFactory which can map specific headers to specific header classes. There is now a Link header and
|
|---|
| 774 | CacheControl header implementation.
|
|---|
| 775 | * Moved getLinks() from Response to just be used on a Link header object.
|
|---|
| 776 |
|
|---|
| 777 | If you previously relied on Guzzle\Http\Message\Header::raw(), then you will need to update your code to use the
|
|---|
| 778 | HeaderInterface (e.g. toArray(), getAll(), etc.).
|
|---|
| 779 |
|
|---|
| 780 | ### Interface changes
|
|---|
| 781 |
|
|---|
| 782 | * Removed from interface: Guzzle\Http\ClientInterface::setUriTemplate
|
|---|
| 783 | * Removed from interface: Guzzle\Http\ClientInterface::setCurlMulti()
|
|---|
| 784 | * Removed Guzzle\Http\Message\Request::receivedRequestHeader() and implemented this functionality in
|
|---|
| 785 | Guzzle\Http\Curl\RequestMediator
|
|---|
| 786 | * Removed the optional $asString parameter from MessageInterface::getHeader(). Just cast the header to a string.
|
|---|
| 787 | * Removed the optional $tryChunkedTransfer option from Guzzle\Http\Message\EntityEnclosingRequestInterface
|
|---|
| 788 | * Removed the $asObjects argument from Guzzle\Http\Message\MessageInterface::getHeaders()
|
|---|
| 789 |
|
|---|
| 790 | ### Removed deprecated functions
|
|---|
| 791 |
|
|---|
| 792 | * Removed Guzzle\Parser\ParserRegister::get(). Use getParser()
|
|---|
| 793 | * Removed Guzzle\Parser\ParserRegister::set(). Use registerParser().
|
|---|
| 794 |
|
|---|
| 795 | ### Deprecations
|
|---|
| 796 |
|
|---|
| 797 | * The ability to case-insensitively search for header values
|
|---|
| 798 | * Guzzle\Http\Message\Header::hasExactHeader
|
|---|
| 799 | * Guzzle\Http\Message\Header::raw. Use getAll()
|
|---|
| 800 | * Deprecated cache control specific methods on Guzzle\Http\Message\AbstractMessage. Use the CacheControl header object
|
|---|
| 801 | instead.
|
|---|
| 802 |
|
|---|
| 803 | ### Other changes
|
|---|
| 804 |
|
|---|
| 805 | * All response header helper functions return a string rather than mixing Header objects and strings inconsistently
|
|---|
| 806 | * Removed cURL blacklist support. This is no longer necessary now that Expect, Accept, etc. are managed by Guzzle
|
|---|
| 807 | directly via interfaces
|
|---|
| 808 | * Removed the injecting of a request object onto a response object. The methods to get and set a request still exist
|
|---|
| 809 | but are a no-op until removed.
|
|---|
| 810 | * Most classes that used to require a `Guzzle\Service\Command\CommandInterface` typehint now request a
|
|---|
| 811 | `Guzzle\Service\Command\ArrayCommandInterface`.
|
|---|
| 812 | * Added `Guzzle\Http\Message\RequestInterface::startResponse()` to the RequestInterface to handle injecting a response
|
|---|
| 813 | on a request while the request is still being transferred
|
|---|
| 814 | * `Guzzle\Service\Command\CommandInterface` now extends from ToArrayInterface and ArrayAccess
|
|---|
| 815 |
|
|---|
| 816 | 3.3 to 3.4
|
|---|
| 817 | ----------
|
|---|
| 818 |
|
|---|
| 819 | Base URLs of a client now follow the rules of http://tools.ietf.org/html/rfc3986#section-5.2.2 when merging URLs.
|
|---|
| 820 |
|
|---|
| 821 | 3.2 to 3.3
|
|---|
| 822 | ----------
|
|---|
| 823 |
|
|---|
| 824 | ### Response::getEtag() quote stripping removed
|
|---|
| 825 |
|
|---|
| 826 | `Guzzle\Http\Message\Response::getEtag()` no longer strips quotes around the ETag response header
|
|---|
| 827 |
|
|---|
| 828 | ### Removed `Guzzle\Http\Utils`
|
|---|
| 829 |
|
|---|
| 830 | The `Guzzle\Http\Utils` class was removed. This class was only used for testing.
|
|---|
| 831 |
|
|---|
| 832 | ### Stream wrapper and type
|
|---|
| 833 |
|
|---|
| 834 | `Guzzle\Stream\Stream::getWrapper()` and `Guzzle\Stream\Stream::getStreamType()` are no longer converted to lowercase.
|
|---|
| 835 |
|
|---|
| 836 | ### curl.emit_io became emit_io
|
|---|
| 837 |
|
|---|
| 838 | Emitting IO events from a RequestMediator is now a parameter that must be set in a request's curl options using the
|
|---|
| 839 | 'emit_io' key. This was previously set under a request's parameters using 'curl.emit_io'
|
|---|
| 840 |
|
|---|
| 841 | 3.1 to 3.2
|
|---|
| 842 | ----------
|
|---|
| 843 |
|
|---|
| 844 | ### CurlMulti is no longer reused globally
|
|---|
| 845 |
|
|---|
| 846 | Before 3.2, the same CurlMulti object was reused globally for each client. This can cause issue where plugins added
|
|---|
| 847 | to a single client can pollute requests dispatched from other clients.
|
|---|
| 848 |
|
|---|
| 849 | If you still wish to reuse the same CurlMulti object with each client, then you can add a listener to the
|
|---|
| 850 | ServiceBuilder's `service_builder.create_client` event to inject a custom CurlMulti object into each client as it is
|
|---|
| 851 | created.
|
|---|
| 852 |
|
|---|
| 853 | ```php
|
|---|
| 854 | $multi = new Guzzle\Http\Curl\CurlMulti();
|
|---|
| 855 | $builder = Guzzle\Service\Builder\ServiceBuilder::factory('/path/to/config.json');
|
|---|
| 856 | $builder->addListener('service_builder.create_client', function ($event) use ($multi) {
|
|---|
| 857 | $event['client']->setCurlMulti($multi);
|
|---|
| 858 | }
|
|---|
| 859 | });
|
|---|
| 860 | ```
|
|---|
| 861 |
|
|---|
| 862 | ### No default path
|
|---|
| 863 |
|
|---|
| 864 | URLs no longer have a default path value of '/' if no path was specified.
|
|---|
| 865 |
|
|---|
| 866 | Before:
|
|---|
| 867 |
|
|---|
| 868 | ```php
|
|---|
| 869 | $request = $client->get('http://www.foo.com');
|
|---|
| 870 | echo $request->getUrl();
|
|---|
| 871 | // >> http://www.foo.com/
|
|---|
| 872 | ```
|
|---|
| 873 |
|
|---|
| 874 | After:
|
|---|
| 875 |
|
|---|
| 876 | ```php
|
|---|
| 877 | $request = $client->get('http://www.foo.com');
|
|---|
| 878 | echo $request->getUrl();
|
|---|
| 879 | // >> http://www.foo.com
|
|---|
| 880 | ```
|
|---|
| 881 |
|
|---|
| 882 | ### Less verbose BadResponseException
|
|---|
| 883 |
|
|---|
| 884 | The exception message for `Guzzle\Http\Exception\BadResponseException` no longer contains the full HTTP request and
|
|---|
| 885 | response information. You can, however, get access to the request and response object by calling `getRequest()` or
|
|---|
| 886 | `getResponse()` on the exception object.
|
|---|
| 887 |
|
|---|
| 888 | ### Query parameter aggregation
|
|---|
| 889 |
|
|---|
| 890 | Multi-valued query parameters are no longer aggregated using a callback function. `Guzzle\Http\Query` now has a
|
|---|
| 891 | setAggregator() method that accepts a `Guzzle\Http\QueryAggregator\QueryAggregatorInterface` object. This object is
|
|---|
| 892 | responsible for handling the aggregation of multi-valued query string variables into a flattened hash.
|
|---|
| 893 |
|
|---|
| 894 | 2.8 to 3.x
|
|---|
| 895 | ----------
|
|---|
| 896 |
|
|---|
| 897 | ### Guzzle\Service\Inspector
|
|---|
| 898 |
|
|---|
| 899 | Change `\Guzzle\Service\Inspector::fromConfig` to `\Guzzle\Common\Collection::fromConfig`
|
|---|
| 900 |
|
|---|
| 901 | **Before**
|
|---|
| 902 |
|
|---|
| 903 | ```php
|
|---|
| 904 | use Guzzle\Service\Inspector;
|
|---|
| 905 |
|
|---|
| 906 | class YourClient extends \Guzzle\Service\Client
|
|---|
| 907 | {
|
|---|
| 908 | public static function factory($config = array())
|
|---|
| 909 | {
|
|---|
| 910 | $default = array();
|
|---|
| 911 | $required = array('base_url', 'username', 'api_key');
|
|---|
| 912 | $config = Inspector::fromConfig($config, $default, $required);
|
|---|
| 913 |
|
|---|
| 914 | $client = new self(
|
|---|
| 915 | $config->get('base_url'),
|
|---|
| 916 | $config->get('username'),
|
|---|
| 917 | $config->get('api_key')
|
|---|
| 918 | );
|
|---|
| 919 | $client->setConfig($config);
|
|---|
| 920 |
|
|---|
| 921 | $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
|
|---|
| 922 |
|
|---|
| 923 | return $client;
|
|---|
| 924 | }
|
|---|
| 925 | ```
|
|---|
| 926 |
|
|---|
| 927 | **After**
|
|---|
| 928 |
|
|---|
| 929 | ```php
|
|---|
| 930 | use Guzzle\Common\Collection;
|
|---|
| 931 |
|
|---|
| 932 | class YourClient extends \Guzzle\Service\Client
|
|---|
| 933 | {
|
|---|
| 934 | public static function factory($config = array())
|
|---|
| 935 | {
|
|---|
| 936 | $default = array();
|
|---|
| 937 | $required = array('base_url', 'username', 'api_key');
|
|---|
| 938 | $config = Collection::fromConfig($config, $default, $required);
|
|---|
| 939 |
|
|---|
| 940 | $client = new self(
|
|---|
| 941 | $config->get('base_url'),
|
|---|
| 942 | $config->get('username'),
|
|---|
| 943 | $config->get('api_key')
|
|---|
| 944 | );
|
|---|
| 945 | $client->setConfig($config);
|
|---|
| 946 |
|
|---|
| 947 | $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
|
|---|
| 948 |
|
|---|
| 949 | return $client;
|
|---|
| 950 | }
|
|---|
| 951 | ```
|
|---|
| 952 |
|
|---|
| 953 | ### Convert XML Service Descriptions to JSON
|
|---|
| 954 |
|
|---|
| 955 | **Before**
|
|---|
| 956 |
|
|---|
| 957 | ```xml
|
|---|
| 958 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 959 | <client>
|
|---|
| 960 | <commands>
|
|---|
| 961 | <!-- Groups -->
|
|---|
| 962 | <command name="list_groups" method="GET" uri="groups.json">
|
|---|
| 963 | <doc>Get a list of groups</doc>
|
|---|
| 964 | </command>
|
|---|
| 965 | <command name="search_groups" method="GET" uri='search.json?query="{{query}} type:group"'>
|
|---|
| 966 | <doc>Uses a search query to get a list of groups</doc>
|
|---|
| 967 | <param name="query" type="string" required="true" />
|
|---|
| 968 | </command>
|
|---|
| 969 | <command name="create_group" method="POST" uri="groups.json">
|
|---|
| 970 | <doc>Create a group</doc>
|
|---|
| 971 | <param name="data" type="array" location="body" filters="json_encode" doc="Group JSON"/>
|
|---|
| 972 | <param name="Content-Type" location="header" static="application/json"/>
|
|---|
| 973 | </command>
|
|---|
| 974 | <command name="delete_group" method="DELETE" uri="groups/{{id}}.json">
|
|---|
| 975 | <doc>Delete a group by ID</doc>
|
|---|
| 976 | <param name="id" type="integer" required="true"/>
|
|---|
| 977 | </command>
|
|---|
| 978 | <command name="get_group" method="GET" uri="groups/{{id}}.json">
|
|---|
| 979 | <param name="id" type="integer" required="true"/>
|
|---|
| 980 | </command>
|
|---|
| 981 | <command name="update_group" method="PUT" uri="groups/{{id}}.json">
|
|---|
| 982 | <doc>Update a group</doc>
|
|---|
| 983 | <param name="id" type="integer" required="true"/>
|
|---|
| 984 | <param name="data" type="array" location="body" filters="json_encode" doc="Group JSON"/>
|
|---|
| 985 | <param name="Content-Type" location="header" static="application/json"/>
|
|---|
| 986 | </command>
|
|---|
| 987 | </commands>
|
|---|
| 988 | </client>
|
|---|
| 989 | ```
|
|---|
| 990 |
|
|---|
| 991 | **After**
|
|---|
| 992 |
|
|---|
| 993 | ```json
|
|---|
| 994 | {
|
|---|
| 995 | "name": "Zendesk REST API v2",
|
|---|
| 996 | "apiVersion": "2012-12-31",
|
|---|
| 997 | "description":"Provides access to Zendesk views, groups, tickets, ticket fields, and users",
|
|---|
| 998 | "operations": {
|
|---|
| 999 | "list_groups": {
|
|---|
| 1000 | "httpMethod":"GET",
|
|---|
| 1001 | "uri": "groups.json",
|
|---|
| 1002 | "summary": "Get a list of groups"
|
|---|
| 1003 | },
|
|---|
| 1004 | "search_groups":{
|
|---|
| 1005 | "httpMethod":"GET",
|
|---|
| 1006 | "uri": "search.json?query=\"{query} type:group\"",
|
|---|
| 1007 | "summary": "Uses a search query to get a list of groups",
|
|---|
| 1008 | "parameters":{
|
|---|
| 1009 | "query":{
|
|---|
| 1010 | "location": "uri",
|
|---|
| 1011 | "description":"Zendesk Search Query",
|
|---|
| 1012 | "type": "string",
|
|---|
| 1013 | "required": true
|
|---|
| 1014 | }
|
|---|
| 1015 | }
|
|---|
| 1016 | },
|
|---|
| 1017 | "create_group": {
|
|---|
| 1018 | "httpMethod":"POST",
|
|---|
| 1019 | "uri": "groups.json",
|
|---|
| 1020 | "summary": "Create a group",
|
|---|
| 1021 | "parameters":{
|
|---|
| 1022 | "data": {
|
|---|
| 1023 | "type": "array",
|
|---|
| 1024 | "location": "body",
|
|---|
| 1025 | "description":"Group JSON",
|
|---|
| 1026 | "filters": "json_encode",
|
|---|
| 1027 | "required": true
|
|---|
| 1028 | },
|
|---|
| 1029 | "Content-Type":{
|
|---|
| 1030 | "type": "string",
|
|---|
| 1031 | "location":"header",
|
|---|
| 1032 | "static": "application/json"
|
|---|
| 1033 | }
|
|---|
| 1034 | }
|
|---|
| 1035 | },
|
|---|
| 1036 | "delete_group": {
|
|---|
| 1037 | "httpMethod":"DELETE",
|
|---|
| 1038 | "uri": "groups/{id}.json",
|
|---|
| 1039 | "summary": "Delete a group",
|
|---|
| 1040 | "parameters":{
|
|---|
| 1041 | "id":{
|
|---|
| 1042 | "location": "uri",
|
|---|
| 1043 | "description":"Group to delete by ID",
|
|---|
| 1044 | "type": "integer",
|
|---|
| 1045 | "required": true
|
|---|
| 1046 | }
|
|---|
| 1047 | }
|
|---|
| 1048 | },
|
|---|
| 1049 | "get_group": {
|
|---|
| 1050 | "httpMethod":"GET",
|
|---|
| 1051 | "uri": "groups/{id}.json",
|
|---|
| 1052 | "summary": "Get a ticket",
|
|---|
| 1053 | "parameters":{
|
|---|
| 1054 | "id":{
|
|---|
| 1055 | "location": "uri",
|
|---|
| 1056 | "description":"Group to get by ID",
|
|---|
| 1057 | "type": "integer",
|
|---|
| 1058 | "required": true
|
|---|
| 1059 | }
|
|---|
| 1060 | }
|
|---|
| 1061 | },
|
|---|
| 1062 | "update_group": {
|
|---|
| 1063 | "httpMethod":"PUT",
|
|---|
| 1064 | "uri": "groups/{id}.json",
|
|---|
| 1065 | "summary": "Update a group",
|
|---|
| 1066 | "parameters":{
|
|---|
| 1067 | "id": {
|
|---|
| 1068 | "location": "uri",
|
|---|
| 1069 | "description":"Group to update by ID",
|
|---|
| 1070 | "type": "integer",
|
|---|
| 1071 | "required": true
|
|---|
| 1072 | },
|
|---|
| 1073 | "data": {
|
|---|
| 1074 | "type": "array",
|
|---|
| 1075 | "location": "body",
|
|---|
| 1076 | "description":"Group JSON",
|
|---|
| 1077 | "filters": "json_encode",
|
|---|
| 1078 | "required": true
|
|---|
| 1079 | },
|
|---|
| 1080 | "Content-Type":{
|
|---|
| 1081 | "type": "string",
|
|---|
| 1082 | "location":"header",
|
|---|
| 1083 | "static": "application/json"
|
|---|
| 1084 | }
|
|---|
| 1085 | }
|
|---|
| 1086 | }
|
|---|
| 1087 | }
|
|---|
| 1088 | ```
|
|---|
| 1089 |
|
|---|
| 1090 | ### Guzzle\Service\Description\ServiceDescription
|
|---|
| 1091 |
|
|---|
| 1092 | Commands are now called Operations
|
|---|
| 1093 |
|
|---|
| 1094 | **Before**
|
|---|
| 1095 |
|
|---|
| 1096 | ```php
|
|---|
| 1097 | use Guzzle\Service\Description\ServiceDescription;
|
|---|
| 1098 |
|
|---|
| 1099 | $sd = new ServiceDescription();
|
|---|
| 1100 | $sd->getCommands(); // @returns ApiCommandInterface[]
|
|---|
| 1101 | $sd->hasCommand($name);
|
|---|
| 1102 | $sd->getCommand($name); // @returns ApiCommandInterface|null
|
|---|
| 1103 | $sd->addCommand($command); // @param ApiCommandInterface $command
|
|---|
| 1104 | ```
|
|---|
| 1105 |
|
|---|
| 1106 | **After**
|
|---|
| 1107 |
|
|---|
| 1108 | ```php
|
|---|
| 1109 | use Guzzle\Service\Description\ServiceDescription;
|
|---|
| 1110 |
|
|---|
| 1111 | $sd = new ServiceDescription();
|
|---|
| 1112 | $sd->getOperations(); // @returns OperationInterface[]
|
|---|
| 1113 | $sd->hasOperation($name);
|
|---|
| 1114 | $sd->getOperation($name); // @returns OperationInterface|null
|
|---|
| 1115 | $sd->addOperation($operation); // @param OperationInterface $operation
|
|---|
| 1116 | ```
|
|---|
| 1117 |
|
|---|
| 1118 | ### Guzzle\Common\Inflection\Inflector
|
|---|
| 1119 |
|
|---|
| 1120 | Namespace is now `Guzzle\Inflection\Inflector`
|
|---|
| 1121 |
|
|---|
| 1122 | ### Guzzle\Http\Plugin
|
|---|
| 1123 |
|
|---|
| 1124 | Namespace is now `Guzzle\Plugin`. Many other changes occur within this namespace and are detailed in their own sections below.
|
|---|
| 1125 |
|
|---|
| 1126 | ### Guzzle\Http\Plugin\LogPlugin and Guzzle\Common\Log
|
|---|
| 1127 |
|
|---|
| 1128 | Now `Guzzle\Plugin\Log\LogPlugin` and `Guzzle\Log` respectively.
|
|---|
| 1129 |
|
|---|
| 1130 | **Before**
|
|---|
| 1131 |
|
|---|
| 1132 | ```php
|
|---|
| 1133 | use Guzzle\Common\Log\ClosureLogAdapter;
|
|---|
| 1134 | use Guzzle\Http\Plugin\LogPlugin;
|
|---|
| 1135 |
|
|---|
| 1136 | /** @var \Guzzle\Http\Client */
|
|---|
| 1137 | $client;
|
|---|
| 1138 |
|
|---|
| 1139 | // $verbosity is an integer indicating desired message verbosity level
|
|---|
| 1140 | $client->addSubscriber(new LogPlugin(new ClosureLogAdapter(function($m) { echo $m; }, $verbosity = LogPlugin::LOG_VERBOSE);
|
|---|
| 1141 | ```
|
|---|
| 1142 |
|
|---|
| 1143 | **After**
|
|---|
| 1144 |
|
|---|
| 1145 | ```php
|
|---|
| 1146 | use Guzzle\Log\ClosureLogAdapter;
|
|---|
| 1147 | use Guzzle\Log\MessageFormatter;
|
|---|
| 1148 | use Guzzle\Plugin\Log\LogPlugin;
|
|---|
| 1149 |
|
|---|
| 1150 | /** @var \Guzzle\Http\Client */
|
|---|
| 1151 | $client;
|
|---|
| 1152 |
|
|---|
| 1153 | // $format is a string indicating desired message format -- @see MessageFormatter
|
|---|
| 1154 | $client->addSubscriber(new LogPlugin(new ClosureLogAdapter(function($m) { echo $m; }, $format = MessageFormatter::DEBUG_FORMAT);
|
|---|
| 1155 | ```
|
|---|
| 1156 |
|
|---|
| 1157 | ### Guzzle\Http\Plugin\CurlAuthPlugin
|
|---|
| 1158 |
|
|---|
| 1159 | Now `Guzzle\Plugin\CurlAuth\CurlAuthPlugin`.
|
|---|
| 1160 |
|
|---|
| 1161 | ### Guzzle\Http\Plugin\ExponentialBackoffPlugin
|
|---|
| 1162 |
|
|---|
| 1163 | Now `Guzzle\Plugin\Backoff\BackoffPlugin`, and other changes.
|
|---|
| 1164 |
|
|---|
| 1165 | **Before**
|
|---|
| 1166 |
|
|---|
| 1167 | ```php
|
|---|
| 1168 | use Guzzle\Http\Plugin\ExponentialBackoffPlugin;
|
|---|
| 1169 |
|
|---|
| 1170 | $backoffPlugin = new ExponentialBackoffPlugin($maxRetries, array_merge(
|
|---|
| 1171 | ExponentialBackoffPlugin::getDefaultFailureCodes(), array(429)
|
|---|
| 1172 | ));
|
|---|
| 1173 |
|
|---|
| 1174 | $client->addSubscriber($backoffPlugin);
|
|---|
| 1175 | ```
|
|---|
| 1176 |
|
|---|
| 1177 | **After**
|
|---|
| 1178 |
|
|---|
| 1179 | ```php
|
|---|
| 1180 | use Guzzle\Plugin\Backoff\BackoffPlugin;
|
|---|
| 1181 | use Guzzle\Plugin\Backoff\HttpBackoffStrategy;
|
|---|
| 1182 |
|
|---|
| 1183 | // Use convenient factory method instead -- see implementation for ideas of what
|
|---|
| 1184 | // you can do with chaining backoff strategies
|
|---|
| 1185 | $backoffPlugin = BackoffPlugin::getExponentialBackoff($maxRetries, array_merge(
|
|---|
| 1186 | HttpBackoffStrategy::getDefaultFailureCodes(), array(429)
|
|---|
| 1187 | ));
|
|---|
| 1188 | $client->addSubscriber($backoffPlugin);
|
|---|
| 1189 | ```
|
|---|
| 1190 |
|
|---|
| 1191 | ### Known Issues
|
|---|
| 1192 |
|
|---|
| 1193 | #### [BUG] Accept-Encoding header behavior changed unintentionally.
|
|---|
| 1194 |
|
|---|
| 1195 | (See #217) (Fixed in 09daeb8c666fb44499a0646d655a8ae36456575e)
|
|---|
| 1196 |
|
|---|
| 1197 | In version 2.8 setting the `Accept-Encoding` header would set the CURLOPT_ENCODING option, which permitted cURL to
|
|---|
| 1198 | properly handle gzip/deflate compressed responses from the server. In versions affected by this bug this does not happen.
|
|---|
| 1199 | See issue #217 for a workaround, or use a version containing the fix.
|
|---|