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[]
getExceptionMap()

No description

from Client
getLogger()

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.

string
getApiContentType()

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

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 113
protected array|null request(string $method, string $path, array $options = [])

Parameters

string $method The HTTP method
string $path The URI path
array $options An array of optional parameters. The following keys are accepted: * query An array of query parameters that will be appended to the URI * additionalHeaders An array of headers that will be added to the request * body The request body * baseUri A string that can be used to override the default client base URI

Return Value

array|null

in Client at line 229
protected string[] getExceptionMap()

Return Value

string[]

in Client at line 242
LoggerInterface getLogger()

Return Value

LoggerInterface

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 128
protected string getApiContentType()

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

Return Value

string

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

Parameters

string $id
string|null $locale

Return Value

Asset

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

Parameters

Query $query

Return Value

ResourceArray

at line 177
ContentType getContentType(string $id)

Parameters

string $id

Return Value

ContentType

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

Parameters

Query $query

Return Value

ResourceArray

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

Parameters

string $id
string|null $locale

Return Value

EntryInterface

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

Parameters

Query $query

Return Value

ResourceArray

at line 249
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 301
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 318
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 333
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 347
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