|
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\ItemInterface; |
|
14
|
|
|
use FeedIo\Feed\NodeInterface; |
|
15
|
|
|
use FeedIo\RuleAbstract; |
|
16
|
|
|
use FeedIo\RuleSet; |
|
17
|
|
|
|
|
18
|
|
|
class LinkNode extends RuleAbstract |
|
19
|
|
|
{ |
|
20
|
|
|
const NODE_NAME = 'link'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \FeedIo\RuleSet |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $ruleSet; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $nodeName |
|
29
|
|
|
*/ |
|
30
|
13 |
|
public function __construct(string $nodeName = null) |
|
31
|
|
|
{ |
|
32
|
13 |
|
parent::__construct($nodeName); |
|
33
|
13 |
|
$mediaRule = new Media(); |
|
34
|
13 |
|
$mediaRule->setUrlAttributeName('href'); |
|
35
|
13 |
|
$this->ruleSet = new RuleSet(new Link('related')); |
|
36
|
13 |
|
$this->ruleSet->add($mediaRule, ['media', 'enclosure']); |
|
37
|
13 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param NodeInterface $node |
|
41
|
|
|
* @param \DOMElement $element |
|
42
|
|
|
* @return mixed |
|
43
|
|
|
*/ |
|
44
|
6 |
|
public function setProperty(NodeInterface $node, \DOMElement $element) : void |
|
45
|
|
|
{ |
|
46
|
6 |
|
if ($element->hasAttribute('rel')) { |
|
47
|
4 |
|
$this->ruleSet->get($element->getAttribute('rel'))->setProperty($node, $element); |
|
48
|
|
|
} else { |
|
49
|
4 |
|
$this->ruleSet->getDefault()->setProperty($node, $element); |
|
50
|
|
|
} |
|
51
|
6 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritDoc |
|
55
|
|
|
*/ |
|
56
|
5 |
|
protected function hasValue(NodeInterface $node) : bool |
|
57
|
|
|
{ |
|
58
|
5 |
|
return true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritDoc |
|
64
|
|
|
*/ |
|
65
|
5 |
|
protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
66
|
|
|
{ |
|
67
|
5 |
|
if ($node instanceof ItemInterface && $node->hasMedia()) { |
|
68
|
|
|
$this->ruleSet->get('media')->apply($document, $rootElement, $node); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
5 |
|
$this->ruleSet->getDefault()->apply($document, $rootElement, $node); |
|
72
|
5 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|