|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
namespace PHPHtmlParser; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Options |
|
6
|
|
|
* |
|
7
|
|
|
* @package PHPHtmlParser |
|
8
|
|
|
* @property bool $whitespaceTextNode |
|
9
|
|
|
* @property bool $strict |
|
10
|
|
|
* @property string|null $enforceEncoding |
|
11
|
|
|
* @property bool $cleanupInput |
|
12
|
|
|
* @property bool $removeScripts |
|
13
|
|
|
* @property bool $removeStyles |
|
14
|
|
|
* @property bool $preserveLineBreaks |
|
15
|
|
|
* @property bool $removeDoubleSpace |
|
16
|
|
|
* @property bool $removeSmartyScripts |
|
17
|
|
|
* @property bool $depthFirstSearch |
|
18
|
|
|
* @property bool $htmlSpecialCharsDecode |
|
19
|
|
|
*/ |
|
20
|
|
|
class Options |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The default options array |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $defaults = [ |
|
29
|
|
|
'whitespaceTextNode' => true, |
|
30
|
|
|
'strict' => false, |
|
31
|
|
|
'enforceEncoding' => null, |
|
32
|
|
|
'cleanupInput' => true, |
|
33
|
|
|
'removeScripts' => true, |
|
34
|
|
|
'removeStyles' => true, |
|
35
|
|
|
'preserveLineBreaks' => false, |
|
36
|
|
|
'removeDoubleSpace' => true, |
|
37
|
|
|
'removeSmartyScripts' => true, |
|
38
|
|
|
'depthFirstSearch' => false, |
|
39
|
|
|
'htmlSpecialCharsDecode' => false, |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The list of all current options set. |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $options = []; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Sets the default options in the options array |
|
51
|
|
|
*/ |
|
52
|
258 |
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
258 |
|
$this->options = $this->defaults; |
|
55
|
258 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* A magic get to call the get() method. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $key |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
* @uses $this->get() |
|
63
|
|
|
*/ |
|
64
|
252 |
|
public function __get($key) |
|
65
|
|
|
{ |
|
66
|
252 |
|
return $this->get($key); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Sets a new options param to override the current option array. |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $options |
|
73
|
|
|
* @return Options |
|
74
|
|
|
* @chainable |
|
75
|
|
|
*/ |
|
76
|
252 |
|
public function setOptions(array $options): Options |
|
77
|
|
|
{ |
|
78
|
252 |
|
foreach ($options as $key => $option) { |
|
79
|
63 |
|
$this->options[$key] = $option; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
252 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Gets the value associated to the key, or null if the key is not |
|
87
|
|
|
* found. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $key |
|
90
|
|
|
* @return mixed |
|
91
|
|
|
*/ |
|
92
|
258 |
|
public function get(string $key) |
|
93
|
|
|
{ |
|
94
|
258 |
|
if (isset($this->options[$key])) { |
|
95
|
255 |
|
return $this->options[$key]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
249 |
|
return null; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return current options as array |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
public function asArray() { |
|
107
|
|
|
return $this->options; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|