Skip to content

Commit

Permalink
Merge pull request #74 from alexdebril/issue/72
Browse files Browse the repository at this point in the history
Issue/72
  • Loading branch information
alexdebril authored May 3, 2017
2 parents 9c1c587 + 085764d commit 30c3eca
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 10 deletions.
34 changes: 34 additions & 0 deletions src/FeedIo/Feed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use FeedIo\Feed\Item\Media;
use FeedIo\Feed\Item\MediaInterface;
use FeedIo\Feed\Item\Author;
use FeedIo\Feed\Item\AuthorInterface;

class Item extends Node implements ItemInterface
{
Expand All @@ -21,6 +23,11 @@ class Item extends Node implements ItemInterface
*/
protected $medias;

/**
* @var AuthorInterface
*/
protected $author;

public function __construct()
{
$this->medias = new \ArrayIterator();
Expand Down Expand Up @@ -62,4 +69,31 @@ public function newMedia()
{
return new Media();
}

/**
* @return AuthorInterface
*/
public function getAuthor()
{
return $this->author;
}

/**
* @param AuthorInterface $author
* @return $this
*/
public function setAuthor(AuthorInterface $author)
{
$this->author = $author;

return $this;
}

/**
* @return AuthorInterface
*/
public function newAuthor()
{
return new Author();
}
}
88 changes: 88 additions & 0 deletions src/FeedIo/Feed/Item/Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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\Feed\Item;

class Author implements AuthorInterface
{

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

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

/**
* @var int
*/
protected $email;

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

/**
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

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

/**
* @param string $uri
* @return $this
*/
public function setUri($uri)
{
$this->uri = $uri;

return $this;
}

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

/**
* @param string $email
* @return $this
*/
public function setEmail($email)
{
$this->email = $email;

return $this;
}

}
53 changes: 53 additions & 0 deletions src/FeedIo/Feed/Item/AuthorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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\Feed\Item;

/**
* Describe a Author instance
*
*/
interface AuthorInterface
{

/**
* @return string
*/
public function getName();

/**
* @param string $name
* @return $this
*/
public function setName($name);

/**
* @return string
*/
public function getUri();

/**
* @param string $uri
* @return $this
*/
public function setUri($uri);

/**
* @return string
*/
public function getEmail();

/**
* @param string $email
* @return $this
*/
public function setEmail($email);

}
24 changes: 24 additions & 0 deletions src/FeedIo/Feed/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace FeedIo\Feed;

use FeedIo\Feed\Item\MediaInterface;
use FeedIo\Feed\Item\AuthorInterface;

/**
* Describes an Item instance
Expand Down Expand Up @@ -57,4 +58,27 @@ public function hasMedia();
* @return MediaInterface
*/
public function newMedia();

/**
* returns the author attribute
*
* @return AuthorInterface
*/
public function getAuthor();

/**
* sets $author to the object's attributes
*
* @param AuthorInterface $author
* @return $this
*/
public function setAuthor(AuthorInterface $author);

/**
* returns a new AuthorInterface
*
* @return AuthorInterface
*/
public function newAuthor();

}
61 changes: 61 additions & 0 deletions src/FeedIo/Rule/Atom/Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\Atom;

use FeedIo\Feed\Item\AuthorInterface;
use FeedIo\Feed\ItemInterface;
use FeedIo\Feed\NodeInterface;
use FeedIo\RuleAbstract;

class Author extends RuleAbstract
{

const NODE_NAME = 'author';

/**
* @param NodeInterface $node
* @param \DOMElement $element
* @return mixed
*/
public function setProperty(NodeInterface $node, \DOMElement $element)
{
if ($node instanceof ItemInterface) {
$author = $node->newAuthor();
$author->setName($this->getAttributeValue($element, 'name'));
$author->setUri($this->getAttributeValue($element, 'uri'));
$author->setEmail($this->getAttributeValue($element, 'email'));
$node->setAuthor($author);
}

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 ItemInterface && !is_null($node->getAuthor())) {
$element = $document->createElement(static::NODE_NAME);
$element->setAttribute('name', $node->getAuthor()->getName());
$element->setAttribute('uri', $node->getAuthor()->getUri());
$element->setAttribute('email', $node->getAuthor()->getEmail());

return $element;
}

return;
}
}
55 changes: 55 additions & 0 deletions src/FeedIo/Rule/Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Item\AuthorInterface;
use FeedIo\Feed\ItemInterface;
use FeedIo\Feed\NodeInterface;
use FeedIo\RuleAbstract;

class Author extends RuleAbstract
{

const NODE_NAME = 'author';

/**
* @param NodeInterface $node
* @param \DOMElement $element
* @return mixed
*/
public function setProperty(NodeInterface $node, \DOMElement $element)
{
if ($node instanceof ItemInterface) {
$author = $node->newAuthor();
$author->setName($element->nodeValue);
$node->setAuthor($author);
}

return $this;
}

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

return;
}

}
9 changes: 6 additions & 3 deletions src/FeedIo/Standard/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace FeedIo\Standard;

use DOMDocument;
use FeedIo\Rule\Atom\Author;
use FeedIo\Rule\Atom\LinkNode;
use FeedIo\Rule\Description;
use FeedIo\Rule\PublicId;
Expand Down Expand Up @@ -82,11 +83,13 @@ public function buildFeedRuleSet()
public function buildItemRuleSet()
{
$ruleSet = $this->buildFeedRuleSet();
$ruleSet->add(new Description('content'), ['summary']);
$ruleSet
->add(new Author())
->add(new Description('content'), ['summary']);

return $ruleSet;
}
}

/**
* @return RuleSet
*/
Expand Down
Loading

0 comments on commit 30c3eca

Please sign in to comment.