1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Message\Request; |
4
|
|
|
|
5
|
|
|
use Jalle19\StatusManager\Exception\MalformedRequestException; |
6
|
|
|
use Jalle19\StatusManager\Message\AbstractMessage; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Base class for all requests for statistics |
10
|
|
|
* |
11
|
|
|
* @package Jalle19\StatusManager\Message\Request |
12
|
|
|
* @copyright Copyright © Sam Stenvall 2016- |
13
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
14
|
|
|
*/ |
15
|
|
|
abstract class StatisticsRequest extends AbstractMessage |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
const TIME_INTERVAL_ALL_TIME = 'allTime'; |
19
|
|
|
const TIME_INTERVAL_LAST_MONTH = 'lastMonth'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $_instanceName; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $_timeInterval; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* StatisticsRequest constructor. |
34
|
|
|
* |
35
|
|
|
* @param string $type |
36
|
|
|
* @param \stdClass $parameters |
37
|
|
|
* |
38
|
|
|
* @throws MalformedRequestException |
39
|
|
|
*/ |
40
|
1 |
|
public function __construct($type, $parameters) |
41
|
|
|
{ |
42
|
1 |
|
parent::__construct($type, $parameters); |
43
|
|
|
|
44
|
|
|
/* @var \stdClass $parameters */ |
45
|
1 |
|
if (!isset($parameters->instanceName) || empty($parameters->instanceName)) |
46
|
1 |
|
throw new MalformedRequestException('Missing mandatory "instanceName" parameter'); |
47
|
|
|
|
48
|
|
|
$this->_instanceName = $parameters->instanceName; |
49
|
|
|
|
50
|
|
|
if (isset($parameters->timeInterval)) |
51
|
|
|
$this->_timeInterval = $parameters->timeInterval; |
52
|
|
|
else |
53
|
|
|
$this->_timeInterval = self::TIME_INTERVAL_ALL_TIME; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getInstanceName() |
61
|
|
|
{ |
62
|
|
|
return $this->_instanceName; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getTimeInterval() |
70
|
|
|
{ |
71
|
|
|
return $this->_timeInterval; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|