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.

createPendingRequest(Connector $connector, Request $request)

Prepare a request for sending through a connector.

inspectRateLimit(Connector|Request $resource, AdmissionPolicy|Cooldown $policy)

Inspect a connector or request rate limit without consuming it.

void
setEventDispatcher(Dispatcher $events)

Set the event dispatcher.

middleware()

Get the global middleware pipeline.

fake(array|MockClient $responses = [])

Add responses to the global mock client, or replace it with the given 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.

void
clearCache(Connector $connector, Request $request)

Clear the cached response for a request without sending it.

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.

string
limiterNameFor(Connector|Request $resource)

Resolve the limiter name used for a resource's limits and cooldowns.

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 80
__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 97
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 273
PendingRequest createPendingRequest(Connector $connector, Request $request)

Prepare a request for sending through a connector.

The pending request has run its plugins, authenticator, boot hooks and request middleware, in that order. It has not been finalized, matched against mock responses or sent.

Middleware is registered on the operation's own pipeline in this order: global middleware, plugin middleware, middleware added by the connector's boot method, the request's middleware, then middleware added by the request's boot method. Connectors are read-only, so connector middleware is registered from the boot method and still runs before the request's.

Parameters

Connector $connector
Request $request

Return Value

PendingRequest

at line 292
LimitResult|CooldownResult inspectRateLimit(Connector|Request $resource, AdmissionPolicy|Cooldown $policy)

Inspect a connector or request rate limit without consuming it.

Parameters

Connector|Request $resource
AdmissionPolicy|Cooldown $policy

Return Value

LimitResult|CooldownResult

at line 303
void setEventDispatcher(Dispatcher $events)

Set the event dispatcher.

On the shared manager, the dispatcher persists for the worker lifetime and receives every subsequent Saloon request event.

Parameters

Dispatcher $events

Return Value

void

at line 315
MiddlewarePipeline middleware()

Get the global middleware pipeline.

On the shared manager, middleware added to this pipeline persists for the worker lifetime and affects every subsequent Saloon request.

Return Value

MiddlewarePipeline

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

Add responses to the global mock client, or replace it with the given client.

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 343
MockClient|null mockClient()

Get the global mock client.

Return Value

MockClient|null

at line 356
SaloonManager clearFake()

Clear the global mock client.

On the shared manager, this immediately removes the recorder for every subsequent Saloon request in the worker.

Return Value

SaloonManager

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

Assert that a matching request was sent.

Parameters

string|callable $value

Return Value

void

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

Assert that no matching request was sent.

Parameters

string|callable $value

Return Value

void

at line 385
void assertSentInOrder(array $callbacks)

Assert that requests were sent in order.

Parameters

array $callbacks

Return Value

void

at line 393
void assertNothingSent()

Assert that nothing was sent.

Return Value

void

at line 403
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 420
SaloonManager resolveCacheScopeUsing(Closure|null $resolver)

Register the cache scope resolver.

On the shared manager, the callback persists for the worker lifetime and affects every subsequently cached Saloon request.

Parameters

Closure|null $resolver

Return Value

SaloonManager

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

Resolve the cache scope for the request.

Parameters

PendingRequest $pendingRequest

Return Value

string|null

at line 444
void clearCache(Connector $connector, Request $request)

Clear the cached response for a request without sending it.

The request is prepared as it is for sending, through its plugins, boot methods and middleware, so the same store, key and scope are resolved. Sending listeners do not run.

Parameters

Connector $connector
Request $request

Return Value

void

at line 462
SaloonManager fixturePath(string $path)

Set the fixture storage path.

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

Parameters

string $path

Return Value

SaloonManager

at line 473
string getFixturePath()

Get the fixture storage path.

Return Value

string

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

Configure missing fixture behavior.

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

Parameters

bool $throw

Return Value

SaloonManager

at line 499
bool throwsOnMissingFixtures()

Determine if missing fixtures should throw.

Return Value

bool

at line 508
protected void sleepMilliseconds(int $milliseconds)

Sleep for a checked number of milliseconds.

Parameters

int $milliseconds

Return Value

void

at line 526
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 549
protected void enforceRateLimits(PendingRequest $pendingRequest)

Enforce connector and request rate limits before transport.

Parameters

PendingRequest $pendingRequest

Return Value

void

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

Enforce one rate-limited resource.

Parameters

PendingRequest $pendingRequest
Connector|Request $resource

Return Value

void

at line 608
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 617
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 637
protected string limiterNameFor(Connector|Request $resource)

Resolve the limiter name used for a resource's limits and cooldowns.

Parameters

Connector|Request $resource

Return Value

string

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

Resolve the framework limiter selected by a resource.

Parameters

Connector|Request $resource

Return Value

Limiter

at line 658
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