class SaloonManager

Properties

protected MiddlewarePipeline $middleware

The middleware applied to every Saloon request.

protected null|PendingRequest): ?string $cacheScopeResolver

The cache scope resolver.

protected string|null $fixturePath

The tests-only fixture path override.

protected bool|null $throwOnMissingFixtures

The tests-only missing fixture behavior override.

protected MockClient|null $mockClient

The tests-only global mock client.

Methods

__construct(Sender $sender, Factory $cache, RateLimiter $rateLimiter, Repository $config, Dispatcher $events)

Create the Saloon manager.

send(Connector $connector, Request $request, MockClient|null $mockClient = null)

Send a request through a connector.

sender()

Get the Saloon sender.

cache()

Get the cache factory.

rateLimiter()

Get the rate limiter manager.

middleware()

Get the global middleware pipeline.

fake(array|MockClient $responses = [])

Replace the global mock client.

MockClient|null
mockClient()

Get the global mock client.

clearFake()

Clear the global mock client.

void
assertSent(string|callable $value)

Assert that a matching request was sent.

void
assertNotSent(string|callable $value)

Assert that no matching request was sent.

void
assertSentInOrder(array $callbacks)

Assert that requests were sent in order.

void
assertNothingSent()

Assert that nothing was sent.

void
assertSentCount(int $count, string|null $requestClass = null)

Assert the number of recorded requests.

resolveCacheScopeUsing(Closure|null $resolver)

Register the cache scope resolver.

string|null
resolveCacheScope(PendingRequest $pendingRequest)

Resolve the cache scope for the request.

fixturePath(string $path)

Set the fixture storage path.

string
getFixturePath()

Get the fixture storage path.

throwOnMissingFixtures(bool $throw = true)

Configure missing fixture behavior.

bool
throwsOnMissingFixtures()

Determine if missing fixtures should throw.

void
sleepMilliseconds(int $milliseconds)

Sleep for a checked number of milliseconds.

array
resolveCache(PendingRequest $pendingRequest, array $transport)

Resolve the cache store and bounded key for an operation.

void
enforceRateLimits(PendingRequest $pendingRequest)

Enforce connector and request rate limits before transport.

void
enforceRateLimitsFor(PendingRequest $pendingRequest, Connector|Request $resource)

Enforce one rate-limited resource.

void
recordRateLimitCooldowns(PendingRequest $pendingRequest, Response $response)

Record connector and request cooldowns from a transport response.

void
recordRateLimitCooldownFor(PendingRequest $pendingRequest, Response $response, Connector|Request $resource)

Record one resource's response-derived cooldown.

rateLimiterFor(Connector|Request $resource)

Resolve the framework limiter selected by a resource.

void
waitForRateLimit(Connector|Request $resource, AdmissionPolicy|Cooldown $policy, Decision $result)

Wait for a denied policy or throw its result.

Details

at line 73
__construct(Sender $sender, Factory $cache, RateLimiter $rateLimiter, Repository $config, Dispatcher $events)

Create the Saloon manager.

Parameters

Sender $sender
Factory $cache
RateLimiter $rateLimiter
Repository $config
Dispatcher $events

at line 90
Response send(Connector $connector, Request $request, MockClient|null $mockClient = null)

Send a request through a connector.

Parameters

Connector $connector
Request $request
MockClient|null $mockClient

Return Value

Response

at line 255
Sender sender()

Get the Saloon sender.

Return Value

Sender

at line 263
Factory cache()

Get the cache factory.

Return Value

Factory

at line 271
RateLimiter rateLimiter()

Get the rate limiter manager.

Return Value

RateLimiter

at line 282
MiddlewarePipeline middleware()

Get the global middleware pipeline.

Boot-only. Middleware added to this pipeline persists on the manager for the worker lifetime and affects every subsequent Saloon request.

Return Value

MiddlewarePipeline

at line 295
MockClient fake(array|MockClient $responses = [])

Replace the global mock client.

