blob: 02b7ea11d542240cfd6b4e7acab66bce6f7447f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?php
// Icinga Web 2 Cube Module | (c) 2020 Icinga GmbH | GPLv2
namespace Icinga\Module\Cube;
use Icinga\Web\Url;
class DimensionParams
{
/**
* @var array Raw dimensions
*/
protected $dimensions = [];
/**
* @var string encoded dimensions separated by coma
*/
protected $params;
// For the form: DimensionsParam::fromUrl($url)
public static function fromUrl(Url $url)
{
return static::fromString($url->getParam('dimensions'));
}
public static function fromArray(array $dimensions = [])
{
$self = new static();
$self->dimensions = array_filter($dimensions);
return $self;
}
// For the controller: DimensionsParam::fromArray($this->params->shift('dimensions'))
public static function fromString($dimensions)
{
return static::fromArray(explode(',', $dimensions));
}
/**
* @param $dimension
*
* @return $this
*/
public function add($dimension)
{
if (! empty($dimension)) {
$this->dimensions[] = $dimension;
}
return $this;
}
/**
* Overwrite dimensions
*
* @param $dimensions
*
* @return $this
*/
public static function update($dimensions)
{
$self = new static();
$self->dimensions = $dimensions;
return $self;
}
/**
* @return string encoded dimensions separated by coma
*/
public function getParams()
{
return implode(',', $this->dimensions);
}
/**
* @return array
*/
public function getDimensions()
{
return $this->dimensions;
}
}
|