\FeedWriterItem

Universal Feed Writer

Item class - Used as feed element in Feed class

Summary

Methods
Properties
Constants
__construct()
addElement()
addElementArray()
getElements()
getVersion()
setDescription()
setContent()
setTitle()
setDate()
setLink()
addEnclosure()
setAuthor()
setId()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
cpt()
$elements
$version
$_cpt
N/A

Properties

$elements

$elements : 

Collection of feed item elements

Type

$version

$version : 

Contains the format of this feed.

Type

$_cpt

$_cpt : 

Is used as a suffix when multiple elements have the same name.

Type

Methods

__construct()

__construct(string  $version = \FeedWriter\Feed::RSS2) 

Constructor

Parameters

string $version

constant (RSS1/RSS2/ATOM) RSS2 is default.

addElement()

addElement(string  $elementName, string  $content, array  $attributes = null, boolean  $overwrite = FALSE, boolean  $allowMultiple = FALSE) : self

Add an element to elements array

Parameters

string $elementName

The tag name of an element

string $content

The content of tag

array $attributes

Attributes (if any) in 'attrName' => 'attrValue' format

boolean $overwrite

Specifies if an already existing element is overwritten.

boolean $allowMultiple

Specifies if multiple elements of the same name are allowed.

Throws

\InvalidArgumentException

if the element name is not a string, empty or NULL.

Returns

self

addElementArray()

addElementArray(array  $elementArray) : self

Set multiple feed elements from an array.

Elements which have attributes cannot be added by this method

Parameters

array $elementArray

Returns

self

getElements()

getElements() : array

Return the collection of elements in this feed item

Throws

\FeedWriter\InvalidOperationException

on ATOM feeds if either a content or link element is missing.

\FeedWriter\InvalidOperationException

on RSS1 feeds if a title or link element is missing.

Returns

array —

All elements of this item.

getVersion()

getVersion() : string

Return the type of this feed item

Returns

string —

The feed type, as defined in Feed.php

setDescription()

setDescription(string  $description) : self

Set the 'description' element of feed item

Parameters

string $description

The content of the 'description' or 'summary' element

Returns

self

setContent()

setContent(string  $content) : self

Set the 'content' element of the feed item For ATOM feeds only

Parameters

string $content

Content for the item (i.e., the body of a blog post).

Throws

\FeedWriter\InvalidOperationException

if this method is called on non-ATOM feeds.

Returns

self

setTitle()

setTitle(string  $title) : self

Set the 'title' element of feed item

Parameters

string $title

The content of 'title' element

Returns

self

setDate()

setDate(\DateTime|integer|string  $date) : self

Set the 'date' element of the feed item.

The value of the date parameter can be either an instance of the DateTime class, an integer containing a UNIX timestamp or a string which is parseable by PHP's 'strtotime' function.

Parameters

\DateTime|integer|string $date

Date which should be used.

Throws

\InvalidArgumentException

if the given date was not parseable.

Returns

self

setLink()

setLink(string  $link) : self

Set the 'link' element of feed item

Parameters

string $link

The content of 'link' element

Returns

self

addEnclosure()

addEnclosure(string  $url, integer  $length, string  $type, boolean  $multiple = TRUE) : self

Attach a external media to the feed item.

Not supported in RSS 1.0 feeds.

See RFC 4288 for syntactical correct MIME types.

Note that you should avoid the use of more than one enclosure in one item, since some RSS aggregators don't support it.

Parameters

string $url

The URL of the media.

integer $length

The length of the media.

string $type

The MIME type attribute of the media.

boolean $multiple

Specifies if multiple enclosures are allowed

Throws

\InvalidArgumentException

if the length or type parameter is invalid.

\FeedWriter\InvalidOperationException

if this method is called on RSS1 feeds.

Returns

self

setAuthor()

setAuthor(string  $author, string|null  $email = null, string|null  $uri = null) : self

Set the 'author' element of feed item.

Not supported in RSS 1.0 feeds.

Parameters

string $author

The author of this item

string|null $email

Optional email address of the author

string|null $uri

Optional URI related to the author

Throws

\InvalidArgumentException

if the provided email address is syntactically incorrect.

\FeedWriter\InvalidOperationException

if this method is called on RSS1 feeds.

Returns

self

setId()

setId(string  $id, boolean  $permaLink = false) : self

Set the unique identifier of the feed item

On ATOM feeds, the identifier must begin with an valid URI scheme.

Parameters

string $id

The unique identifier of this item

boolean $permaLink

The value of the 'isPermaLink' attribute in RSS 2 feeds.

Throws

\InvalidArgumentException

if the permaLink parameter is not boolean.

\FeedWriter\InvalidOperationException

if this method is called on RSS1 feeds.

Returns

self

cpt()

cpt() : integer

Return an unique number

Returns

integer