Completed
Push — master ( 6097a5...d36649 )
by Alexander
07:23 queued 03:45
created

HttpRequestAbstract   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 80
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setData() 0 4 1
getBody() 0 1 ?
check() 0 1 ?
A setStream() 0 4 1
A getValidator() 0 4 1
A setValidator() 0 6 1
A getData() 0 6 1
1
<?php
2
/**
3
 * Base class for http-request processing
4
 *
5
 * @file      HttpRequestAbstract.php
6
 *
7
 * PHP version 5.6+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2017 Alexander Yancharuk <alex at itvault at info>
11
 * @date      2017-01-18 10:14
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Request;
17
18
use Veles\Request\Validator\ValidatorInterface;
19
20
/**
21
 * Class   HttpRequestAbstract
22
 *
23
 * @author Yancharuk Alexander <alex at itvault at info>
24
 */
25
abstract class HttpRequestAbstract
26
{
27
	/** @var string  */
28
	protected $stream = 'php://input';
29
	protected $validator;
30
	/** @var array Valid data */
31
	protected $data;
32
33
	/**
34
	 * Save data after validation
35
	 *
36
	 * @param array $data
37
	 */
38
	protected function setData(array $data)
39
	{
40
		$this->data = $data;
41
	}
42
43
	/**
44
	 * Getting http-request body
45
	 *
46
	 * @return array
47
	 */
48
	abstract public function getBody();
49
50
	/**
51
	 * Check input according definitions
52
	 *
53
	 * @param mixed $definitions
54
	 */
55
	abstract public function check($definitions);
56
57
	/**
58
	 * Setting stream for request data reading
59
	 *
60
	 * @param string $stream
61
	 */
62
	public function setStream($stream)
63
	{
64
		$this->stream = $stream;
65
	}
66
67
	/**
68
	 * Getting validator
69
	 *
70
	 * @return ValidatorInterface
71
	 */
72
	public function getValidator()
73
	{
74
		return $this->validator;
75
	}
76
77
	/**
78
	 * Setting validator
79
	 *
80
	 * @param $validator
81
	 *
82
	 * @return $this
83
	 */
84
	public function setValidator(ValidatorInterface $validator)
85
	{
86
		$this->validator = $validator;
87
88
		return $this;
89
	}
90
91
	/**
92
	 * Getting valid data
93
	 *
94
	 * @param $definitions
95
	 *
96
	 * @return array
97
	 */
98
	public function getData($definitions)
99
	{
100
		$this->check($definitions);
101
102
		return $this->data;
103
	}
104
}
105