1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace League\HTMLToMarkdown; |
6
|
|
|
|
7
|
|
|
class Configuration |
8
|
|
|
{ |
9
|
|
|
/** @var array<string, mixed> */ |
10
|
|
|
protected $config; |
11
|
|
|
|
12
|
102 |
|
/** |
13
|
|
|
* @param array<string, mixed> $config |
14
|
102 |
|
*/ |
15
|
|
|
public function __construct(array $config = []) |
16
|
102 |
|
{ |
17
|
102 |
|
$this->config = $config; |
18
|
|
|
|
19
|
|
|
$this->checkForDeprecatedOptions($config); |
20
|
|
|
} |
21
|
|
|
|
22
|
96 |
|
/** |
23
|
|
|
* @param array<string, mixed> $config |
24
|
96 |
|
*/ |
25
|
96 |
|
public function merge(array $config = []): void |
26
|
96 |
|
{ |
27
|
|
|
$this->checkForDeprecatedOptions($config); |
28
|
|
|
$this->config = \array_replace_recursive($this->config, $config); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array<string, mixed> $config |
33
|
|
|
*/ |
34
|
|
|
public function replace(array $config = []): void |
35
|
|
|
{ |
36
|
|
|
$this->checkForDeprecatedOptions($config); |
37
|
|
|
$this->config = $config; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
6 |
|
* @param mixed $value |
42
|
|
|
*/ |
43
|
6 |
|
public function setOption(string $key, $value): void |
44
|
6 |
|
{ |
45
|
6 |
|
$this->checkForDeprecatedOptions([$key => $value]); |
46
|
|
|
$this->config[$key] = $value; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed|null $default |
51
|
|
|
* |
52
|
|
|
* @return mixed|null |
53
|
96 |
|
*/ |
54
|
|
|
public function getOption(?string $key = null, $default = null) |
55
|
96 |
|
{ |
56
|
|
|
if ($key === null) { |
57
|
|
|
return $this->config; |
58
|
|
|
} |
59
|
96 |
|
|
60
|
18 |
|
if (! isset($this->config[$key])) { |
61
|
|
|
return $default; |
62
|
|
|
} |
63
|
93 |
|
|
64
|
|
|
return $this->config[$key]; |
65
|
|
|
} |
66
|
102 |
|
|
67
|
|
|
/** |
68
|
102 |
|
* @param array<string, mixed> $config |
69
|
96 |
|
*/ |
70
|
3 |
|
private function checkForDeprecatedOptions(array $config): void |
71
|
96 |
|
{ |
72
|
34 |
|
foreach ($config as $key => $value) { |
73
|
2 |
|
if ($key === 'bold_style' && $value !== '**') { |
74
|
68 |
|
@\trigger_error('Customizing the bold_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED); |
75
|
102 |
|
} elseif ($key === 'italic_style' && $value !== '*') { |
76
|
|
|
@\trigger_error('Customizing the italic_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|