Completed
Push — master ( 814b21...208c25 )
by Henry
05:27
created

Helper::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 0
cp 0
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
namespace Redaxscript\Template;
3
4
use Redaxscript\Asset;
5
use Redaxscript\Header;
6
use Redaxscript\Language;
7
use Redaxscript\Model;
8
use Redaxscript\Registry;
9
use function file_get_contents;
10
11
/**
12
 * helper class to provide template helper
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category Template
18
 * @author Henry Ruhs
19
 */
20
21
class Helper
22
{
23
	/**
24
	 * get the registry
25
	 *
26
	 * @since 2.6.0
27
	 *
28
	 * @param string $key
29
	 *
30
	 * @return string|array|null
31
	 */
32 1
33
	public static function getRegistry(string $key = null)
34 1
	{
35 1
		$registry = Registry::getInstance();
36
		return $registry->get($key);
37
	}
38
39
	/**
40
	 * get the language
41
	 *
42
	 * @since 2.6.0
43
	 *
44
	 * @param string $key
45
	 *
46
	 * @return string|array|null
47
	 */
48 1
49
	public static function getLanguage(string $key = null)
50 1
	{
51 1
		$language = Language::getInstance();
52
		return $language->get($key);
53
	}
54
55
	/**
56
	 * get the setting
57
	 *
58
	 * @since 2.6.0
59
	 *
60
	 * @param string $key
61
	 *
62
	 * @return string|null
63
	 */
64 1
65
	public static function getSetting(string $key = null) : ?string
66 1
	{
67 1
		$settingModel = new Model\Setting();
68
		return $settingModel->get($key);
69
	}
70
71
	/**
72
	 * get the title
73
	 *
74
	 * @since 3.0.0
75
	 *
76
	 * @return string|null
77
	 */
78 18
79
	public static function getTitle() : ?string
80 18
	{
81 18
		$title = new Helper\Title(Registry::getInstance(), Language::getInstance());
82
		return $title->process();
83
	}
84
85
	/**
86
	 * get the canonical
87
	 *
88
	 * @since 3.0.0
89
	 *
90
	 * @return string|null
91
	 */
92 6
93
	public static function getCanonical() : ?string
94 6
	{
95 6
		$canonical = new Helper\Canonical(Registry::getInstance(), Language::getInstance());
96
		return $canonical->process();
97
	}
98
99
	/**
100
	 * get the description
101
	 *
102
	 * @since 3.0.0
103
	 *
104
	 * @return string|null
105
	 */
106 8
107
	public static function getDescription() : ?string
108 8
	{
109 8
		$description = new Helper\Description(Registry::getInstance(), Language::getInstance());
110
		return $description->process();
111
	}
112
113
	/**
114
	 * get the keywords
115
	 *
116
	 * @since 3.0.0
117
	 *
118
	 * @return string|null
119
	 */
120 8
121
	public static function getKeywords() : ?string
122 8
	{
123 8
		$keywords = new Helper\Keywords(Registry::getInstance(), Language::getInstance());
124
		return $keywords->process();
125
	}
126
127
	/**
128
	 * get the robots
129
	 *
130
	 * @since 3.0.0
131
	 *
132
	 * @return string|null
133
	 */
134 6
135
	public static function getRobots() : ?string
136 6
	{
137 6
		$robots = new Helper\Robots(Registry::getInstance(), Language::getInstance());
138
		return $robots->process();
139
	}
140
141
	/**
142
	 * get the transport
143
	 *
144
	 * @since 3.0.0
145
	 *
146
	 * @return array
147
	 */
148 1
149
	public static function getTransport() : array
150 1
	{
151 1
		$transport = new Asset\Transport(Registry::getInstance(), Language::getInstance());
152
		return $transport->getArray();
153
	}
154
155
	/**
156
	 * get the subset
157
	 *
158
	 * @since 3.0.0
159
	 *
160
	 * @return string|null
161
	 */
162 4
163
	public static function getSubset() : ?string
164 4
	{
165 4
		$subset = new Helper\Subset(Registry::getInstance(), Language::getInstance());
166
		return $subset->process();
167
	}
168
169
	/**
170
	 * get the direction
171
	 *
172
	 * @since 3.0.0
173
	 *
174
	 * @return string|null
175
	 */
176 3
177
	public static function getDirection() : ?string
178 3
	{
179 3
		$direction = new Helper\Direction(Registry::getInstance(), Language::getInstance());
180
		return $direction->process();
181
	}
182
183
	/**
184
	 * get the class
185
	 *
186
	 * @since 3.0.0
187
	 *
188
	 * @param string $prefix
189
	 *
190
	 * @return string|null
191
	 */
192 4
193
	public static function getClass(string $prefix = null) : ?string
194 4
	{
195 4
		$client = new Helper\Client(Registry::getInstance(), Language::getInstance());
196
		return $client->process($prefix);
197
	}
198
199
	/**
200
	 * get the response code
201
	 *
202
	 * @since 4.0.0
203
	 *
204
	 * @return int
205
	 */
206
207
	public static function getResponseCode() : int
208
	{
209
		return Header::responseCode();
210
	}
211
212
	/**
213
	 * get the content
214
	 *
215
	 * @since 4.0.0
216
	 *
217
	 * @param string|array $file
218
	 *
219
	 * @return string|null
220
	 */
221
222
	public static function getContent($file = null) : ?string
223
	{
224
		$output = null;
225
226
		/* process file */
227
228
		foreach ((array)$file as $value)
229
		{
230
			$output .= file_get_contents($value);
231
		}
232
		return $output;
233
	}
234
}
235