class Client extends Client

A Client is used to communicate the Contentful Delivery API.

A Client is only responsible for one Space. When access to multiple spaces 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

Methods

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

Client constructor.

array
request(string $method, string $path, array $options = [])

No description

from Client
string
getUserAgentAppName()

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

string
getUserAgent()

Returns the value of the User-Agent header for any requests made to Contentful

from Client
static array
decodeJson(string $json)

No description

from Client
getAsset(string $id, string|null $locale = null)

No description

getAssets(Query $query = null)

No description

getContentType(string $id)

No description

getContentTypes(Query $query = null)

No description

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

No description

getEntries(Query $query = null)

No description

getSpace()

No description

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

Resolve a link to it's resource.

reviveJson(string $json)

Revive JSON previously cached.

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 71
__construct(string $token, string $spaceId, bool $preview = false, string|null $defaultLocale = null, array $options = [])

Client constructor.

Parameters

string $token
string $spaceId ID of the space 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 options. The following keys are possible: * guzzle Override the guzzle instance used by the Contentful client * logger Inject a Contentful logger * uriOverride Override the uri that is used to connect to the Contentful API (e.g. 'https://cdn.contentful.com/'). The trailing slash is required. * cacheDir Path to the cache directory to be used to read metadata. The client never writes to the cache, use the CLI to warm up the cache.

in Client at line 78
protected array request(string $method, string $path, array $options = [])

Parameters

string $method
string $path
array $options

Return Value

array

at line 107
protected string getUserAgentAppName()

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

Return Value

string

in Client at line 194
protected string getUserAgent()

Returns the value of the User-Agent header for any requests made to Contentful

Return Value

string

in Client at line 214
static array decodeJson(string $json)

Parameters

string $json JSON encoded object or array

Return Value

array

Exceptions

RuntimeException On invalid JSON

at line 120
Asset getAsset(string $id, string|null $locale = null)

Parameters

string $id
string|null $locale

Return Value

Asset

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

Parameters

Query $query

Return Value

ResourceArray

at line 155
ContentType getContentType(string $id)

Parameters

string $id

Return Value

ContentType

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

Parameters

Query $query

Return Value

ResourceArray

at line 192
EntryInterface getEntry(string $id, string|null $locale = null)

Parameters

string $id
string|null $locale

Return Value

EntryInterface

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

Parameters

Query $query

Return Value

ResourceArray

at line 225
Space getSpace()

Return Value

Space

Resolve a link to it's resource.

Parameters

Link $link
string|null $locale

Return Value

Asset|EntryInterface

Exceptions

InvalidArgumentException When encountering an unexpected link type.

at line 277
Asset|ContentType|DynamicEntry|Space|DeletedAsset|DeletedEntry|ResourceArray reviveJson(string $json)

Revive JSON previously cached.

Parameters

string $json

Return Value

Asset|ContentType|DynamicEntry|Space|DeletedAsset|DeletedEntry|ResourceArray

Exceptions

SpaceMismatchException When attempting to revive JSON belonging to a different space

at line 294
mixed syncRequest(array $queryData)

Internal method for \Contentful\Delivery\Synchronization\Manager

Parameters

array $queryData

Return Value

mixed

See also

\Contentful\Delivery\Synchronization\Manager

at line 309
bool isPreview()

Returns true when using the Preview API

Return Value

bool

See also

https://www.contentful.com/developers/docs/references/content-preview-api/#/reference Preview API Reference

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