| 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 |
* @internal since 8.8.0, will be made private in 9.0.0 |
| 21 |
*/ |
| 22 |
public $bMultibyteSupport; |
| 23 |
|
| 24 |
/** |
| 25 |
* The default charset for the CSS if no `@charset` declaration is found. Defaults to utf-8. |
| 26 |
* |
| 27 |
* @var string |
| 28 |
* |
| 29 |
* @internal since 8.8.0, will be made private in 9.0.0 |
| 30 |
*/ |
| 31 |
public $sDefaultCharset = 'utf-8'; |
| 32 |
|
| 33 |
/** |
| 34 |
* Whether the parser silently ignore invalid rules instead of choking on them. |
| 35 |
* |
| 36 |
* @var bool |
| 37 |
* |
| 38 |
* @internal since 8.8.0, will be made private in 9.0.0 |
| 39 |
*/ |
| 40 |
public $bLenientParsing = true; |
| 41 |
|
| 42 |
private function __construct() |
| 43 |
{ |
| 44 |
$this->bMultibyteSupport = extension_loaded('mbstring'); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* @return self new instance |
| 49 |
*/ |
| 50 |
public static function create() |
| 51 |
{ |
| 52 |
return new Settings(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Enables/disables multi-byte string support. |
| 57 |
* |
| 58 |
* If `true` (`mbstring` extension must be enabled), will use (slower) `mb_strlen`, `mb_convert_case`, `mb_substr` |
| 59 |
* and `mb_strpos` functions. Otherwise, the normal (ASCII-Only) functions will be used. |
| 60 |
* |
| 61 |
* @param bool $bMultibyteSupport |
| 62 |
* |
| 63 |
* @return self fluent interface |
| 64 |
*/ |
| 65 |
public function withMultibyteSupport($bMultibyteSupport = true) |
| 66 |
{ |
| 67 |
$this->bMultibyteSupport = $bMultibyteSupport; |
| 68 |
return $this; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Sets the charset to be used if the CSS does not contain an `@charset` declaration. |
| 73 |
* |
| 74 |
* @param string $sDefaultCharset |
| 75 |
* |
| 76 |
* @return self fluent interface |
| 77 |
*/ |
| 78 |
public function withDefaultCharset($sDefaultCharset) |
| 79 |
{ |
| 80 |
$this->sDefaultCharset = $sDefaultCharset; |
| 81 |
return $this; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Configures whether the parser should silently ignore invalid rules. |
| 86 |
* |
| 87 |
* @param bool $bLenientParsing |
| 88 |
* |
| 89 |
* @return self fluent interface |
| 90 |
*/ |
| 91 |
public function withLenientParsing($bLenientParsing = true) |
| 92 |
{ |
| 93 |
$this->bLenientParsing = $bLenientParsing; |
| 94 |
return $this; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Configures the parser to choke on invalid rules. |
| 99 |
* |
| 100 |
* @return self fluent interface |
| 101 |
*/ |
| 102 |
public function beStrict() |
| 103 |
{ |
| 104 |
return $this->withLenientParsing(false); |
| 105 |
} |
| 106 |
} |
| 107 |
|