Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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       * If true (mbstring extension must be enabled), will use (slower) `mb_strlen`, `mb_convert_case`, `mb_substr`
  15       * and `mb_strpos` functions. Otherwise, the normal (ASCII-Only) functions will be used.
  16       *
  17       * @var bool
  18       */
  19      public $bMultibyteSupport;
  20  
  21      /**
  22       * The default charset for the CSS if no `@charset` rule is found. Defaults to utf-8.
  23       *
  24       * @var string
  25       */
  26      public $sDefaultCharset = 'utf-8';
  27  
  28      /**
  29       * Lenient parsing. When used (which is true by default), the parser will not choke
  30       * on unexpected tokens but simply ignore 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       * @param bool $bMultibyteSupport
  51       *
  52       * @return self fluent interface
  53       */
  54      public function withMultibyteSupport($bMultibyteSupport = true)
  55      {
  56          $this->bMultibyteSupport = $bMultibyteSupport;
  57          return $this;
  58      }
  59  
  60      /**
  61       * @param string $sDefaultCharset
  62       *
  63       * @return self fluent interface
  64       */
  65      public function withDefaultCharset($sDefaultCharset)
  66      {
  67          $this->sDefaultCharset = $sDefaultCharset;
  68          return $this;
  69      }
  70  
  71      /**
  72       * @param bool $bLenientParsing
  73       *
  74       * @return self fluent interface
  75       */
  76      public function withLenientParsing($bLenientParsing = true)
  77      {
  78          $this->bLenientParsing = $bLenientParsing;
  79          return $this;
  80      }
  81  
  82      /**
  83       * @return self fluent interface
  84       */
  85      public function beStrict()
  86      {
  87          return $this->withLenientParsing(false);
  88      }
  89  }