FeedWriter\Item::addElement PHP Method

addElement() public method

Add an element to elements array
public addElement ( string $elementName, string $content, array $attributes = null, boolean $overwrite = FALSE, boolean $allowMultiple = FALSE ) : self
$elementName string The tag name of an element
$content string The content of tag
$attributes array Attributes (if any) in 'attrName' => 'attrValue' format
$overwrite boolean Specifies if an already existing element is overwritten.
$allowMultiple boolean Specifies if multiple elements of the same name are allowed.
return self
    public function addElement($elementName, $content, array $attributes = null, $overwrite = FALSE, $allowMultiple = FALSE)
    {
        if (empty($elementName)) {
            throw new \InvalidArgumentException('The element name may not be empty or NULL.');
        }
        if (!is_string($elementName)) {
            throw new \InvalidArgumentException('The element name must be a string.');
        }
        $key = $elementName;
        // return if element already exists & if overwriting is disabled
        // & if multiple elements are not allowed.
        if (isset($this->elements[$elementName]) && !$overwrite) {
            if (!$allowMultiple) {
                return $this;
            }
            $key .= '-' . $this->cpt();
        }
        $this->elements[$key]['name'] = $elementName;
        $this->elements[$key]['content'] = $content;
        $this->elements[$key]['attributes'] = $attributes;
        return $this;
    }