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

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', ClientOptions $options = \null)

Client constructor.

string
getApi()

Returns a string representation of the API currently in use.

string
getSpaceId()

No description

string
getEnvironmentId()

No description

ResourceBuilderInterface
getResourceBuilder()

No description

Parser
getRichTextParser()

No description

static 
getSdkName()

{@inheritdoc}

static 
getPackageName()

{@inheritdoc}

static 
getApiContentType()

{@inheritdoc}

ResourcePoolInterface
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.

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.

ResourceInterface
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.

bool
isDeliveryApi()

Returns true when using the Delivery API.

bool
isPreviewApi()

Returns true when using the Preview API.

getSynchronizationManager()

Get an instance of the synchronization manager.

array
syncRequest(array $queryData)

Internal method for the sync manager.

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

{@inheritdoc}

Details

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

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
ClientOptions $options

at line 155
string getApi()

Returns a string representation of the API currently in use.

Return Value

string

at line 163
string getSpaceId()

Return Value

string

at line 171
string getEnvironmentId()

Return Value

string

at line 179
ResourceBuilderInterface getResourceBuilder()

Return Value

ResourceBuilderInterface

at line 187
Parser getRichTextParser()

Return Value

Parser

at line 195
static protected getSdkName()

{@inheritdoc}

at line 203
static protected getPackageName()

{@inheritdoc}

at line 211
static protected getApiContentType()

{@inheritdoc}

at line 221
ResourcePoolInterface getResourcePool()

Returns the resource pool currently in use.

Return Value

ResourcePoolInterface

at line 245
Asset getAsset(string $assetId, string $locale = \null)

Returns a single Asset object corresponding to the given ID.

Parameters

string $assetId
string $locale

Return Value

Asset

Exceptions

NotFoundException If no asset is found with the given ID

at line 264
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 284
ContentType getContentType(string $contentTypeId)

Returns a single ContentType object corresponding to the given ID.

Parameters

string $contentTypeId

Return Value

ContentType

Exceptions

NotFoundException If no content type is found with the given ID

at line 300
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 315
Environment getEnvironment()

Returns the Environment object corresponding to the one in use.

Return Value

Environment

at line 350
Entry getEntry(string $entryId, string $locale = \null)

Returns a single Entry object corresponding to the given ID.

Parameters

string $entryId
string $locale

Return Value

Entry

Exceptions

NotFoundException If no entry is found with the given ID

at line 369
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 389
Space getSpace()

Returns the Space object corresponding to the one in use.

Return Value

Space

Resolve a link to its actual resource.

Parameters

Link $link
string $locale

Return Value

ResourceInterface

Exceptions

InvalidArgumentException when encountering an unexpected link type

at line 415
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 431
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 443
bool isDeliveryApi()

Returns true when using the Delivery API.

Return Value

bool

at line 453
bool isPreviewApi()

Returns true when using the Preview API.

Return Value

bool

at line 461
Manager getSynchronizationManager()

Get an instance of the synchronization manager.

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

Return Value

Manager

at line 469
array syncRequest(array $queryData)

Internal method for the sync manager.

Parameters

array $queryData

Return Value

array

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

{@inheritdoc}

Parameters

string $method
string $uri
array $options