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  use Sabberworm\CSS\Parsing\ParserState;
   7  use Sabberworm\CSS\Parsing\SourceException;
   8  use Sabberworm\CSS\Parsing\UnexpectedEOFException;
   9  use Sabberworm\CSS\Parsing\UnexpectedTokenException;
  10  
  11  class URL extends PrimitiveValue
  12  {
  13      /**
  14       * @var CSSString
  15       */
  16      private $oURL;
  17  
  18      /**
  19       * @param int $iLineNo
  20       */
  21      public function __construct(CSSString $oURL, $iLineNo = 0)
  22      {
  23          parent::__construct($iLineNo);
  24          $this->oURL = $oURL;
  25      }
  26  
  27      /**
  28       * @return URL
  29       *
  30       * @throws SourceException
  31       * @throws UnexpectedEOFException
  32       * @throws UnexpectedTokenException
  33       */
  34      public static function parse(ParserState $oParserState)
  35      {
  36          $bUseUrl = $oParserState->comes('url', true);
  37          if ($bUseUrl) {
  38              $oParserState->consume('url');
  39              $oParserState->consumeWhiteSpace();
  40              $oParserState->consume('(');
  41          }
  42          $oParserState->consumeWhiteSpace();
  43          $oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine());
  44          if ($bUseUrl) {
  45              $oParserState->consumeWhiteSpace();
  46              $oParserState->consume(')');
  47          }
  48          return $oResult;
  49      }
  50  
  51      /**
  52       * @return void
  53       */
  54      public function setURL(CSSString $oURL)
  55      {
  56          $this->oURL = $oURL;
  57      }
  58  
  59      /**
  60       * @return CSSString
  61       */
  62      public function getURL()
  63      {
  64          return $this->oURL;
  65      }
  66  
  67      /**
  68       * @return string
  69       */
  70      public function __toString()
  71      {
  72          return $this->render(new OutputFormat());
  73      }
  74  
  75      /**
  76       * @return string
  77       */
  78      public function render(OutputFormat $oOutputFormat)
  79      {
  80          return "url({$this->oURL->render($oOutputFormat)})";
  81      }
  82  }