Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace Sabberworm\CSS;
4
 
5
/**
6
 * Parser settings class.
7
 *
8
 * Configure parser behaviour here.
9
 */
10
class Settings
11
{
12
    /**
13
     * Multi-byte string support.
14
     *
15
     * If `true` (`mbstring` extension must be enabled), will use (slower) `mb_strlen`, `mb_convert_case`, `mb_substr`
16
     * and `mb_strpos` functions. Otherwise, the normal (ASCII-Only) functions will be used.
17
     *
18
     * @var bool
19
     */
20
    public $bMultibyteSupport;
21
 
22
    /**
23
     * The default charset for the CSS if no `@charset` declaration is found. Defaults to utf-8.
24
     *
25
     * @var string
26
     */
27
    public $sDefaultCharset = 'utf-8';
28
 
29
    /**
30
     * Whether the parser silently ignore invalid rules instead of choking on them.
31
     *
32
     * @var bool
33
     */
34
    public $bLenientParsing = true;
35
 
36
    private function __construct()
37
    {
38
        $this->bMultibyteSupport = extension_loaded('mbstring');
39
    }
40
 
41
    /**
42
     * @return self new instance
43
     */
44
    public static function create()
45
    {
46
        return new Settings();
47
    }
48
 
49
    /**
50
     * Enables/disables multi-byte string support.
51
     *
52
     * If `true` (`mbstring` extension must be enabled), will use (slower) `mb_strlen`, `mb_convert_case`, `mb_substr`
53
     * and `mb_strpos` functions. Otherwise, the normal (ASCII-Only) functions will be used.
54
     *
55
     * @param bool $bMultibyteSupport
56
     *
57
     * @return self fluent interface
58
     */
59
    public function withMultibyteSupport($bMultibyteSupport = true)
60
    {
61
        $this->bMultibyteSupport = $bMultibyteSupport;
62
        return $this;
63
    }
64
 
65
    /**
66
     * Sets the charset to be used if the CSS does not contain an `@charset` declaration.
67
     *
68
     * @param string $sDefaultCharset
69
     *
70
     * @return self fluent interface
71
     */
72
    public function withDefaultCharset($sDefaultCharset)
73
    {
74
        $this->sDefaultCharset = $sDefaultCharset;
75
        return $this;
76
    }
77
 
78
    /**
79
     * Configures whether the parser should silently ignore invalid rules.
80
     *
81
     * @param bool $bLenientParsing
82
     *
83
     * @return self fluent interface
84
     */
85
    public function withLenientParsing($bLenientParsing = true)
86
    {
87
        $this->bLenientParsing = $bLenientParsing;
88
        return $this;
89
    }
90
 
91
    /**
92
     * Configures the parser to choke on invalid rules.
93
     *
94
     * @return self fluent interface
95
     */
96
    public function beStrict()
97
    {
98
        return $this->withLenientParsing(false);
99
    }
100
}