class Client extends BaseClient implements ClientInterface, SynchronizationClientInterface, JsonDecoderClientInterface

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

MAX_DEPTH

API_DELIVERY

API_PREVIEW

URI_DELIVERY

The URI for the Delivery API.

URI_PREVIEW

The URI for the Preview API.

Properties

protected int $currentDepth

Methods

__construct(string $token, string $spaceId, string $environmentId = 'master', ClientOptions $options = null)

Client constructor.

getApi()

Returns a string representation of the API currently in use.

getSpaceId()

Returns the ID of the space currently in use.

getEnvironmentId()

Returns the ID of the environment currently in use.

getResourceBuilder()

No description

getRichTextParser()

No description

static 
getSdkName()

{@inheritdoc}

static 
getPackageName()

{@inheritdoc}

static 
getApiContentType()

{@inheritdoc}

getResourcePool()

Returns the resource pool currently in use.

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

Returns a single Asset object corresponding to the given ID.

ResourceArray|Asset[]
getAssets(Query $query = null)

Returns a collection of Asset objects wrapped in a ResourceArray instance.

getContentType(string $contentTypeId)

Returns a single ContentType object corresponding to the given ID.

ResourceArray|ContentType[]
getContentTypes(Query $query = null)

Returns a collection of ContentType objects wrapped in a ResourceArray instance.

getEnvironment()

Returns the Environment object corresponding to the one in use.

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

Returns a single Entry object corresponding to the given ID.

getTag(string $tagId)

Find a specific tag by its id.

Tag[]
getAllTags()

Returns all tags in the current space and environment.

ResourceArray|Entry[]
getEntries(Query $query = null)

Returns a collection of Entry objects wrapped in a ResourceArray instance.

getSpace()

Returns the Space object corresponding to the one in use.

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

Resolve a link to its actual resource.

ResourceInterface[]
resolveLinkCollection(array $links, string $locale = null)

Resolves an array of links.

ResourceInterface|ResourceArray
parseJson(string $json)

Parse a JSON string.

isDeliveryApi()

Returns true when using the Delivery API.

isPreviewApi()

Returns true when using the Preview API.

getSynchronizationManager()

Get an instance of the synchronization manager.

syncRequest(array $queryData)

Internal method for the sync manager.

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

{@inheritdoc}

getQueryPool()

Returns the query pool currently in use.

Details

at line 135
__construct(string $token, string $spaceId, string $environmentId = 'master', ClientOptions $options = null)

Client constructor.

Parameters

string $token
string $spaceId
string $environmentId
ClientOptions $options

at line 165
getApi()

Returns a string representation of the API currently in use.

at line 170
getSpaceId()

Returns the ID of the space currently in use.

at line 175
getEnvironmentId()

Returns the ID of the environment currently in use.

at line 180
getResourceBuilder()

at line 185
getRichTextParser()

at line 193
static protected getSdkName()

{@inheritdoc}

at line 201
static protected getPackageName()

{@inheritdoc}

at line 209
static protected getApiContentType()

{@inheritdoc}

at line 217
getResourcePool()

Returns the resource pool currently in use.

at line 237
getAsset(string $assetId, string $locale = null)

Returns a single Asset object corresponding to the given ID.

Parameters

string $assetId
string $locale

Exceptions

NotFoundException If no asset is found with the given ID

at line 256
ResourceArray|Asset[] getAssets(Query $query = null)

Returns a collection of Asset objects wrapped in a ResourceArray instance.

Parameters

Query $query

Return Value

ResourceArray|Asset[]

at line 276
getContentType(string $contentTypeId)

Returns a single ContentType object corresponding to the given ID.

Parameters

string $contentTypeId

Exceptions

NotFoundException If no content type is found with the given ID

at line 292
ResourceArray|ContentType[] getContentTypes(Query $query = null)

Returns a collection of ContentType objects wrapped in a ResourceArray instance.

Parameters

Query $query

Return Value

ResourceArray|ContentType[]

at line 307
getEnvironment()

Returns the Environment object corresponding to the one in use.

at line 342
getEntry(string $entryId, string $locale = null)

Returns a single Entry object corresponding to the given ID.

Parameters

string $entryId
string $locale

Exceptions

NotFoundException If no entry is found with the given ID

at line 371
getTag(string $tagId)

Find a specific tag by its id.

Parameters

string $tagId the id of the tag

at line 387
Tag[] getAllTags()

Returns all tags in the current space and environment.

Return Value

Tag[]

at line 403
ResourceArray|Entry[] getEntries(Query $query = null)

Returns a collection of Entry objects wrapped in a ResourceArray instance.

Parameters

Query $query

Return Value

ResourceArray|Entry[]

at line 429
getSpace()

Returns the Space object corresponding to the one in use.

Resolve a link to its actual resource.

Parameters

Link $link
string $locale

Exceptions

InvalidArgumentException when encountering an unexpected link type

at line 468
ResourceInterface[] resolveLinkCollection(array $links, string $locale = null)

Resolves an array of links.

A method implementing this may apply some optimizations to reduce the amount of necessary API calls.

Parameters

array $links
string $locale

Return Value

ResourceInterface[]

at line 482
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 or environment

at line 492
isDeliveryApi()

Returns true when using the Delivery API.

at line 500
isPreviewApi()

Returns true when using the Preview API.

at line 508
getSynchronizationManager()

Get an instance of the synchronization manager.

Note that with the Preview API only an initial sync gives valid results.

at line 516
syncRequest(array $queryData)

Internal method for the sync manager.

Parameters

array $queryData

at line 526
request(string $method, string $uri, array $options = [])

{@inheritdoc}

Parameters

string $method
string $uri
array $options

at line 536
getQueryPool()

Returns the query pool currently in use.