Tests only. The client persists on the manager until the test application is destroyed or clearFake() is called.

Parameters

array|MockClient $responses

Return Value

MockClient

at line 305
MockClient|null mockClient()

Get the global mock client.

Return Value

MockClient|null

at line 318
SaloonManager clearFake()

Clear the global mock client.

Tests only. This immediately removes the recorder for every subsequent Saloon request in the worker.

Return Value

SaloonManager

at line 328
void assertSent(string|callable $value)

Assert that a matching request was sent.

Parameters

string|callable $value

Return Value

void

at line 336
void assertNotSent(string|callable $value)

Assert that no matching request was sent.

Parameters

string|callable $value

Return Value

void

at line 346
void assertSentInOrder(array $callbacks)

Assert that requests were sent in order.

Parameters

array $callbacks

Return Value

void

at line 354
void assertNothingSent()

Assert that nothing was sent.

Return Value

void

at line 364
void assertSentCount(int $count, string|null $requestClass = null)

Assert the number of recorded requests.

Parameters

int $count
string|null $requestClass

Return Value

void

at line 377
SaloonManager resolveCacheScopeUsing(Closure|null $resolver)

Register the cache scope resolver.

Boot-only. The callback persists on the manager for the worker lifetime and affects every subsequently cached Saloon request.

Parameters

Closure|null $resolver

Return Value

SaloonManager

at line 387
string|null resolveCacheScope(PendingRequest $pendingRequest)

Resolve the cache scope for the request.

Parameters

PendingRequest $pendingRequest

Return Value

string|null

at line 400
SaloonManager fixturePath(string $path)

Set the fixture storage path.

Tests only. The override persists on the manager until the test application is destroyed.

Parameters

string $path

Return Value

SaloonManager

at line 410
string getFixturePath()

Get the fixture storage path.

Return Value

string

at line 425
SaloonManager throwOnMissingFixtures(bool $throw = true)

Configure missing fixture behavior.

Tests only. The override persists on the manager until the test application is destroyed.

Parameters

bool $throw

Return Value

SaloonManager

at line 435
bool throwsOnMissingFixtures()

Determine if missing fixtures should throw.

Return Value

bool

at line 444
protected void sleepMilliseconds(int $milliseconds)

Sleep for a checked number of milliseconds.

Parameters

int $milliseconds

Return Value

void

at line 461
protected array resolveCache(PendingRequest $pendingRequest, array $transport)

Resolve the cache store and bounded key for an operation.

Parameters

PendingRequest $pendingRequest
array $transport

Return Value

array

at line 484
protected void enforceRateLimits(PendingRequest $pendingRequest)

Enforce connector and request rate limits before transport.

Parameters

PendingRequest $pendingRequest

Return Value

void

at line 493
protected void enforceRateLimitsFor(PendingRequest $pendingRequest, Connector|Request $resource)

Enforce one rate-limited resource.

Parameters

PendingRequest $pendingRequest
Connector|Request $resource

Return Value

void

at line 543
protected void recordRateLimitCooldowns(PendingRequest $pendingRequest, Response $response)

Record connector and request cooldowns from a transport response.

Parameters

PendingRequest $pendingRequest
Response $response

Return Value

void

at line 552
protected void recordRateLimitCooldownFor(PendingRequest $pendingRequest, Response $response, Connector|Request $resource)

Record one resource's response-derived cooldown.

Parameters

PendingRequest $pendingRequest
Response $response
Connector|Request $resource

Return Value

void

at line 572
protected Limiter rateLimiterFor(Connector|Request $resource)

Resolve the framework limiter selected by a resource.

Parameters

Connector|Request $resource

Return Value

Limiter

at line 585
protected void waitForRateLimit(Connector|Request $resource, AdmissionPolicy|Cooldown $policy, Decision $result)

Wait for a denied policy or throw its result.

Parameters

Connector|Request $resource
AdmissionPolicy|Cooldown $policy
Decision $result

Return Value

void