Data providers are the core means to access external data. These are classes which use custom methods to access data.
Available data providers:
- Http - generic HTTP data provider
- Rest - data provider for REST-based APIs
- GraphQL - data provider for GraphQL APOIs
A DataProvider interface is used which defines the following common methods for data providers.
Return base URI to use for all data requests.
- Returns a string
Return URI to use for current data request
- Parameters
string|null $endpointOptional endpoint to append to base URI
- Returns a string
Return a unique identifier safe to use for caching based on the request
- Parameters
$uriURI for requestarray $contextArray of contextual data (e.g. request options)
- Returns a string
Whether errors are suppressed
- Returns a boolean
Return default decoder to decode responses.
- Returns an object of type
Strata\Data\Decode\DecoderInterfaceor null if no default decoder set
Decode a response
- Parameters
mixed $responseResponse to decode (normally an object or array)DecoderInterface|null $decoderOptional decoder, if not set uses getDefaultDecoder()
- Returns the decoded data (normally an array or object)
Is the cache enabled?
- Returns a boolean
Return the cache
- Returns an object of type
Strata\Data\Cache\DataCache
Adds an event listener that listens on the specified event. See events.
- Parameters
string $eventNameEvent namecallable $listenerThe listenerint $priorityThe higher this value, the earlier an event listener will be triggered in the chain (defaults to 0)
Adds an event subscriber. See events.
- Parameters
EventSubscriberInterface $subscriberEvent subscriber
Dispatches an event to all registered listeners
- Parameters
Event $eventThe event to pass to the event handlers/listenersstring $eventNameThe name of the event to dispatch
- Returns an object of type
Symfony\Contracts\EventDispatcher\Event