Skip to content

Commit

Permalink
Merge pull request #168 from SMillerDev/release/3.0
Browse files Browse the repository at this point in the history
Add support for language/lang
  • Loading branch information
alexdebril authored Mar 30, 2018
2 parents 106435a + a355c38 commit 2e02120
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/specifications-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface : FeedInterface
| icon / logo | image | not supported | not supported |
| rights | copyright | not supported | not supported |
| subtitle | N/A | not supported | not supported |
| lang | language | not supported | not supported |
| lang | language | getLanguage | setLanguage |
| base | N/A | not supported | not supported |
| generator | generator | not supported | not supported |
| N/A | managingEditor | not supported | not supported |
Expand Down
27 changes: 27 additions & 0 deletions src/FeedIo/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Feed extends Node implements FeedInterface, \JsonSerializable
*/
protected $url;

/**
* @var string $language
*/
protected $language;

public function __construct()
{
$this->items = new \ArrayIterator();
Expand All @@ -52,6 +57,28 @@ public function setUrl($url)
return $this;
}

/**
* @return string $language
*/
public function getLanguage()
{
return $this->language;
}

/**
* @param string $language
* @return FeedInterface
*/
public function setLanguage($language)
{
$this->language = $language;

return $this;
}




/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element
Expand Down
11 changes: 11 additions & 0 deletions src/FeedIo/FeedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public function getUrl();
* @return FeedInterface
*/
public function setUrl($url);

/**
* @return string $language
*/
public function getLanguage();

/**
* @param string $language
* @return FeedInterface
*/
public function setLanguage($language);

/**
* Atom : feed.entry <feed><entry>
Expand Down
50 changes: 50 additions & 0 deletions src/FeedIo/Rule/Language.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the feed-io package.
*
* (c) Alexandre Debril <alex.debril@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FeedIo\Rule;

use FeedIo\Feed\NodeInterface;
use FeedIo\FeedInterface;
use FeedIo\RuleAbstract;

class Language extends RuleAbstract
{
const NODE_NAME = 'language';

/**
* @param NodeInterface $node
* @param \DOMElement $element
* @return $this
*/
public function setProperty(NodeInterface $node, \DOMElement $element)
{
if ($node instanceof FeedInterface) {
$node->set(static::NODE_NAME, $element->nodeValue);
}

return $this;
}

/**
* creates the accurate DomElement content according to the $item's property
*
* @param \DomDocument $document
* @param NodeInterface $node
* @return \DomElement
*/
public function createElement(\DomDocument $document, NodeInterface $node)
{
if (!($node instanceof FeedInterface) || is_null($node->getLanguage())) {
return;
}

return $document->createElement($this->getNodeName(), $node->getLanguage());
}
}
4 changes: 3 additions & 1 deletion src/FeedIo/Standard/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use FeedIo\Rule\Atom\Author;
use FeedIo\Rule\Atom\LinkNode;
use FeedIo\Rule\Description;
use FeedIo\Rule\Language;
use FeedIo\Rule\PublicId;
use FeedIo\Rule\Atom\Category;

Expand Down Expand Up @@ -72,6 +73,7 @@ public function buildFeedRuleSet()
$ruleSet
->add(new LinkNode())
->add(new PublicId('id'))
->add(new Language('lang'))
->add($this->getModifiedSinceRule('updated'))
;

Expand All @@ -93,7 +95,7 @@ public function buildItemRuleSet()
}

/**
* @return RuleSet
* @return \FeedIo\RuleSet
*/
protected function buildBaseRuleSet()
{
Expand Down
13 changes: 6 additions & 7 deletions src/FeedIo/Standard/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FeedIo\Reader\Document;
use FeedIo\Rule\Author;
use FeedIo\Rule\Description;
use FeedIo\Rule\Language;
use FeedIo\Rule\Link;
use FeedIo\Rule\PublicId;
use FeedIo\Rule\Media;
Expand Down Expand Up @@ -80,21 +81,19 @@ public function getMainElement(\DOMDocument $document)
}

/**
* @return RuleSet
* @return \FeedIo\RuleSet
*/
public function buildFeedRuleSet()
{
$ruleSet = $this->buildItemRuleSet();
$ruleSet->add(
$this->getModifiedSinceRule('lastPubDate'),
array('lastBuildDate')
);
$ruleSet->add($this->getModifiedSinceRule('lastPubDate'), ['lastBuildDate'])
->add(new Language());

return $ruleSet;
}

/**
* @return RuleSet
* @return \FeedIo\RuleSet
*/
public function buildItemRuleSet()
{
Expand All @@ -111,7 +110,7 @@ public function buildItemRuleSet()
}

/**
* @return RuleSet
* @return \FeedIo\RuleSet
*/
protected function buildBaseRuleSet()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/FeedIo/StandardFormatter/FormatterTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testFormat()
$feed->setLastModified($date);
$feed->setLink('http://localhost');
$feed->setPublicId(1);
$feed->setLanguage('en');
$feed->addCategory($category);

$item = new Item();
Expand All @@ -58,6 +59,7 @@ public function testFormat()
$feed->add($item);

$formatter = new XmlFormatter($this->standard);

$document = $formatter->toDom($feed);
$this->assertXmlStringEqualsXmlFile($this->getSampleFile(), $document->saveXML());
}
Expand Down
1 change: 1 addition & 0 deletions tests/samples/expected-atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<category label="sample" scheme="http://localhost" term="sample" />
<link href="http://localhost"/>
<id>1</id>
<lang>en</lang>
<updated>2014-12-01T00:00:00+00:00</updated>

<entry>
Expand Down
1 change: 1 addition & 0 deletions tests/samples/rss/expected-rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<description/>
<pubDate>Mon, 01 Dec 2014 00:00:00 +0000</pubDate>
<lastPubDate>Mon, 01 Dec 2014 00:00:00 +0000</lastPubDate>
<language>en</language>
<item>
<title>item title</title>
<category domain="http://localhost">sample</category>
Expand Down

0 comments on commit 2e02120

Please sign in to comment.