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.

UPGRADING.md 50 KiB

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