1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Phalcon Framework. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Phalcon\Html\Helper; |
13
|
|
|
|
14
|
|
|
use Phalcon\Html\Exception; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Title |
18
|
|
|
* |
19
|
|
|
* @property array $append |
20
|
|
|
* @property string $delimiter |
21
|
|
|
* @property string $indent |
22
|
|
|
* @property array $prepend |
23
|
|
|
* @property string $title |
24
|
|
|
* @property string $separator |
25
|
|
|
*/ |
26
|
|
|
class Title extends AbstractHelper |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $append = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $delimiter = PHP_EOL; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $indent = " "; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $prepend = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $title = ''; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $separator = ''; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Sets the separator and returns the object back |
60
|
|
|
* |
61
|
|
|
* @param string $separator |
62
|
|
|
* @param string|null $indent |
63
|
|
|
* @param string|null $delimiter |
64
|
|
|
* |
65
|
|
|
* @return Title |
66
|
|
|
*/ |
67
|
1 |
|
public function __invoke( |
68
|
|
|
string $separator = '', |
69
|
|
|
string $indent = null, |
70
|
|
|
string $delimiter = null |
71
|
|
|
): Title { |
72
|
1 |
|
$this->delimiter = $delimiter; |
73
|
1 |
|
$this->indent = $indent; |
74
|
1 |
|
$this->separator = $separator; |
75
|
|
|
|
76
|
1 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the title tags |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
* @throws Exception |
84
|
|
|
*/ |
85
|
1 |
|
public function __toString() |
86
|
|
|
{ |
87
|
1 |
|
$items = array_merge( |
88
|
1 |
|
$this->prepend, |
89
|
1 |
|
[$this->title], |
90
|
1 |
|
$this->append |
91
|
|
|
); |
92
|
|
|
|
93
|
1 |
|
$indent = $this->indent ? $this->indent : ''; |
94
|
1 |
|
$delimiter = $this->delimiter ? $this->delimiter : ''; |
95
|
|
|
|
96
|
1 |
|
$this->append = []; |
97
|
1 |
|
$this->prepend = []; |
98
|
1 |
|
$this->title = ''; |
99
|
|
|
|
100
|
|
|
return $indent |
101
|
1 |
|
. $this->renderFullElement( |
102
|
1 |
|
'title', |
103
|
1 |
|
implode($this->separator, $items), |
104
|
1 |
|
[], |
105
|
1 |
|
true |
106
|
|
|
) |
107
|
1 |
|
. $delimiter; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Appends text to current document title |
112
|
|
|
* |
113
|
|
|
* @param string $text |
114
|
|
|
* @param bool $raw |
115
|
|
|
* |
116
|
|
|
* @return Title |
117
|
|
|
*/ |
118
|
1 |
|
public function append(string $text, bool $raw = false): Title |
119
|
|
|
{ |
120
|
1 |
|
$text = $raw ? $text : $this->escaper->html($text); |
121
|
|
|
|
122
|
1 |
|
$this->append[] = $text; |
123
|
|
|
|
124
|
1 |
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns the title |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
1 |
|
public function get(): string |
133
|
|
|
{ |
134
|
1 |
|
return $this->title; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Sets the title |
139
|
|
|
* |
140
|
|
|
* @param string $text |
141
|
|
|
* @param bool $raw |
142
|
|
|
* |
143
|
|
|
* @return Title |
144
|
|
|
*/ |
145
|
1 |
|
public function set(string $text, bool $raw = false): Title |
146
|
|
|
{ |
147
|
1 |
|
$text = $raw ? $text : $this->escaper->html($text); |
148
|
|
|
|
149
|
1 |
|
$this->title = $text; |
150
|
|
|
|
151
|
1 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Prepends text to current document title |
156
|
|
|
* |
157
|
|
|
* @param string $text |
158
|
|
|
* @param bool $raw |
159
|
|
|
* |
160
|
|
|
* @return Title |
161
|
|
|
*/ |
162
|
1 |
|
public function prepend(string $text, bool $raw = false): Title |
163
|
|
|
{ |
164
|
1 |
|
$text = $raw ? $text : $this->escaper->html($text); |
165
|
|
|
|
166
|
1 |
|
$this->prepend[] = $text; |
167
|
|
|
|
168
|
1 |
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// public static function checkField(var parameters) -> string |
172
|
|
|
// public static function endForm() -> string |
173
|
|
|
// public static function fileField(var parameters) -> string |
174
|
|
|
// public static function linkTo(parameters, text = null, local = true) -> string |
175
|
|
|
// public static function radioField(var parameters) -> string |
176
|
|
|
// public static function select(var parameters, data = null) -> string |
177
|
|
|
// public static function selectStatic(parameters, data = null) -> string |
178
|
|
|
// public static function tagHtml( string tagName, var parameters = null, |
179
|
|
|
// bool selfClose = false, bool onlyStart = false, bool useEol = false) -> string |
180
|
|
|
// public static function tagHtmlClose(string tagName, bool useEol = false) -> string |
181
|
|
|
} |
182
|
|
|
|