Upgrading from v2
Last updated
Last updated
Saloon version three comes with many improvements over version two, but most of the improvements were internal changes, so the upgrade to v3 from v2 shouldn't be too cumbersome. If you haven't already, it's recommended to read through to get an idea of what has changed before making the upgrade.
First of all, you should bump Saloon to the next major version in your composer.json
file. You should also update any of the following plugins if you have them installed.
saloonphp/saloon
to ^3.0
saloonphp/laravel-plugin
to ^3.0
saloonphp/cache-plugin
to ^3.0
saloonphp/laravel-http-sender
to ^2.0
saloonphp/rate-limit-plugin
to ^2.0
saloonphp/pagination-plugin
to ^2.0
After that, make sure to run the following command to update your composer.lock
file and your vendor
directory.
High-impact changes will most likely be things that everyone needs to update.
From version three, Saloon uses Guzzle ^7.6
which introduced a new option to configure a minimum TLS version. With Saloon v3, Saloon has set this default to TLS 1.2. If any of your API integrations require a lower level of TLS security, you can change the Saloon config while your application is loading.
Previously, Saloon's Config
and MockConfig
classes lived in a Saloon\Helpers
directory. These classes have now been moved to the root Saloon
namespace. You should update your use
statements to the new namespace.
use Saloon\Helpers\Config
use Saloon\Config
use Saloon\Helpers\MockConfig
use Saloon\MockConfig
Another decision that was made was to backtrack on the interfaces that were added in Saloon v2. This may not affect your integration, but a lot of the code examples and recommendations in v2 suggested using the contracts instead of the abstract classes, so you may have a few places in your application where you have imported the interface and not the class. You should find and replace the following main interfaces.
use Saloon\Contracts\Connector
use Saloon\Http\Connector
use Saloon\Contracts\Request
use Saloon\Http\Request
use Saloon\Contracts\PendingRequest
use Saloon\Http\PendingRequest
use Saloon\Contracts\Response
use Saloon\Http\Response
During some of the code review to improve readability, the HasBody
body trait has been renamed to HasStringBody
to be more explicit. If any of your requests send a plain string body, you should find and replace this trait.
use Saloon\Traits\Body\HasBody
use Saloon\Traits\Body\HasStringBody
use HasBody
use HasStringBody
Medium-impact changes are changes that come up for some people but not others.
The second argument of the $connector->sendAndRetry()
method has been renamed from maxAttempts
to tries
. If you are using named arguments then you will need to replace this name.
If you previously used the handleRetry
argument when using $connector->sendAndRetry()
- Saloon will now send an instance of Request
instead of PendingRequest
through the closure.
With version three, some of the methods in the Saloon\Config
class have been renamed. These changes have been listed below and you should make sure to rename them if you have used them in your application.
Config::middleware()
Config::globalMiddleware()
Config::resetMiddleware()
Config::clearGlobalMiddleware()
Config::resolveSenderWith()
Config::setSenderResolver()
Config::setDefaultSender()
Config::$defaultSender =
Low-impact changes are changes that are unlikely to come up unless you have overwritten some of Saloon's functionality or used its interfaces. It's still worth looking through to make sure you haven't missed anything.
On the MockResponse
class Saloon had a few methods which have now been renamed to be more consistent with the rest of Saloon. These changes are:
getBody()
has changed to body()
getHeaders()
has changed to headers()
getStatus()
has changed to status()
Saloon v3 introduced the ability to reorder middleware. With this, the old prepend
argument on middleware methods has been replaced with a pipeOrder
argument. Additionally, the second argument for the middleware is now name
.
The following methods have now been removed from the PendingRequest
class. You can use the suggested replacement if you are using them in your application.
$pendingRequest->send()
$pendingRequest->getConnector()->send()
$pendingRequest->sendAsync()
$pendingRequest->getConnector()->sendAsync()
$pendingRequest->getSender()
$pendingRequest->getConnector()->sender()
Previously, Saloon's PendingRequest
and middleware would be invoked before an asynchronous request was sent (using $connector->sendAsync()
) - now Saloon has fixed this issue and the PendingRequest
and middleware will only be invoked while the Promise
is being resolved - at the same time as sending the request. If your application depended on the old way the middleware was invoked you should make sure your application isn't affected by this change.
Previously, the MockResponse
would extend a class called SimulatedResponsePayload
. This class has now been renamed to FakeResponse
. Additionally, methods on the PendingRequest
like $pendingRequest->setSimulatedResponsePayload()
has been renamed to $pendingRequest->setFakeResponse()
. If you were extending the old class or using the methods to set the fake response in middleware, you should rename these methods.
The Sender
interface has been completely rewritten in Saloon v3. Instead of just the sendRequest
method. You now have to define three methods. If you have made a custom sender in Saloon, you should make sure this is updated.
Saloon v2 shipped with a simple Date
helper class that wrapped around PHP's DateTime
classes. This has now been removed in Saloon v3.
Saloon v2 shipped with a few helpers to reduce dependencies. The Str
and Arr
helper methods have been renamed to StringHelpers
and ArrayHelpers
respectively to prevent accidental imports when using Laravel. Saloon's internal helper classes have also been declared final
as these shouldn't be extended or used by your application.
As mentioned above, Saloon v3 removes a lot of interfaces that weren't adding value to the library. Alongside the ones mentioned above, these other interfaces have been removed.
If you have made your own BodyRepository
class from the base class and relied on the __toString
method this has now been removed. Additionally, the interface has been updated and now requires a toStream()
method. Inside here, you must define how to convert your body type into a Stream using the provided StreamFactory
.
The old Timeout
enum has now been removed. If your application used to use this method, you should migrate to use Config::$defaultConnectionTimeout
and Config::$defaultRequestTimeout
.
Previously, the MultipartValue
object had a toArray
method. Now that all body repositories are converted into Streams, this method is no longer required.
The SimulatedSender
class which would be used if you were mocking or had a cached response has now been removed.
You can to see the different TLS options available.
With version three, paginators are no longer included in the core Saloon library and have been moved to a plugin. Additionally, the paginators have been completely rebuilt. Review if you have used any of the pagination functionality and follow the new to rebuild them in the new way.
If we forgot to add something to this upgrade please let us know by .