aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Configuration.php
blob: 7e1d71e687e719842f5447e5d3ecd37b16c52a20 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

declare(strict_types=1);

namespace League\HTMLToMarkdown;

class Configuration
{
    /** @var array<string, mixed> */
    protected $config;

    /**
     * @param array<string, mixed> $config
     */
    public function __construct(array $config = [])
    {
        $this->config = $config;

        $this->checkForDeprecatedOptions($config);
    }

    /**
     * @param array<string, mixed> $config
     */
    public function merge(array $config = []): void
    {
        $this->checkForDeprecatedOptions($config);
        $this->config = \array_replace_recursive($this->config, $config);
    }

    /**
     * @param array<string, mixed> $config
     */
    public function replace(array $config = []): void
    {
        $this->checkForDeprecatedOptions($config);
        $this->config = $config;
    }

    /**
     * @param mixed $value
     */
    public function setOption(string $key, $value): void
    {
        $this->checkForDeprecatedOptions([$key => $value]);
        $this->config[$key] = $value;
    }

    /**
     * @param mixed|null $default
     *
     * @return mixed|null
     */
    public function getOption(?string $key = null, $default = null)
    {
        if ($key === null) {
            return $this->config;
        }

        if (! isset($this->config[$key])) {
            return $default;
        }

        return $this->config[$key];
    }

    /**
     * @param array<string, mixed> $config
     */
    private function checkForDeprecatedOptions(array $config): void
    {
        foreach ($config as $key => $value) {
            if ($key === 'bold_style' && $value !== '**') {
                @\trigger_error('Customizing the bold_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED);
            } elseif ($key === 'italic_style' && $value !== '*') {
                @\trigger_error('Customizing the italic_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED);
            }
        }
    }
}