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.

$this
setApplication(string|null $name, string|null $version = null)

Set the application name and version. The values are used as part of the X-Contentful-User-Agent header.

from Client
$this
setIntegration(string|null $name, string|null $version = null)

Set the integration name and version. The values are used as part of the X-Contentful-User-Agent header.

from Client
array|null
request(string $method, string $path, array $options = [])

No description

from Client
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.

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 72
__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 80
$this setApplication(string|null $name, string|null $version = null)

Set the application name and version. The values are used as part of the X-Contentful-User-Agent header.

Parameters

string|null $name
string|null $version

Return Value

$this

in Client at line 95
$this setIntegration(string|null $name, string|null $version = null)

Set the integration name and version. The values are used as part of the X-Contentful-User-Agent header.

Parameters

string|null $name
string|null $version

Return Value

$this

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

Parameters

string $method
string $path
array $options

Return Value

array|null

at line 108
protected string getSdkName()

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

Return Value

string

at line 118
protected string getSdkVersion()

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

Return Value

string

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

Parameters

string $id
string|null $locale

Return Value

Asset

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

Parameters

Query $query

Return Value

ResourceArray

at line 167
ContentType getContentType(string $id)

Parameters

string $id

Return Value

ContentType

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

Parameters

Query $query

Return Value

ResourceArray

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

Parameters

string $id
string|null $locale

Return Value

EntryInterface

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

Parameters

Query $query

Return Value

ResourceArray

at line 239
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 291
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 308
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 323
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 337
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