FailSoftReadTrait
Read contract of the repository layer above `ApiBridge`.
On denial internalAction*() returns Result::failure(PERMISSION_DENIED)->toArray(), but repository
find(), findBy() and findAll() promise data, not an operation result; their callers
(mapper, component, template) read ['items'] or ['id'], or pass it straight to the hydrator.
A failed envelope then acts as a valid but meaningless record: a TypeError in the hydrator
(Payment::setCode(?string) gets an int from the code key), or a silent empty page with no
log line outside it. This trait turns both into one predictable behavior: no data, plus an
API_FAILSOFT line in the auth channel.
The logic is not in ApiBridge because the bridge also serves the write contract
(SaveTrait, DeleteTrait, TreeTrait, RegisterEventTrait), where the failure
envelope is the wanted return value (many callers outside the Api layer read ['success']).
The bridge must not rewrite the envelope; the decision that it should have been data belongs to
the repository read methods.
Tags
Table of Contents
Methods
- failSoftRead() : array<string|int, mixed>
- Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
Methods
failSoftRead()
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
protected
failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>
NOTE: it does not log on purpose. ApiBridge::call(), which sees both the
endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second
copy would turn one failure into three lines in auth.log.
Parameters
- $response : mixed
- $endpoint : string
-
only for call readability; the log takes the endpoint from the bridge