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\Property;
   4  
   5  use Sabberworm\CSS\Comment\Comment;
   6  use Sabberworm\CSS\OutputFormat;
   7  
   8  /**
   9   * Class representing an `@charset` rule.
  10   *
  11   * The following restrictions apply:
  12   * - May not be found in any CSSList other than the Document.
  13   * - May only appear at the very top of a Document’s contents.
  14   * - Must not appear more than once.
  15   */
  16  class Charset implements AtRule
  17  {
  18      /**
  19       * @var string
  20       */
  21      private $sCharset;
  22  
  23      /**
  24       * @var int
  25       */
  26      protected $iLineNo;
  27  
  28      /**
  29       * @var array<array-key, Comment>
  30       */
  31      protected $aComments;
  32  
  33      /**
  34       * @param string $sCharset
  35       * @param int $iLineNo
  36       */
  37      public function __construct($sCharset, $iLineNo = 0)
  38      {
  39          $this->sCharset = $sCharset;
  40          $this->iLineNo = $iLineNo;
  41          $this->aComments = [];
  42      }
  43  
  44      /**
  45       * @return int
  46       */
  47      public function getLineNo()
  48      {
  49          return $this->iLineNo;
  50      }
  51  
  52      /**
  53       * @param string $sCharset
  54       *
  55       * @return void
  56       */
  57      public function setCharset($sCharset)
  58      {
  59          $this->sCharset = $sCharset;
  60      }
  61  
  62      /**
  63       * @return string
  64       */
  65      public function getCharset()
  66      {
  67          return $this->sCharset;
  68      }
  69  
  70      /**
  71       * @return string
  72       */
  73      public function __toString()
  74      {
  75          return $this->render(new OutputFormat());
  76      }
  77  
  78      /**
  79       * @return string
  80       */
  81      public function render(OutputFormat $oOutputFormat)
  82      {
  83          return "@charset {$this->sCharset->render($oOutputFormat)};";
  84      }
  85  
  86      /**
  87       * @return string
  88       */
  89      public function atRuleName()
  90      {
  91          return 'charset';
  92      }
  93  
  94      /**
  95       * @return string
  96       */
  97      public function atRuleArgs()
  98      {
  99          return $this->sCharset;
 100      }
 101  
 102      /**
 103       * @param array<array-key, Comment> $aComments
 104       *
 105       * @return void
 106       */
 107      public function addComments(array $aComments)
 108      {
 109          $this->aComments = array_merge($this->aComments, $aComments);
 110      }
 111  
 112      /**
 113       * @return array<array-key, Comment>
 114       */
 115      public function getComments()
 116      {
 117          return $this->aComments;
 118      }
 119  
 120      /**
 121       * @param array<array-key, Comment> $aComments
 122       *
 123       * @return void
 124       */
 125      public function setComments(array $aComments)
 126      {
 127          $this->aComments = $aComments;
 128      }
 129  }