class BaseResourceBuilder implements ResourceBuilderInterface

BaseResourceBuilder class.

This class is responsible for populating PHP objects using data received from Contentful's API.

Methods

__construct()

ResourceBuilder constructor.

build(array $data, ResourceInterface $resource = null)

Creates or updates an object using given data.

getMapper(string $fqcn)

Returns the mapper object appropriate for the given data.

setDataMapperMatcher(string $type, callable $dataMapperMatcher = null)

Sets a callable which will receive raw data (the JSON payload converted to a PHP array) and will determine the FQCN for appropriate mapping of that resource.

string
getMapperNamespace()

Returns the namespace where mapper classes are located.

createMapper(string $fqcn)

Abstract function for instantiating a mapper.

string
getSystemType(array $data)

Determines the SDK resource type given the API system type.

Details

at line 48
__construct()

ResourceBuilder constructor.

at line 56
ResourceInterface|ResourceArray build(array $data, ResourceInterface $resource = null)

Creates or updates an object using given data.

This method will overwrite properties of the $resource parameter.

Parameters

array $data The raw API data
ResourceInterface $resource A object if it needs to be updated, or null otherwise

Return Value

ResourceInterface|ResourceArray

at line 74
MapperInterface getMapper(string $fqcn)

Returns the mapper object appropriate for the given data.

Parameters

string $fqcn

Return Value

MapperInterface

Exceptions

RuntimeException

at line 129
BaseResourceBuilder setDataMapperMatcher(string $type, callable $dataMapperMatcher = null)

Sets a callable which will receive raw data (the JSON payload converted to a PHP array) and will determine the FQCN for appropriate mapping of that resource.

Parameters

string $type The system type as defined in ResourceBuilder::getSystemType()
callable $dataMapperMatcher A valid callable

Return Value

BaseResourceBuilder

at line 141
abstract protected string getMapperNamespace()

Returns the namespace where mapper classes are located.

Return Value

string

at line 152
abstract protected MapperInterface createMapper(string $fqcn)

Abstract function for instantiating a mapper.

This function is made abstract because different resource builders might need to create mappers with different arguments.

Parameters

string $fqcn

Return Value

MapperInterface

at line 163
abstract protected string getSystemType(array $data)

Determines the SDK resource type given the API system type.

Parameters

array $data The raw data fetched from the API

Return Value

string The system type that works in the SDK

Exceptions

InvalidArgumentException If the data array provided doesn't contain meaningful information