class Client extends BaseClient

A Client is used to communicate the Contentful Delivery API.

A Client is only responsible for one space and one environment. When access to multiple spaces or environments is required, create multiple Clients.

This class can be configured to use the Preview API instead of the Delivery API. This grants access to not yet published content.

Constants

VERSION

API_DELIVERY

API_PREVIEW

URI_DELIVERY

The URI for the Delivery API.

URI_PREVIEW

The URI for the Preview API.

Methods

__construct(string $token, string $spaceId, string $environmentId = 'master', bool $preview = false, string|null $defaultLocale = null, array $options = [])

Client constructor.

getApi()

{@inheritdoc}

string
getSdkName()

The name of the library to be used in the User-Agent header.

string
getSdkVersion()

The version of the library to be used in the User-Agent header.

string
getApiContentType()

Returns the Content-Type (MIME-Type) to be used when communication with the API.

getInstanceRepository()

Returns the instance repository currently in use.

getAsset(string $assetId, string|null $locale = null)

No description

ResourceArray
getAssets(Query $query = null)

No description

getContentType(string $contentTypeId)

No description

ResourceArray
getContentTypes(Query $query = null)

No description

getEnvironment()

No description

getEntry(string $entryId, string|null $locale = null)

No description

ResourceArray
getEntries(Query $query = null)

No description

getSpace()

No description

resolveLink(Link $link, string|null $locale = null)

Resolve a link to it's resource.

ResourceInterface|ResourceArray
parseJson(string $json)

Parse a JSON string.

string|null
extractEnvironmentId(array $data)

Checks a data structure and extracts the environment ID, if present.

mixed
syncRequest(array $queryData)

Internal method for \Contentful\Delivery\Synchronization\Manager.

bool
isPreview()

Returns true when using the Preview API.

getSynchronizationManager()

Get an instance of the synchronization manager. Note that with the Preview API only an inital sync is giving valid results.

Details

at line 112
__construct(string $token, string $spaceId, string $environmentId = 'master', bool $preview = false, string|null $defaultLocale = null, array $options = [])

Client constructor.

Parameters

string $token Delivery API Access Token for the space used with this Client
string $spaceId ID of the space used with this Client
string $environmentId ID of the environment used with this Client
bool $preview true to use the Preview API
string|null $defaultLocale The default is to fetch the Space's default locale. Set to a locale string, e.g. "en-US" to fetch content in that locale. Set it to "*" to fetch content in all locales.
array $options An array of optional configuration. The following options are available: * guzzle Override the guzzle instance used by the Contentful client * logger A PSR-3 logger * baseUri Override the uri that is used to connect to the Contentful API (e.g. 'https://cdn.contentful.com/'). * cache Null or a PSR-6 cache item pool. The client only writes to the cache if autoWarmup is true, otherwise, you are responsible for warming it up using \Contentful\Delivery\Cache\CacheWarmer. * autoWarmup Warm up the cache automatically

at line 156
getApi()

{@inheritdoc}

at line 164
ResourceBuilder getResourceBuilder()

Return Value

ResourceBuilder

at line 174
protected string getSdkName()

The name of the library to be used in the User-Agent header.

Return Value

string

at line 184
protected string getSdkVersion()

The version of the library to be used in the User-Agent header.

Return Value

string

at line 194
protected string getApiContentType()

Returns the Content-Type (MIME-Type) to be used when communication with the API.

Return Value

string

at line 204
InstanceRepository getInstanceRepository()

Returns the instance repository currently in use.

Return Value

InstanceRepository

at line 231
Asset getAsset(string $assetId, string|null $locale = null)

Parameters

string $assetId
string|null $locale

Return Value

Asset

at line 248
ResourceArray getAssets(Query $query = null)

Parameters

Query $query

Return Value

ResourceArray

at line 266
ContentType getContentType(string $contentTypeId)

Parameters

string $contentTypeId

Return Value

ContentType

at line 281
ResourceArray getContentTypes(Query $query = null)

Parameters

Query $query

Return Value

ResourceArray

at line 292
Environment getEnvironment()

Return Value

Environment

at line 321
Entry getEntry(string $entryId, string|null $locale = null)

Parameters

string $entryId
string|null $locale

Return Value

Entry

at line 338
ResourceArray getEntries(Query $query = null)

Parameters

Query $query

Return Value

ResourceArray

at line 354
Space getSpace()

Return Value

Space

Resolve a link to it's resource.

Parameters

Link $link
string|null $locale

Return Value

Asset|Entry

Exceptions

InvalidArgumentException when encountering an unexpected link type

at line 404
ResourceInterface|ResourceArray parseJson(string $json)

Parse a JSON string.

Parameters

string $json

Return Value

ResourceInterface|ResourceArray

Exceptions

InvalidArgumentException When attempting to parse JSON belonging to a different space

at line 467
string|null extractEnvironmentId(array $data)

Checks a data structure and extracts the environment ID, if present.

Parameters

array $data

Return Value

string|null

at line 504
mixed syncRequest(array $queryData)

Internal method for \Contentful\Delivery\Synchronization\Manager.

Parameters

array $queryData

Return Value

mixed

at line 516
bool isPreview()

Returns true when using the Preview API.

Return Value

bool

at line 529
Manager getSynchronizationManager()

Get an instance of the synchronization manager. Note that with the Preview API only an inital sync is giving valid results.

Return Value

Manager

See also

https://www.contentful.com/developers/docs/concepts/sync/ Sync API