1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of the feed-io package. |
4
|
|
|
* |
5
|
|
|
* (c) Alexandre Debril <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace FeedIo\Rule\Atom; |
12
|
|
|
|
13
|
|
|
use FeedIo\Feed\Node\CategoryInterface; |
14
|
|
|
use FeedIo\Feed\NodeInterface; |
15
|
|
|
|
16
|
|
|
class Category extends \FeedIo\Rule\Category |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param NodeInterface $node |
21
|
|
|
* @param \DOMElement $element |
22
|
|
|
*/ |
23
|
3 |
|
public function setProperty(NodeInterface $node, \DOMElement $element) : void |
24
|
|
|
{ |
25
|
3 |
|
$category = $node->newCategory(); |
26
|
3 |
|
$category->setScheme($this->getAttributeValue($element, 'scheme')) |
27
|
3 |
|
->setLabel($this->getAttributeValue($element, 'label')) |
28
|
3 |
|
->setTerm($this->getAttributeValue($element, 'term')); |
29
|
|
|
|
30
|
3 |
|
$node->addCategory($category); |
31
|
3 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \DomDocument $document |
35
|
|
|
* @param CategoryInterface $category |
36
|
|
|
* @return \DomElement |
37
|
|
|
*/ |
38
|
3 |
|
public function createCategoryElement(\DomDocument $document, CategoryInterface $category) : \DOMElement |
39
|
|
|
{ |
40
|
3 |
|
$element = $document->createElement($this->getNodeName()); |
41
|
3 |
|
$this->setNonEmptyAttribute($element, 'scheme', $category->getScheme()); |
42
|
3 |
|
$this->setNonEmptyAttribute($element, 'term', $category->getTerm()); |
43
|
3 |
|
$this->setNonEmptyAttribute($element, 'label', $category->getLabel()); |
44
|
|
|
|
45
|
3 |
|
return $element; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Sets the attribute only if the value is not emtpy |
50
|
|
|
* @param DomElement $element |
51
|
|
|
* @param string $name |
52
|
|
|
* @param string $value |
53
|
|
|
*/ |
54
|
3 |
|
protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void |
55
|
|
|
{ |
56
|
3 |
|
if (! is_null($value)) { |
57
|
3 |
|
$element->setAttribute($name, $value); |
58
|
|
|
} |
59
|
3 |
|
} |
60
|
|
|
} |
61
|
|
|
|