You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1253 lines
52 KiB

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