1 | <?php |
||
31 | 1 | final class DeviceView |
|
32 | { |
||
33 | /** |
||
34 | * Implement nette smart magic |
||
35 | */ |
||
36 | 1 | use Nette\SmartObject; |
|
37 | |||
38 | public const VIEW_MOBILE = 'mobile'; |
||
39 | public const VIEW_PHONE = 'phone'; |
||
40 | public const VIEW_TABLET = 'tablet'; |
||
41 | public const VIEW_FULL = 'full'; |
||
42 | public const VIEW_NOT_MOBILE = 'not_mobile'; |
||
43 | |||
44 | /** |
||
45 | * @var Http\IRequest |
||
46 | */ |
||
47 | private $httpRequest; |
||
48 | |||
49 | /** |
||
50 | * @var Http\IResponse |
||
51 | */ |
||
52 | private $httpResponse; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $viewType = self::VIEW_FULL; |
||
58 | |||
59 | /** |
||
60 | * @var CookieSettings |
||
61 | */ |
||
62 | private $cookieSettings; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $switchParameterName = 'device_view'; |
||
68 | |||
69 | /** |
||
70 | * @param string $setSwitchParameterName |
||
71 | * @param CookieSettings $cookieSettings |
||
72 | * @param Http\IRequest $httpRequest |
||
73 | * @param Http\IResponse $httpResponse |
||
74 | */ |
||
75 | public function __construct(string $setSwitchParameterName, CookieSettings $cookieSettings, Http\IRequest $httpRequest, Http\IResponse $httpResponse) |
||
90 | |||
91 | /** |
||
92 | * Gets the view type for a device |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getViewType() : string |
||
100 | |||
101 | /** |
||
102 | * Is the device in full view |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function isFullView() : bool |
||
110 | |||
111 | /** |
||
112 | * Is the device a tablet view type |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isTabletView() : bool |
||
120 | |||
121 | /** |
||
122 | * Is the device a phone view type |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function isPhoneView() : bool |
||
130 | |||
131 | /** |
||
132 | * Is the device a mobile view type |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function isMobileView() : bool |
||
140 | |||
141 | /** |
||
142 | * Is not the device a mobile view type (PC, Mac, etc.) |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function isNotMobileView() : bool |
||
150 | |||
151 | /** |
||
152 | * Sets the tablet view type |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | public function setTabletView() : void |
||
160 | |||
161 | /** |
||
162 | * Sets the phone view type |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | public function setPhoneView() : void |
||
170 | |||
171 | /** |
||
172 | * Sets the mobile view type |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | public function setMobileView() : void |
||
180 | |||
181 | /** |
||
182 | * Sets the not mobile view type |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | public function setNotMobileView() : void |
||
190 | |||
191 | /** |
||
192 | * @return string |
||
193 | */ |
||
194 | public function getSwitchParameterName() : string |
||
198 | |||
199 | /** |
||
200 | * Gets the switch param value from the query string (GET header) |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getSwitchParameterValue() : string |
||
208 | |||
209 | /** |
||
210 | * Has the Request the switch param in the query string (GET header) |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | public function hasSwitchParameter() : bool |
||
218 | |||
219 | /** |
||
220 | * Gets the RedirectResponse by switch param value |
||
221 | * |
||
222 | * @param string $redirectUrl |
||
223 | * |
||
224 | * @return Application\Responses\RedirectResponse |
||
225 | */ |
||
226 | public function getRedirectResponseBySwitchParam(string $redirectUrl) : Application\Responses\RedirectResponse |
||
250 | |||
251 | /** |
||
252 | * Modifies the Response for non-mobile devices |
||
253 | * |
||
254 | * @return Http\IResponse |
||
255 | */ |
||
256 | public function modifyNotMobileResponse() : Http\IResponse |
||
263 | |||
264 | /** |
||
265 | * Modifies the Response for tablet devices |
||
266 | * |
||
267 | * @return Http\IResponse |
||
268 | */ |
||
269 | public function modifyTabletResponse() : Http\IResponse |
||
276 | |||
277 | /** |
||
278 | * Modifies the Response for phone devices |
||
279 | * |
||
280 | * @return Http\IResponse |
||
281 | */ |
||
282 | public function modifyPhoneResponse() : Http\IResponse |
||
289 | |||
290 | /** |
||
291 | * Modifies the Response for mobile devices |
||
292 | * |
||
293 | * @return Http\IResponse |
||
294 | */ |
||
295 | public function modifyMobileResponse() : Http\IResponse |
||
302 | |||
303 | /** |
||
304 | * Gets the RedirectResponse for phone devices |
||
305 | * |
||
306 | * @param string $host Uri host |
||
307 | * @param int $statusCode Status code |
||
308 | * |
||
309 | * @return Application\Responses\RedirectResponse |
||
310 | */ |
||
311 | public function getPhoneRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
318 | |||
319 | /** |
||
320 | * Gets the RedirectResponse for tablet devices |
||
321 | * |
||
322 | * @param string $host Uri host |
||
323 | * @param int $statusCode Status code |
||
324 | * |
||
325 | * @return Application\Responses\RedirectResponse |
||
326 | */ |
||
327 | public function getTabletRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
334 | |||
335 | /** |
||
336 | * Gets the RedirectResponse for mobile devices |
||
337 | * |
||
338 | * @param string $host Uri host |
||
339 | * @param int $statusCode Status code |
||
340 | * |
||
341 | * @return Application\Responses\RedirectResponse |
||
342 | */ |
||
343 | public function getMobileRedirectResponse(string $host, int $statusCode) : Application\Responses\RedirectResponse |
||
350 | |||
351 | /** |
||
352 | * Gets the cookie |
||
353 | * |
||
354 | * @param string $cookieValue |
||
355 | * |
||
356 | * @return void |
||
357 | */ |
||
358 | private function createCookie(string $cookieValue) : void |
||
371 | } |
||
372 |