1 | <?php |
||
24 | final class DeviceView extends Nette\Object |
||
25 | { |
||
26 | const VIEW_MOBILE = 'mobile'; |
||
27 | const VIEW_PHONE = 'phone'; |
||
28 | const VIEW_TABLET = 'tablet'; |
||
29 | const VIEW_FULL = 'full'; |
||
30 | const VIEW_NOT_MOBILE = 'not_mobile'; |
||
31 | |||
32 | /** |
||
33 | * @var Http\IRequest |
||
34 | */ |
||
35 | private $httpRequest; |
||
36 | |||
37 | /** |
||
38 | * @var Http\IResponse |
||
39 | */ |
||
40 | private $httpResponse; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $viewType = self::VIEW_FULL; |
||
46 | |||
47 | /** |
||
48 | * @var CookieSettings |
||
49 | */ |
||
50 | private $cookieSettings; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $switchParameterName = 'device_view'; |
||
56 | |||
57 | /** |
||
58 | * @param string $setSwitchParameterName |
||
59 | * @param CookieSettings $cookieSettings |
||
60 | * @param Http\IRequest $httpRequest |
||
61 | * @param Http\IResponse $httpResponse |
||
62 | */ |
||
63 | public function __construct(string $setSwitchParameterName, CookieSettings $cookieSettings, Http\IRequest $httpRequest, Http\IResponse $httpResponse) |
||
78 | |||
79 | /** |
||
80 | * Gets the view type for a device |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getViewType() : string |
||
88 | |||
89 | /** |
||
90 | * Is the device in full view |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isFullView() : bool |
||
98 | |||
99 | /** |
||
100 | * Is the device a tablet view type |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function isTabletView() : bool |
||
108 | |||
109 | /** |
||
110 | * Is the device a phone view type |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isPhoneView() : bool |
||
118 | |||
119 | /** |
||
120 | * Is the device a mobile view type |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function isMobileView() : bool |
||
128 | |||
129 | /** |
||
130 | * Is not the device a mobile view type (PC, Mac, etc.) |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isNotMobileView() : bool |
||
138 | |||
139 | /** |
||
140 | * Sets the tablet view type |
||
141 | * |
||
142 | * @return void |
||
143 | */ |
||
144 | public function setTabletView() |
||
148 | |||
149 | /** |
||
150 | * Sets the phone view type |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | public function setPhoneView() |
||
158 | |||
159 | /** |
||
160 | * Sets the mobile view type |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | public function setMobileView() |
||
168 | |||
169 | /** |
||
170 | * Sets the not mobile view type |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function setNotMobileView() |
||
178 | |||
179 | /** |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getSwitchParameterName() : string |
||
186 | |||
187 | /** |
||
188 | * Gets the switch param value from the query string (GET header) |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getSwitchParameterValue() : string |
||
196 | |||
197 | /** |
||
198 | * Has the Request the switch param in the query string (GET header) |
||
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function hasSwitchParameter() : bool |
||
206 | |||
207 | /** |
||
208 | * Gets the RedirectResponse by switch param value |
||
209 | * |
||
210 | * @param string $redirectUrl |
||
211 | * |
||
212 | * @return Application\Responses\RedirectResponse |
||
213 | */ |
||
214 | public function getRedirectResponseBySwitchParam(string $redirectUrl) : Application\Responses\RedirectResponse |
||
238 | |||
239 | /** |
||
240 | * Modifies the Response for non-mobile devices |
||
241 | * |
||
242 | * @return Http\IResponse |
||
243 | */ |
||
244 | public function modifyNotMobileResponse() : Http\IResponse |
||
251 | |||
252 | /** |
||
253 | * Modifies the Response for tablet devices |
||
254 | * |
||
255 | * @return Http\IResponse |
||
256 | */ |
||
257 | public function modifyTabletResponse() : Http\IResponse |
||
264 | |||
265 | /** |
||
266 | * Modifies the Response for phone devices |
||
267 | * |
||
268 | * @return Http\IResponse |
||
269 | */ |
||
270 | public function modifyPhoneResponse() : Http\IResponse |
||
277 | |||
278 | /** |
||
279 | * Modifies the Response for mobile devices |
||
280 | * |
||
281 | * @return Http\IResponse |
||
282 | */ |
||
283 | public function modifyMobileResponse() : Http\IResponse |
||
290 | |||
291 | /** |
||
292 | * Gets the RedirectResponse for phone devices |
||
293 | * |
||
294 | * @param string $host Uri host |
||
295 | * @param int $statusCode Status code |
||
296 | * |
||
297 | * @return Application\Responses\RedirectResponse |
||
298 | */ |
||
299 | public function getPhoneRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
306 | |||
307 | /** |
||
308 | * Gets the RedirectResponse for tablet devices |
||
309 | * |
||
310 | * @param string $host Uri host |
||
311 | * @param int $statusCode Status code |
||
312 | * |
||
313 | * @return Application\Responses\RedirectResponse |
||
314 | */ |
||
315 | public function getTabletRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
322 | |||
323 | /** |
||
324 | * Gets the RedirectResponse for mobile devices |
||
325 | * |
||
326 | * @param string $host Uri host |
||
327 | * @param int $statusCode Status code |
||
328 | * |
||
329 | * @return Application\Responses\RedirectResponse |
||
330 | */ |
||
331 | public function getMobileRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
338 | |||
339 | /** |
||
340 | * Gets the cookie |
||
341 | * |
||
342 | * @param string $cookieValue |
||
343 | */ |
||
344 | private function createCookie(string $cookieValue) |
||
357 | } |
||
358 |