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