1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Ntentan Framework |
4
|
|
|
* Copyright (c) 2008-2015 James Ekow Abaka Ainooson |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining |
7
|
|
|
* a copy of this software and associated documentation files (the |
8
|
|
|
* "Software"), to deal in the Software without restriction, including |
9
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, |
10
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to |
11
|
|
|
* permit persons to whom the Software is furnished to do so, subject to |
12
|
|
|
* the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be |
15
|
|
|
* included in all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
20
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
21
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
22
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
23
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace ntentan\honam\engines\php\helpers; |
27
|
|
|
|
28
|
|
|
use ntentan\honam\engines\php\Helper; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The FeedHelper provides a generic way of generating feeds. The FeedHelper has |
33
|
|
|
* drivers which generate specific feed formats RSS and (Atom in a later release). |
34
|
|
|
*/ |
35
|
|
|
class FeedHelper extends Helper |
36
|
|
|
{ |
37
|
|
|
private $items; |
38
|
|
|
private $properties = array(); |
39
|
|
|
private $format = 'rss'; |
40
|
|
|
|
41
|
|
|
public function help($items) |
42
|
|
|
{ |
43
|
|
|
$this->items = $items; |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setItems($items) |
48
|
|
|
{ |
49
|
|
|
$this->items = $items; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setTitle($title) |
54
|
|
|
{ |
55
|
|
|
$this->properties['title'] = $title; |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setUrl($url) |
60
|
|
|
{ |
61
|
|
|
$this->properties['url'] = $url; |
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setUpdated($updated) |
66
|
|
|
{ |
67
|
|
|
$this->properties['updated'] = $updated; |
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setDescription($desccription) |
72
|
|
|
{ |
73
|
|
|
$this->properties['description'] = $desccription; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function __toString() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$generatorClassName = ucfirst($this->format) . "Feed"; |
80
|
|
|
$generatorClass = __NAMESPACE__ . "\\feed\\generators\\$generatorClassName"; |
81
|
|
|
$generator = new $generatorClass(); |
82
|
|
|
$generator->setup($this->properties, $this->items); |
83
|
|
|
return $generator->generate(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.