|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Request Utils basic file. |
|
4
|
|
|
* |
|
5
|
|
|
* @package App |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright YetiForce Sp. z o.o |
|
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace App; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Request Utils basic class. |
|
16
|
|
|
*/ |
|
17
|
|
|
class RequestUtil |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var bool Cache https check variable. */ |
|
20
|
|
|
protected static $httpsCache; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string Cache request id variable. */ |
|
23
|
|
|
protected static $requestId; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Browser cache variable. |
|
27
|
|
|
* |
|
28
|
|
|
* @var stdClass |
|
29
|
|
|
*/ |
|
30
|
|
|
protected static $browserCache; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Get browser details. |
|
34
|
|
|
* |
|
35
|
|
|
* @return object |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function getBrowserInfo(): object |
|
38
|
|
|
{ |
|
39
|
|
|
if (empty(self::$browserCache)) { |
|
40
|
|
|
$browserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); |
|
41
|
|
|
$browser = new \stdClass(); |
|
42
|
|
|
$browser->win = false !== strpos($browserAgent, 'win'); |
|
43
|
|
|
$browser->mac = false !== strpos($browserAgent, 'mac'); |
|
44
|
|
|
$browser->linux = false !== strpos($browserAgent, 'linux'); |
|
45
|
|
|
$browser->unix = false !== strpos($browserAgent, 'unix'); |
|
46
|
|
|
$browser->webkit = false !== strpos($browserAgent, 'applewebkit'); |
|
47
|
|
|
$browser->opera = false !== strpos($browserAgent, 'opera') || ($browser->webkit && false !== strpos($browserAgent, 'opr/')); |
|
48
|
|
|
$browser->ns = false !== strpos($browserAgent, 'netscape'); |
|
49
|
|
|
$browser->chrome = !$browser->opera && false !== strpos($browserAgent, 'chrome'); |
|
50
|
|
|
$browser->ie = !$browser->opera && (false !== strpos($browserAgent, 'compatible; msie') || false !== strpos($browserAgent, 'trident/')); |
|
51
|
|
|
$browser->safari = !$browser->opera && !$browser->chrome && ($browser->webkit || false !== strpos($browserAgent, 'safari')); |
|
52
|
|
|
$browser->mz = !$browser->ie && !$browser->safari && !$browser->chrome && !$browser->ns && !$browser->opera && false !== strpos($browserAgent, 'mozilla'); |
|
53
|
|
|
|
|
54
|
|
|
if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $browserAgent, $regs)) { |
|
55
|
|
|
$browser->lang = $regs[1]; |
|
56
|
|
|
} else { |
|
57
|
|
|
$browser->lang = 'en'; |
|
58
|
|
|
} |
|
59
|
|
|
$browser->https = self::isHttps(); |
|
60
|
|
|
self::$browserCache = $browser; |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
return self::$browserCache; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Check that the connection is https. |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function isHttps(): bool |
|
71
|
|
|
{ |
|
72
|
|
|
if (!isset(self::$httpsCache)) { |
|
73
|
|
|
self::$httpsCache = (!empty($_SERVER['HTTPS']) && 'off' !== strtolower($_SERVER['HTTPS'])) |
|
74
|
|
|
|| (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === strtolower($_SERVER['HTTP_X_FORWARDED_PROTO'])); |
|
75
|
|
|
} |
|
76
|
|
|
return self::$httpsCache; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get request id. |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function requestId(): string |
|
85
|
|
|
{ |
|
86
|
|
|
if (empty(self::$requestId)) { |
|
87
|
|
|
self::$requestId = sprintf('%08x', abs(crc32($_SERVER['REMOTE_ADDR'] . $_SERVER['REQUEST_TIME'] . $_SERVER['REMOTE_PORT']))); |
|
88
|
|
|
} |
|
89
|
|
|
return self::$requestId; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..