comparison vendor/zendframework/zend-feed/src/Reader/Extension/Slash/Entry.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10 namespace Zend\Feed\Reader\Extension\Slash;
11
12 use Zend\Feed\Reader\Extension;
13
14 /**
15 */
16 class Entry extends Extension\AbstractEntry
17 {
18 /**
19 * Get the entry section
20 *
21 * @return string|null
22 */
23 public function getSection()
24 {
25 return $this->getData('section');
26 }
27
28 /**
29 * Get the entry department
30 *
31 * @return string|null
32 */
33 public function getDepartment()
34 {
35 return $this->getData('department');
36 }
37
38 /**
39 * Get the entry hit_parade
40 *
41 * @return array
42 */
43 public function getHitParade()
44 {
45 $name = 'hit_parade';
46
47 if (isset($this->data[$name])) {
48 return $this->data[$name];
49 }
50
51 $stringParade = $this->getData($name);
52 $hitParade = [];
53
54 if (!empty($stringParade)) {
55 $stringParade = explode(',', $stringParade);
56
57 foreach ($stringParade as $hit) {
58 $hitParade[] = $hit + 0; //cast to integer
59 }
60 }
61
62 $this->data[$name] = $hitParade;
63 return $hitParade;
64 }
65
66 /**
67 * Get the entry comments
68 *
69 * @return int
70 */
71 public function getCommentCount()
72 {
73 $name = 'comments';
74
75 if (isset($this->data[$name])) {
76 return $this->data[$name];
77 }
78
79 $comments = $this->getData($name, 'string');
80
81 if (!$comments) {
82 $this->data[$name] = null;
83 return $this->data[$name];
84 }
85
86 return $comments;
87 }
88
89 /**
90 * Get the entry data specified by name
91 * @param string $name
92 * @param string $type
93 *
94 * @return mixed|null
95 */
96 protected function getData($name, $type = 'string')
97 {
98 if (array_key_exists($name, $this->data)) {
99 return $this->data[$name];
100 }
101
102 $data = $this->xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/slash10:' . $name . ')');
103
104 if (!$data) {
105 $data = null;
106 }
107
108 $this->data[$name] = $data;
109
110 return $data;
111 }
112
113 /**
114 * Register Slash namespaces
115 *
116 * @return void
117 */
118 protected function registerNamespaces()
119 {
120 $this->xpath->registerNamespace('slash10', 'http://purl.org/rss/1.0/modules/slash/');
121 }
122 }