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.
registerDiffbot¶
-
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
- $d (\Swader\Diffbot\Diffbot) –
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.
setLinks¶
setMeta¶
setBreadcrumb¶
-
Swader\Diffbot\Traits\StandardApi::
setBreadcrumb
($bool)¶ Parameters: - $bool (bool) – Either
true
orfalse
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.- $bool (bool) – Either
setQuerystring¶
-
Swader\Diffbot\Traits\StandardApi::
setQuerystring
($bool)¶ Parameters: - $bool (bool) – Either
true
orfalse
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.- $bool (bool) – Either
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.
getLang¶
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
getHumanLanguage¶
Swader\Diffbot\Traits\StandardEntity::
getHumanLanguage
()¶
Returns: string Alias method for
getLang()
above.
getPageUrl¶
Swader\Diffbot\Traits\StandardEntity::
getPageUrl
()¶
Returns: string Returns the URL which was processed
getResolvedPageUrl¶
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.
getTitle¶
Swader\Diffbot\Traits\StandardEntity::
getTitle
()¶
Returns: string Returns the title of the document which was processed.
getLinks¶
Swader\Diffbot\Traits\StandardEntity::
getLinks
()¶
Returns: array | null Returns an array of all links found on the processed page. Links will be simple string elements in an indexed array. If the
Swader\Diffbot\Traits\StandardApi::setLinks
method was not called, will returnnull
.
getMeta¶
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 returnnull
.
getBreadcrumb¶
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 returnnull
.
getQueryString¶
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 returnnull
.