Completed
Push — issue/96 ( 5d401e...7b0d36 )
by Alex
02:40
created

XmlAbstract::format()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
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\Standard;
12
13
14
use FeedIo\Parser\XmlParser;
15
use FeedIo\StandardAbstract;
16
use FeedIo\RuleSet;
17
use FeedIo\Rule\ModifiedSince;
18
use FeedIo\Rule\Title;
19
20
abstract class XmlAbstract extends StandardAbstract
21
{
22
23
    /**
24
     * Name of the node containing all the feed's items
25
     */
26
    const ITEM_NODE = 'item';
27
28
    /**
29
     * This is for XML Standards
30
     */
31
    const SYNTAX_FORMAT = 'Xml';
32
33
    /**
34
     * RuleSet used to parse the feed's main node
35
     * @var \FeedIo\RuleSet
36
     */
37
    protected $feedRuleSet;
38
39
    /**
40
     * @var \FeedIo\RuleSet
41
     */
42
    protected $itemRuleSet;
43
44
    /**
45
     * Formats the document according to the standard's specification
46
     * @param  \DOMDocument $document
47
     * @return mixed
48
     */
49
    abstract public function format(\DOMDocument $document);
50
51
    /**
52
     * @param  \DOMDocument $document
53
     * @return \DomElement
54
     */
55
    abstract public function getMainElement(\DOMDocument $document);
56
57
    /**
58
     * Builds and returns a rule set to parse the root node
59
     * @return \FeedIo\RuleSet
60
     */
61
    abstract public function buildFeedRuleSet();
62
63
    /**
64
     * Builds and returns a rule set to parse an item
65
     * @return \FeedIo\RuleSet
66
     */
67
    abstract public function buildItemRuleSet();
68
69
    /**
70
     * @return string
71
     */
72 12
    public function getItemNodeName()
73
    {
74 12
        return static::ITEM_NODE;
75
    }
76
77
    /**
78
     * Returns the RuleSet used to parse the feed's main node
79
     * @return \FeedIo\RuleSet
80
     */
81 13
    public function getFeedRuleSet()
82
    {
83 13
        if (is_null($this->feedRuleSet)) {
84 13
            $this->feedRuleSet = $this->buildFeedRuleSet();
85 13
        }
86
87 13
        return $this->feedRuleSet;
88 1
    }
89
90
    /**
91
     * @return \FeedIo\RuleSet
92
     */
93 11
    public function getItemRuleSet()
94
    {
95 11
        if (is_null($this->itemRuleSet)) {
96 11
            $this->itemRuleSet = $this->buildItemRuleSet();
97 11
        }
98
99 11
        return $this->itemRuleSet;
100
    }
101
102
    /**
103
     * @param  string        $tagName
104
     * @return ModifiedSince
105
     */
106 15
    public function getModifiedSinceRule($tagName)
107
    {
108 15
        $rule = new ModifiedSince($tagName);
109 15
        $rule->setDefaultFormat($this->getDefaultDateFormat());
110 15
        $rule->setDateTimeBuilder($this->dateTimeBuilder);
111
112 15
        return $rule;
113
    }
114
115
    /**
116
     * @return RuleSet
117
     */
118 15
    protected function buildBaseRuleSet()
119
    {
120 15
        $ruleSet = $ruleSet = new RuleSet();
121 15
        $ruleSet->add(new Title());
122
123 15
        return $ruleSet;
124
    }
125
}