Completed
Push — master ( c7133e...ae87f2 )
by Nazar
06:07
created

Request   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 2
lcom 1
cbo 6
ccs 12
cts 12
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 1
A init_from_globals() 0 3 1
1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs;
9
use
10
	cs\Request\Cookie,
11
	cs\Request\Data_and_files,
12
	cs\Request\Query,
13
	cs\Request\Route,
14
	cs\Request\Server;
15
16
/**
17
 * Provides next events:
18
 *  System/Request/routing_replace
19
 *  ['rc'    => &$rc] //Reference to string with current route, this string can be changed
20
 *
21
 * @method static $this instance($check = false)
22
 */
23
class Request {
24
	use
25
		Singleton,
26
		Cookie,
27
		Data_and_files,
28
		Query,
29
		Route,
30
		Server;
31
	/**
32
	 * Global request id, used by system
33
	 *
34
	 * @var int
35
	 */
36
	public static $id = 0;
37
	/**
38
	 * Unix timestamp when request processing started
39
	 *
40
	 * @var float
41
	 */
42
	public $started;
43
	/**
44
	 * Initialize request object with specified data
45
	 *
46
	 * @param string[]             $server          Typically `$_SERVER`
47
	 * @param array                $query           Typically `$_GET`
48
	 * @param array                $data            Typically `$_POST`
49
	 * @param array[]              $files           Typically `$_FILES`; might be like native PHP array `$_FILES` or normalized; each file item MUST contain
50
	 *                                              keys `name`, `type`, `size`, `error` and at least one of `tmp_name` or `stream`
51
	 * @param null|resource|string $data_stream     String, like `php://input` or resource, like `fopen('php://input', 'rb')`
52
	 * @param string[]             $cookie          Typically `$_COOKIE`
53
	 * @param float                $request_started Unix timestamp when request processing started
54
	 *
55
	 * @throws ExitException
56
	 */
57 24
	function init ($server, $query, $data, $files, $data_stream, $cookie, $request_started) {
58 24
		++static::$id;
59 24
		$this->init_server($server);
60 24
		$this->init_query($query);
61 24
		$this->init_data_and_files($data, $files, $data_stream);
62 24
		$this->init_cookie($cookie);
63 24
		$this->init_route();
64 24
		$this->started = $request_started;
65 24
	}
66
	/**
67
	 * Initialize request object from superglobals `$_SERVER`, `$_GET`, `$_POST`, `$_COOKIE` and `$_FILES` (including parsing `php://input` when necessary)
68
	 *
69
	 * @throws ExitException
70
	 */
71 24
	function init_from_globals () {
72 24
		$this->init($_SERVER, $_GET, $_POST, $_FILES, 'php://input', $_COOKIE, MICROTIME);
73 24
	}
74
}
75