diff --git a/Classes/Channel.php b/Classes/Channel.php index 6d7781a..f11364a 100644 --- a/Classes/Channel.php +++ b/Classes/Channel.php @@ -1,4 +1,6 @@ description = $description; + return $this; } /** * @param string $title - * @return void + * @return Channel */ - public function setTitle($title) + public function setTitle(string $title): Channel { $this->title = $title; + return $this; } /** * @param string $feedUri - * @return void + * @return Channel */ - public function setFeedUri($feedUri) + public function setFeedUri(string $feedUri): Channel { $this->feedUri = $feedUri; + return $this; } /** * @param string $websiteUri - * @return void + * @return Channel */ - public function setWebsiteUri($websiteUri) + public function setWebsiteUri(string $websiteUri): Channel { $this->websiteUri = $websiteUri; + return $this; } /** * @param string $language - * @return void + * @return Channel */ - public function setLanguage($language) + public function setLanguage(string $language): Channel { $this->language = $language; + return $this; } /** * Adds a new item to this channel * * @param Item $item An item - * @return void + * @return Channel */ - public function addItem(Item $item) + public function addItem(Item $item): Channel { $this->items[] = $item; + return $this; } /** * @return \SimpleXMLElement + * @throws \Exception */ - public function asXML() + public function asXML(): \SimpleXMLElement { $date = new \DateTime('now', new \DateTimeZone('GMT')); $nowFormatted = $date->format('D, d M Y H:i:s') . ' GMT'; @@ -148,4 +151,4 @@ public function asXML() return $xml; } -} \ No newline at end of file +} diff --git a/Classes/Feed.php b/Classes/Feed.php index 02fdbf5..2f6f500 100644 --- a/Classes/Feed.php +++ b/Classes/Feed.php @@ -1,4 +1,6 @@ */ - protected $channels = array(); + protected $channels = []; /** * Adds a new channel to this feed @@ -28,7 +29,7 @@ class Feed * @param Channel $channel * @return Feed */ - public function addChannel(Channel $channel) + public function addChannel(Channel $channel): Feed { $this->channels[] = $channel; @@ -40,7 +41,7 @@ public function addChannel(Channel $channel) * * @return string */ - public function render() + public function render(): string { $xml = new SimpleXMLElement( ' @@ -67,4 +68,4 @@ public function render() return $dom->saveXML(); } -} \ No newline at end of file +} diff --git a/Classes/Item.php b/Classes/Item.php index 85b9bfd..56b872f 100644 --- a/Classes/Item.php +++ b/Classes/Item.php @@ -1,4 +1,6 @@ */ - protected $categories = array(); + protected $categories = []; /** * Can be an array of either strings or arrays (with indexes "category" and "domain"). * * @param array $categories - * @return void + * @return Item */ - public function setCategories($categories) + public function setCategories(array $categories): Item { $this->categories = $categories; + return $this; } /** * @return array */ - public function getCategories() + public function getCategories(): array { return $this->categories; } /** * @param string $commentsLink - * @return void + * @return Item */ - public function setCommentsLink($commentsLink) + public function setCommentsLink(string $commentsLink): Item { $this->commentsLink = $commentsLink; + return $this; } /** * @return string */ - public function getCommentsLink() + public function getCommentsLink(): string { return $this->commentsLink; } /** * @param string $content - * @return void + * @return Item */ - public function setContent($content) + public function setContent(string $content): Item { $this->content = $content; + return $this; } /** * @return string */ - public function getContent() + public function getContent(): string { return $this->content; } /** * @param string $creator - * @return void + * @return Item */ - public function setCreator($creator) + public function setCreator(string $creator): Item { $this->creator = $creator; + return $this; } /** * @return string */ - public function getCreator() + public function getCreator(): string { return $this->creator; } /** * @param string $description - * @return void + * @return Item */ - public function setDescription($description) + public function setDescription(string $description): Item { $this->description = $description; + return $this; } /** * @return string */ - public function getDescription() + public function getDescription(): string { return $this->description; } /** * @param string $guid - * @return void + * @return Item */ - public function setGuid($guid) + public function setGuid(string $guid): Item { $this->guid = $guid; + return $this; } /** * @return string */ - public function getGuid() + public function getGuid(): string { return $this->guid; } /** * @param string $itemLink - * @return void + * @return Item */ - public function setItemLink($itemLink) + public function setItemLink(string $itemLink): Item { $this->itemLink = $itemLink; + return $this; } /** * @return string */ - public function getItemLink() + public function getItemLink(): string { return $this->itemLink; } /** * @param \DateTime $publicationDate - * @return void + * @return Item */ - public function setPublicationDate(\DateTime $publicationDate = null) + public function setPublicationDate(\DateTime $publicationDate = null): Item { $this->publicationDate = $publicationDate; + return $this; } /** * @return \DateTime */ - public function getPublicationDate() + public function getPublicationDate(): \DateTime { return $this->publicationDate; } /** * @param string $title - * @return void + * @return Item */ - public function setTitle($title) + public function setTitle(string $title): Item { $this->title = $title; + return $this; } /** * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title; } @@ -220,7 +230,7 @@ public function getTitle() /** * @return \SimpleXMLElement */ - public function asXml() + public function asXml(): \SimpleXMLElement { $xml = new SimpleXMLElement( ' @@ -267,5 +277,4 @@ public function asXml() return $xml; } - -} \ No newline at end of file +} diff --git a/Classes/SimpleXMLElement.php b/Classes/SimpleXMLElement.php index a4afc05..f1195c5 100644 --- a/Classes/SimpleXMLElement.php +++ b/Classes/SimpleXMLElement.php @@ -1,4 +1,6 @@ addChild($name, null, $namespace); $child->setChildCdataValue($value); @@ -64,10 +65,10 @@ public function addCdataChild($name, $value, $namespace = null) * @param string $value The value to be enclosed in CDATA * @return void */ - private function setChildCdataValue($value) + private function setChildCdataValue(string $value): void { $domNode = dom_import_simplexml($this); $domNode->appendChild($domNode->ownerDocument->createCDATASection($value)); } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 3d18bcf..0a4cd5b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ RSS / Atom Feed Generator ========================= -This is yet another RSS / Atom feed generator for PHP 5.5 and later. It works great +This is yet another RSS / Atom feed generator for PHP 7 and later. It works great in combination with Flow but should also be fine as a standalone library. This package is composer enabled. @@ -12,26 +12,26 @@ Example ```php setTitle('All about TYPO3 Flow') + ->setTitle('All about Neos Flow') ->setDescription($channelDescription) ->setFeedUri($feedUri) ->setWebsiteUri($websiteUri) ->setLanguage('en-US'); -$item = new Item(); +$item = new \RobertLemke\Rss\Item(); $item ->setTitle('My first blog post') ->setGuid($someUniqueIdentifier) - ->setPublicationDate(new \DateTime()) + ->setPublicationDate(new DateTime()) ->setContent($blogPostContent); $channel->addItem($item); $feed->addChannel($channel); -echo $feed; +echo $feed->render(); ``` diff --git a/composer.json b/composer.json index a2b1a64..ac6a6a2 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,9 @@ } ], "require": { - "php": "~5.5 || ~7.0" + "ext-simplexml": "*", + "ext-dom": "*", + "php": "~7.0" }, "conflict": { "neos/flow": "<4"