1: <?php
2: /**
3: * This file is part of the FastFeed package.
4: *
5: * (c) Daniel González <daniel@desarrolla2.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10: namespace FastFeed\Parser;
11:
12: use DOMElement;
13: use FastFeed\Item;
14: use FastFeed\Aggregator\AggregatorInterface;
15: use FastFeed\Exception\LogicException;
16:
17: /**
18: * AbstractParser
19: */
20: abstract class AbstractParser extends AbstractDomParser
21: {
22:
23: /**
24: * @var array
25: */
26: protected $aggregators = array();
27:
28: /**
29: * @return mixed
30: * @throws \FastFeed\Exception\LogicException
31: */
32: public function popAggregator()
33: {
34: if (!$this->aggregators) {
35: throw new LogicException('You tried to pop from an empty Aggregator stack.');
36: }
37:
38: return array_shift($this->aggregators);
39: }
40:
41: /**
42: * @param AggregatorInterface $aggregator
43: */
44: public function pushAggregator(AggregatorInterface $aggregator)
45: {
46: $this->aggregators[] = $aggregator;
47: }
48:
49: /**
50: * @param DOMElement $node
51: * @param Item $item
52: */
53: protected function executeAggregators(DOMElement $node, Item $item)
54: {
55: foreach ($this->aggregators as $aggregator) {
56: $aggregator->process($node, $item);
57: }
58: }
59:
60: /**
61: * @return array
62: */
63: abstract protected function getPropertiesMapping();
64:
65: /**
66: * @param DOMElement $node
67: * @param Item $item
68: */
69: protected function setProperties(DOMElement $node, Item $item)
70: {
71: $propertiesMapping = $this->getPropertiesMapping();
72: foreach ($propertiesMapping as $methodName => $propertyName) {
73: $value = $this->getNodeValueByTagName($node, $propertyName);
74: if ($value) {
75: $item->$methodName($value);
76: }
77: }
78: }
79: }
80: