FeedWriter\Item::setAuthor PHP Méthode

setAuthor() public méthode

Not supported in RSS 1.0 feeds.
public setAuthor ( string $author, string | null $email = null, string | null $uri = null ) : self
$author string The author of this item
$email string | null Optional email address of the author
$uri string | null Optional URI related to the author
Résultat self
    public function setAuthor($author, $email = null, $uri = null)
    {
        if ($this->version == Feed::RSS1) {
            throw new InvalidOperationException('The author element is not supported in RSS1 feeds.');
        }
        // Regex from RFC 4287 page 41
        if ($email != null && preg_match('/.+@.+/', $email) != 1) {
            throw new \InvalidArgumentException('The email address is syntactically incorrect.');
        }
        if ($this->version == Feed::RSS2) {
            if ($email != null) {
                $author = $email . ' (' . $author . ')';
            }
            $this->addElement('author', $author);
        } else {
            $elements = array('name' => $author);
            if ($email != null) {
                $elements['email'] = $email;
            }
            if ($uri != null) {
                $elements['uri'] = $uri;
            }
            $this->addElement('author', $elements);
        }
        return $this;
    }