Completed
Push — master ( 61475a...8376f2 )
by Nazar
04:08
created

Request::init_from_globals_get_data()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
rs 8.8571
cc 5
eloc 10
nc 4
nop 0
1
<?php
2
/**
3
 * @package   CleverStyle CMS
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\Compatibility,
11
	cs\Request\Cookie,
12
	cs\Request\Data_and_files,
13
	cs\Request\Query,
14
	cs\Request\Route as Request_route,
15
	cs\Request\Psr7,
16
	cs\Request\Server;
17
18
class Request implements \ArrayAccess, \Iterator {
19
	use
20
		Singleton,
21
		Compatibility,
22
		Cookie,
23
		Data_and_files,
24
		Query,
25
		Psr7,
26
		Request_route,
27
		Server;
28
29
	/**
30
	 * Initialize request object with specified data
31
	 *
32
	 * @param string[]             $server      Typically `$_SERVER`
33
	 * @param array                $query       Typically `$_GET`
34
	 * @param array                $data        Typically `$_POST`
35
	 * @param null|resource|string $data_stream String, like `php://input` or resource, like `fopen('php://input', 'rb')`
36
	 * @param string[]             $cookie      Typically `$_COOKIE`
37
	 * @param array[]              $files       Typically `$_FILES`; might be like native PHP array `$_FILES` or normalized; each file item MUST contain keys
38
	 *                                          `name`, `type`, `size`, `error` and at least one of `tmp_name` or `stream`
39
	 *
40
	 * @throws ExitException
41
	 */
42
	function init ($server, $query, $data, $data_stream, $cookie, $files) {
43
		$this->init_server($server);
44
		$this->init_query($query);
45
		$this->init_data_and_files($data, $files, $data_stream);
46
		$this->init_cookie($cookie);
47
		$this->init_route();
48
	}
49
	/**
50
	 * Initialize request object from superglobals `$_SERVER`, `$_GET`, `$_POST`, `$_COOKIE` and `$_FILES` (including parsing `php://input` in case of custom
51
	 * request methods)
52
	 *
53
	 * @throws ExitException
54
	 */
55
	function init_from_globals () {
56
		// Hack: we override `$_SERVER` with iterator object, so conversion from iterator to an array is needed
57
		$this->init_server(iterator_to_array($_SERVER));
58
		$this->init_query($_GET);
59
		$this->init_data_and_files($_POST, $_FILES, 'php://input');
60
		$this->init_cookie($_COOKIE);
61
		$this->init_route();
62
	}
63
}
64