1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pfilsx\DataGrid\Config; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class DataGridConfiguration |
8
|
|
|
* @package Pfilsx\DataGrid\Config |
9
|
|
|
* @internal |
10
|
|
|
*/ |
11
|
|
|
class Configuration implements ConfigurationInterface |
12
|
|
|
{ |
13
|
|
|
protected $template; |
14
|
|
|
|
15
|
|
|
protected $noDataMessage; |
16
|
|
|
|
17
|
|
|
protected $paginationLimit; |
18
|
|
|
|
19
|
|
|
protected $paginationEnabled; |
20
|
|
|
|
21
|
|
|
protected $translationDomain; |
22
|
|
|
|
23
|
|
|
public function __construct(array $config = []) |
24
|
|
|
{ |
25
|
|
|
foreach ($config as $key => $value) { |
26
|
|
|
$key = str_replace('_', '', $key); |
27
|
|
|
$setter = 'set' . $key; |
28
|
|
|
if (method_exists($this, $setter)) { |
29
|
|
|
$this->$setter($value); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getTemplate(): ?string |
35
|
|
|
{ |
36
|
|
|
return $this->template; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function setTemplate(string $template): void |
40
|
|
|
{ |
41
|
|
|
$this->template = $template; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getNoDataMessage(): ?string |
45
|
|
|
{ |
46
|
|
|
return $this->noDataMessage; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setNoDataMessage(string $message): void |
50
|
|
|
{ |
51
|
|
|
$this->noDataMessage = $message; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setPaginationEnabled(bool $value): void |
55
|
|
|
{ |
56
|
|
|
$this->paginationEnabled = $value; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setPaginationLimit(int $limit): void |
60
|
|
|
{ |
61
|
|
|
$this->paginationLimit = $limit; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function setTranslationDomain(?string $domain): void |
66
|
|
|
{ |
67
|
|
|
$this->translationDomain = $domain; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getConfigsArray(): array |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
'template' => $this->getTemplate(), |
74
|
|
|
'paginationEnabled' => $this->getPaginationEnabled(), |
75
|
|
|
'paginationLimit' => $this->getPaginationLimit(), |
76
|
|
|
'noDataMessage' => $this->getNoDataMessage(), |
77
|
|
|
'translationDomain' => $this->getTranslationDomain() |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function merge(ConfigurationInterface $configuration): ConfigurationInterface |
82
|
|
|
{ |
83
|
|
|
$result = clone $this; |
84
|
|
|
foreach ($configuration->getConfigsArray() as $key => $value) { |
85
|
|
|
if ($value !== null) { |
86
|
|
|
$setter = 'set' . ucfirst($key); |
87
|
|
|
$result->$setter($value); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
return $result; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getPaginationLimit(): ?int |
94
|
|
|
{ |
95
|
|
|
return $this->paginationLimit; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getPaginationEnabled(): ?bool |
99
|
|
|
{ |
100
|
|
|
return $this->paginationEnabled; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getTranslationDomain(): ?string |
104
|
|
|
{ |
105
|
|
|
return $this->translationDomain; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|