1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leogout\Bundle\SeoBundle\Model; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Description of LinkTag. |
7
|
|
|
* |
8
|
|
|
* @author: leogout |
9
|
|
|
*/ |
10
|
|
|
class LinkTag implements RenderableInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $type; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $rel; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $title; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $href; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getHref() |
36
|
|
|
{ |
37
|
|
|
return $this->href; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $href |
42
|
|
|
* |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function setHref($href) |
46
|
|
|
{ |
47
|
|
|
$this->href = (string) $href; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getRel() |
56
|
|
|
{ |
57
|
|
|
return $this->rel; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $rel |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public function setRel($rel) |
66
|
|
|
{ |
67
|
|
|
$this->rel = (string) $rel; |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getType() |
76
|
|
|
{ |
77
|
|
|
return $this->type; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $type |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
|
|
public function setType($type) |
86
|
|
|
{ |
87
|
|
|
$this->type = (string) $type; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getTitle() |
96
|
|
|
{ |
97
|
|
|
return $this->title; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $title |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function setTitle($title) |
106
|
|
|
{ |
107
|
|
|
$this->title = (string) $title; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns a string only if $value isn't null |
114
|
|
|
* |
115
|
|
|
* @param string $format |
116
|
|
|
* @param string $value |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
private function sprintfIfNotNull($format, $value) |
121
|
|
|
{ |
122
|
|
|
if ('' === $value || null === $value) { |
123
|
|
|
return ''; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return sprintf($format, $value); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function render() |
133
|
|
|
{ |
134
|
|
|
$href = $this->sprintfIfNotNull('href="%s" ', $this->getHref()); |
135
|
|
|
$rel = $this->sprintfIfNotNull('rel="%s" ', $this->getRel()); |
136
|
|
|
$type = $this->sprintfIfNotNull('type="%s" ', $this->getType()); |
137
|
|
|
$title = $this->sprintfIfNotNull('title="%s" ', $this->getTitle()); |
138
|
|
|
|
139
|
|
|
return sprintf('<link %s%s%s%s/>', $href, $rel, $type, $title); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function __toString() |
146
|
|
|
{ |
147
|
|
|
return $this->render(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|