1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\API; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\ArgumentHelper; |
15
|
|
|
use WBW\Library\Core\Exception\Argument\StringArgumentException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DataTables options. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\API |
22
|
|
|
*/ |
23
|
|
|
class DataTablesOptions { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Options. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $options; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
*/ |
35
|
|
|
public function __construct() { |
36
|
|
|
$this->setOptions([]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Ad an option. |
41
|
|
|
* |
42
|
|
|
* @param string $name The name. |
43
|
|
|
* @param mixed $value The value. |
44
|
|
|
* @return DataTablesOptions Returns this options. |
45
|
|
|
* @throws StringArgumentException Throws a string argument exception if the argument is not a string. |
46
|
|
|
*/ |
47
|
|
|
public function addOption($name, $value) { |
48
|
|
|
ArgumentHelper::isTypeOf($name, ArgumentHelper::ARGUMENT_STRING); |
49
|
|
|
if (false === array_key_exists($name, $this->options)) { |
50
|
|
|
$this->options[$name] = $value; |
51
|
|
|
} |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get an option. |
57
|
|
|
* |
58
|
|
|
* @param string $name The name. |
59
|
|
|
* @return mixed Returns the option in case of success, null otherwise. |
60
|
|
|
*/ |
61
|
|
|
public function getOption($name) { |
62
|
|
|
if (true === array_key_exists($name, $this->options)) { |
63
|
|
|
return $this->options[$name]; |
64
|
|
|
} |
65
|
|
|
return null; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the options. |
70
|
|
|
* |
71
|
|
|
* @return array Returns the options. |
72
|
|
|
*/ |
73
|
|
|
public function getOptions() { |
74
|
|
|
return $this->options; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Determines if an option exists. |
79
|
|
|
* |
80
|
|
|
* @param string $name The name. |
81
|
|
|
* @return bool Returns true in case of success, false otherwise. |
82
|
|
|
*/ |
83
|
|
|
public function hasOption($name) { |
84
|
|
|
return array_key_exists($name, $this->options); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Remove an option. |
89
|
|
|
* |
90
|
|
|
* @param string $name The name. |
91
|
|
|
* @return DataTablesOptions Returns this option. |
92
|
|
|
*/ |
93
|
|
|
public function removeOption($name) { |
94
|
|
|
if (true === array_key_exists($name, $this->options)) { |
95
|
|
|
unset($this->options[$name]); |
96
|
|
|
} |
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set an option. |
102
|
|
|
* |
103
|
|
|
* @param string $name The name. |
104
|
|
|
* @param mixed $value The value. |
105
|
|
|
* @return DataTablesOptions Returns this options. |
106
|
|
|
* @throws StringArgumentException Throws a string argument exception if the argument is not a string. |
107
|
|
|
*/ |
108
|
|
|
public function setOption($name, $value) { |
109
|
|
|
ArgumentHelper::isTypeOf($name, ArgumentHelper::ARGUMENT_STRING); |
110
|
|
|
$this->options[$name] = $value; |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set the options. |
116
|
|
|
* |
117
|
|
|
* @param array $options Thhe options. |
118
|
|
|
* @return DataTablesOptions Returns this options. |
119
|
|
|
*/ |
120
|
|
|
protected function setOptions(array $options) { |
121
|
|
|
$this->options = $options; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
} |
126
|
|
|
|