Passed
Push — developer ( 44b1b4...e20091 )
by Mariusz
167:14 queued 131:59
created

RequestUtil::requestId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
	 * Check that the connection is https.
27
	 *
28
	 * @return bool
29
	 */
30
	public static function isHttps(): bool
31
	{
32
		if (!isset(self::$httpsCache)) {
33
			self::$httpsCache = (!empty($_SERVER['HTTPS']) && 'off' !== strtolower($_SERVER['HTTPS']))
34
				|| (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']));
35
		}
36
		return self::$httpsCache;
37
	}
38
39
	/**
40
	 * Get request id.
41
	 *
42
	 * @return string
43
	 */
44
	public static function requestId(): string
45
	{
46
		if (empty(self::$requestId)) {
47
			self::$requestId = sprintf('%08x', abs(crc32($_SERVER['REMOTE_ADDR'] . $_SERVER['REQUEST_TIME'] . $_SERVER['REMOTE_PORT'])));
48
		}
49
		return self::$requestId;
50
	}
51
}
52