Traits

All the traits used in the Diffbot PHP client are described in this one document.

DiffbotAware

trait Swader\Diffbot\Traits\DiffbotAware

The DiffbotAware trait is there to make the API classes spawned by Diffbot aware of their parent, so that common configuration values and other factories can be accessed even after an API class has been instantiated.

Unless you’re implementing your own API class which doesn’t extend the \Swader\Diffbot\Abstracts\Api, you won’t need this.

Swader\Diffbot\Traits\DiffbotAware::registerDiffbot($d)
Parameters:
  • $d (\Swader\Diffbot\Diffbot) – Swader\Diffbot\Diffbot - an instance of the Diffbot main class to inject into children, like instances of various API classes.
Returns:

$this

StandardApi

trait Swader\Diffbot\Traits\StandardApi

The StandardApi trait contains some methods common to most, if not all, API classes. These methods are setters for fields which appear in every Diffbot API: links, breadcrumb, meta and querystring. More information available under optional fields in various API doc files.

Swader\Diffbot\Traits\StandardApi::setBreadcrumb($bool)
Parameters:
  • $bool (bool) – Either true or false
Returns:

$this

Sets the breadcrumb optional field to true. The API then returns a top-level array (breadcrumb) of URLs and link text from page breadcrumbs.

Swader\Diffbot\Traits\StandardApi::setQuerystring($bool)
Parameters:
  • $bool (bool) – Either true or false
Returns:

$this

Sets the querystring optional field to true. The API then returns any key/value pairs present in the URL querystring. Items without a discrete value will be returned as true.

StandardEntity

trait Swader\Diffbot\Traits\StandardEntity

The StandardEntity trait is here to add some common methods to the various entities. These make sense only in the standard entities, i.e. the data formats returned by Diffbot, which is why they aren’t in the abstract \Swader\Diffbot\Abstracts\Entity class. You probably won’t need this trait unless you define a \Swader\Diffbot\Api\Custom API which offers fields of the same names as those returned by the getters in this trait.

Swader\Diffbot\Traits\StandardEntity::getLang()
Returns:string

Returns the language code of the detected language of the processed content. The code returned is a two-character ISO 639-1 code: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Swader\Diffbot\Traits\StandardEntity::getHumanLanguage()
Returns:string

Alias method for getLang() above.

Swader\Diffbot\Traits\StandardEntity::getPageUrl()
Returns:string

Returns the URL which was processed

Swader\Diffbot\Traits\StandardEntity::getResolvedPageUrl()
Returns:string

Returns page URL which was resolved by redirects, if any. Will often be identical to result from getPageUrl above.

Swader\Diffbot\Traits\StandardEntity::getTitle()
Returns:string

Returns the title of the document which was processed.

Swader\Diffbot\Traits\StandardEntity::getMeta()
Returns:array | null

Returns an array containing the full contents of page meta tags, including sub-arrays for OpenGraph tags, Twitter Card metadata, schema.org microdata, and – if available – oEmbed metadata. If the Swader\Diffbot\Traits\StandardApi::setMeta method was not called, will return null.

Swader\Diffbot\Traits\StandardEntity::getBreadcrumb()
Returns:array | null

Returns a top-level array (breadcrumb) of URLs and link text from page breadcrumbs. If the Swader\Diffbot\Traits\StandardApi::setBreadcrumb method was not called, will return null.

Swader\Diffbot\Traits\StandardEntity::getQueryString()
Returns:array | null

Returns any key/value pairs present in the URL querystring. Items without a discrete value will be returned as true. If the Swader\Diffbot\Traits\StandardApi::setQuerystring method was not called, will return null.

Swader\Diffbot\Traits\StandardEntity::getDiffbotUri()
Returns:string

A unique identifier of the entity in Diffbot’s database. Useful for filtering out duplicates, caching, etc.