EntityFactory

The EntityFactory builds the Swader\Diffbot\Entity\EntityIterator by providing it with a collection of entities returned by an API, and a Guzzle Response which to consume. It implements the Swader\Diffbot\Interfaces\EntityFactory interface.

The only reason to build your own version of the EntityFactory is to provide it with instructions on how to pair API return types and entities you developed by extending Swader\Diffbot\Abstracts\Entity.

For a concrete example of this, see this tutorial on SitePoint, which demonstrates custom “AuthorFolio” and “SitePointArticle” entities automatically created by calls to a custom API.

class Swader\Diffbot\Factory\Entity

Swader\Diffbot\Factory\Entity::createAppropriateIterator($response)
Parameters:
  • $response (GuzzleHttp\Message\ResponseInterface) – The Guzzle response given by the Guzzle client after an API call’s execution
Returns:

Swader\Diffbot\Entity\EntityIterator

The only method publicly accessible, and the only method one needs to implement when building one’s own EntityFactory, createAppropriateIterator does what it says - it takes the Guzzle response provided to it, and builds an EntityIterator - a collection of Entities fitting for an API’s result.