packagist saloonphp/saloon v1.2.0
Version v1.2.0 - More SDK Tools

latest releases: v3.x-dev, v3.10.0, v3.9.1...
2 years ago

Previously you could define custom methods on the connector to call requests in Saloon, like so:

protected array $requests = [
    'getMyUser' => UserRequest::class,
    ErrorRequest::class,
];

This was pretty limited as you couldn't define "groups" of requests.

This PR introduces an extension to this API and now you can define an array of requests, keyed for a collection or a custom "RequestCollection" which is a class that extends the base "RequestCollection" class and can have completely custom methods inside. You will also have access to the connector.

Define groups of requests

$connector->user()->get()

protected array $requests = [
    'user' => [
        'get' => UserRequest::class,
    ],
];

Define custom request collections

$connector->user()->get()

protected array $requests = [
    'user' => UserCollection::class,
];
class UserCollection extends RequestCollection
{
    public function get(): SaloonRequest
    {
        return $this->connector->request(new UserRequest);
    }
}

What's Changed

Full Changelog: v1.1.0...v1.2.0

Don't miss a new saloon release

NewReleases is sending notifications on new releases.