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\Value;
   4  
   5  use Sabberworm\CSS\OutputFormat;
   6  
   7  abstract class ValueList extends Value
   8  {
   9      /**
  10       * @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
  11       */
  12      protected $aComponents;
  13  
  14      /**
  15       * @var string
  16       */
  17      protected $sSeparator;
  18  
  19      /**
  20       * phpcs:ignore Generic.Files.LineLength
  21       * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents
  22       * @param string $sSeparator
  23       * @param int $iLineNo
  24       */
  25      public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0)
  26      {
  27          parent::__construct($iLineNo);
  28          if (!is_array($aComponents)) {
  29              $aComponents = [$aComponents];
  30          }
  31          $this->aComponents = $aComponents;
  32          $this->sSeparator = $sSeparator;
  33      }
  34  
  35      /**
  36       * @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent
  37       *
  38       * @return void
  39       */
  40      public function addListComponent($mComponent)
  41      {
  42          $this->aComponents[] = $mComponent;
  43      }
  44  
  45      /**
  46       * @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
  47       */
  48      public function getListComponents()
  49      {
  50          return $this->aComponents;
  51      }
  52  
  53      /**
  54       * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents
  55       *
  56       * @return void
  57       */
  58      public function setListComponents(array $aComponents)
  59      {
  60          $this->aComponents = $aComponents;
  61      }
  62  
  63      /**
  64       * @return string
  65       */
  66      public function getListSeparator()
  67      {
  68          return $this->sSeparator;
  69      }
  70  
  71      /**
  72       * @param string $sSeparator
  73       *
  74       * @return void
  75       */
  76      public function setListSeparator($sSeparator)
  77      {
  78          $this->sSeparator = $sSeparator;
  79      }
  80  
  81      /**
  82       * @return string
  83       */
  84      public function __toString()
  85      {
  86          return $this->render(new OutputFormat());
  87      }
  88  
  89      /**
  90       * @return string
  91       */
  92      public function render(OutputFormat $oOutputFormat)
  93      {
  94          return $oOutputFormat->implode(
  95              $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator
  96              . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator),
  97              $this->aComponents
  98          );
  99      }
 100  }