-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dimension.php
executable file
·64 lines (52 loc) · 1.29 KB
/
Dimension.php
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
<?php
namespace OLAP;
class Dimension extends Model
{
const PREFIX = 'dimension_';
/**
* @var Type
*/
private $type;
public function __construct($name, $type, $options = [])
{
$this->name = $name;
$this->type = $type instanceof Type ? $type : new Type($type);
$this->options = $options ?: [];
}
/**
* @return Type
*/
public function getType()
{
return $this->type;
}
public function isDenormalized()
{
return !empty($this->options['denormalized']);
}
public function getParent()
{
return empty($this->options['parent']) ? null : $this->makeName($this->options['parent']);
}
public function getIndex()
{
return empty($this->options['index']) ? 'btree' : $this->options['index'];
}
/**
* Return dimension value
* @param array $data
* @return mixed
*/
public function mapValue(array $data)
{
return (array_key_exists($this->name, $data) ? $data[$this->name] : null) ?: $this->emptyValue();
}
protected function makeName($name)
{
return self::PREFIX . $name;
}
protected function emptyValue()
{
return array_key_exists('empty', $this->options) ? $this->options['empty'] : '';
}
}