New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guzzle v6 #1062
Conversation
Woohoo!!! |
Nice! |
Hey, Good work guys. I have a question / concern. How are you guys going to help the maintainers of the opensource projects which rely on guzzle. Is there any thoughts about it ? Thank you and good work moving to PSR-7. |
@mtdowling what is the reasoning for implementing your own PSR-7 codebase rather than relying on |
@harikt I think higher level libraries that use Guzzle that don't want to cause conflicts can use a similar strategy that we are using the in the AWS SDK for PHP v3: create your own client interface and use that interface in your project instead of relying on a specific version of Guzzle (or any other library).
@stof We considered using |
I have a few concerns about the event system going away. I have a CLI app that queries my company's API, and leverages Log/Retry Subscribers, as well as Before/After Events. Is there any documentation about the migration path for apps which rely on these Guzzle v5 features? |
3. Guzzle has a minimum PHP version requirement of PHP 5.4. Pull requests must | ||
not require a PHP version greater than PHP 5.4. | ||
not require a PHP version greater than PHP 5.4 unless the feature is only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/5.4/5.5/
Thank you @mtdowling for the explanations. |
Hey @skyzyx. I probably should write more docs around this. When using the middleware approach, you need to inject middleware functions into the client's HandlerStack. This should be done when creating a client by injecting a custom HandlerStack into the client using the
Logging and retries were added directly into Guzzle. // Create a handler stack that adds the default middlewares
// note that you can omit the default middlewares by just creating
// the HandlerStack directly.
$stack = GuzzleHttp\HandlerStack::create();
// Create a log middleware
$logger = create_my_psr_logger(); // implement this function
$formatter = new GuzzleHttp\MessageFormatter();
$middleware = GuzzleHttp\Middleware::log($logger, $formatter);
// Add the log middleware to the stack. You can just push to the end
// or unshift to the front of the stack. You can give middlewares names.
$stack->push($logger, 'my-logger');
// You can add middlewares before or after other middlewares by name
$retry = \GuzzleHttp\Middleware::retry(function ($retries, $request, $response, $exception) {
return false; // return true or false
});
$stack->before('my-logger', $retry);
// Create the client and use the handler stack you created.
$client = new GuzzleHttp\Client(['handler' => $stack]); Basically you build up the customizations you'll need when you create the client. If you need specific ad-hoc customizations, you can add a middleware that keys in on custom request options (because each middleware is passed in the request and array of request options). Alternatively, you can specify a custom handler when sending a request by adding a handler into the More documentation on handlers and middleware can be found here: https://github.com/guzzle/guzzle/blob/guzzle-v6/docs/handlers-and-middleware.rst |
[WIP] safe check uri_template extension
The branch has now been prepped for merging. I will be tagging and releasing Guzzle 6 tomorrow morning. |
Travis say
and I remembered the #1065. |
Guzzle now uses PSR-7 for HTTP messages.
Due to the fact that these messages are immutable, this prompted a
re-architecting of Guzzle to use a middleware based system rather than an
event system. Any HTTP message interaction (e.g.,
GuzzleHttp\Message\Request
)need to be updated to work with the new immutable PSR-7 request and response
objects. Any event listeners or subscribers need to be updated to become
middleware functions that wrap handlers (or are injected into a
GuzzleHttp\HandlerStack
.GuzzleHttp\BatchResults
GuzzleHttp\Collection
GuzzleHttp\HasDataTrait
GuzzleHttp\ToArrayInterface
guzzlehttp/streams
dependency has been removed. Stream functionalityis now present in the
GuzzleHttp\Psr7
namespace provided by theguzzlehttp/psr7
package.guzzlehttp/promises
library. We use a custom promise library for threesignificant reasons:
chaining and promise resolution will eventually blow the stack. Guzzle
promises are not recursive as they use a sort of trampolining technique.
Note: there has been movement in the React project to modify promises to
no longer utilize recursion.
wait for a result. Guzzle promises allows this functionality.
promises requiring wrapping react promises with RingPHP futures. This
overhead is no longer needed, reducing stack sizes, reducing complexity,
and improving performance.
GuzzleHttp\Mimetypes
has been moved to a function inGuzzleHttp\Psr7\mimetype_from_extension
andGuzzleHttp\Psr7\mimetype_from_filename
.GuzzleHttp\Query
andGuzzleHttp\QueryParser
have been removed. Querystrings must now be passed into request objects as strings, or provided to
the
query
request option when creating requests with clients. Thequery
option uses PHP's
http_build_query
to convert an array to a string. If youneed a different serialization technique, you will need to pass the query
string in as a string. There are a couple helper functions that will make
working with query strings easier:
GuzzleHttp\Psr7\parse_query
andGuzzleHttp\Psr7\build_query
.system based on PSR-7, using RingPHP and it's middleware system as well adds
more complexity than the benefits it provides. All HTTP handlers that were
present in RingPHP have been modified to work directly with PSR-7 messages
and placed in the
GuzzleHttp\Handler
namespace. This significantly reducescomplexity in Guzzle, removes a dependency, and improves performance. RingPHP
will be maintained for Guzzle 5 support, but will no longer be a part of
Guzzle 6.
integration has been removed. Note: while the event system has been removed,
if there is sufficient demand, it would be possible that a package could be
created that adds event support into the middleware system.
Event
namespace.Subscriber
namespace.Transaction
classRequestFsm
RingBridge
GuzzleHttp\Subscriber\Cookie
is now provided byGuzzleHttp\Middleware::cookies
GuzzleHttp\Subscriber\HttpError
is now provided byGuzzleHttp\Middleware::httpError
GuzzleHttp\Subscriber\History
is now provided byGuzzleHttp\Middleware::history
GuzzleHttp\Subscriber\Mock
is now provided byGuzzleHttp\Middleware::mock
GuzzleHttp\Subscriber\Prepare
is now provided byGuzzleHttp\PrepareBodyMiddleware
GuzzleHttp\Subscriber\Redirect
is now provided byGuzzleHttp\RedirectMiddleware
Psr\Http\Message\UriInterface
(implements inGuzzleHttp\Psr7\Uri
) for URI support.GuzzleHttp\Url
is now gone.GuzzleHttp\Utils
have been moved to namespacedfunctions under the
GuzzleHttp
namespace. This requires either a Composerbased autoloader or you to include functions.php.