Completed
Push — master ( e2f106...c79eb3 )
by Nazar
04:11
created

Data::init_data()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 3
eloc 5
nc 4
nop 2
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\Request;
9
10
trait Data {
11
	/**
12
	 * Data array, similar to `$_POST`
13
	 *
14
	 * @var array
15
	 */
16
	public $data;
17
	/**
18
	 * Data stream resource, similar to `fopen('php://input', 'br')`
19
	 *
20
	 * Make sure you're controlling position in stream where you read something, if code in some other place might seek on this stream
21
	 *
22
	 * @var null|resource
23
	 */
24
	public $data_stream;
25
	/**
26
	 * @param array                $data        Typically `$_POST`
27
	 * @param null|resource|string $data_stream String, like `php://input` or resource, like `fopen('php://input', 'br')`
28
	 */
29
	function init_data ($data = [], $data_stream = null) {
30
		if (is_resource($this->data_stream)) {
31
			fclose($this->data_stream);
32
		}
33
		$this->data        = $data;
34
		$this->data_stream = is_string($data_stream) ? fopen($data_stream, 'br') : $data_stream;
35
	}
36
}
37