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]

   1  <?php
   2  
   3  /**
   4   * SCSSPHP
   5   *
   6   * @copyright 2012-2020 Leaf Corcoran
   7   *
   8   * @license http://opensource.org/licenses/MIT MIT
   9   *
  10   * @link http://scssphp.github.io/scssphp
  11   */
  12  
  13  namespace ScssPhp\ScssPhp\SourceMap;
  14  
  15  /**
  16   * Base 64 Encode/Decode
  17   *
  18   * @author Anthon Pang <anthon.pang@gmail.com>
  19   *
  20   * @internal
  21   */
  22  class Base64
  23  {
  24      /**
  25       * @var array<int, string>
  26       */
  27      private static $encodingMap = [
  28          0 => 'A',
  29          1 => 'B',
  30          2 => 'C',
  31          3 => 'D',
  32          4 => 'E',
  33          5 => 'F',
  34          6 => 'G',
  35          7 => 'H',
  36          8 => 'I',
  37          9 => 'J',
  38          10 => 'K',
  39          11 => 'L',
  40          12 => 'M',
  41          13 => 'N',
  42          14 => 'O',
  43          15 => 'P',
  44          16 => 'Q',
  45          17 => 'R',
  46          18 => 'S',
  47          19 => 'T',
  48          20 => 'U',
  49          21 => 'V',
  50          22 => 'W',
  51          23 => 'X',
  52          24 => 'Y',
  53          25 => 'Z',
  54          26 => 'a',
  55          27 => 'b',
  56          28 => 'c',
  57          29 => 'd',
  58          30 => 'e',
  59          31 => 'f',
  60          32 => 'g',
  61          33 => 'h',
  62          34 => 'i',
  63          35 => 'j',
  64          36 => 'k',
  65          37 => 'l',
  66          38 => 'm',
  67          39 => 'n',
  68          40 => 'o',
  69          41 => 'p',
  70          42 => 'q',
  71          43 => 'r',
  72          44 => 's',
  73          45 => 't',
  74          46 => 'u',
  75          47 => 'v',
  76          48 => 'w',
  77          49 => 'x',
  78          50 => 'y',
  79          51 => 'z',
  80          52 => '0',
  81          53 => '1',
  82          54 => '2',
  83          55 => '3',
  84          56 => '4',
  85          57 => '5',
  86          58 => '6',
  87          59 => '7',
  88          60 => '8',
  89          61 => '9',
  90          62 => '+',
  91          63 => '/',
  92      ];
  93  
  94      /**
  95       * @var array<string|int, int>
  96       */
  97      private static $decodingMap = [
  98          'A' => 0,
  99          'B' => 1,
 100          'C' => 2,
 101          'D' => 3,
 102          'E' => 4,
 103          'F' => 5,
 104          'G' => 6,
 105          'H' => 7,
 106          'I' => 8,
 107          'J' => 9,
 108          'K' => 10,
 109          'L' => 11,
 110          'M' => 12,
 111          'N' => 13,
 112          'O' => 14,
 113          'P' => 15,
 114          'Q' => 16,
 115          'R' => 17,
 116          'S' => 18,
 117          'T' => 19,
 118          'U' => 20,
 119          'V' => 21,
 120          'W' => 22,
 121          'X' => 23,
 122          'Y' => 24,
 123          'Z' => 25,
 124          'a' => 26,
 125          'b' => 27,
 126          'c' => 28,
 127          'd' => 29,
 128          'e' => 30,
 129          'f' => 31,
 130          'g' => 32,
 131          'h' => 33,
 132          'i' => 34,
 133          'j' => 35,
 134          'k' => 36,
 135          'l' => 37,
 136          'm' => 38,
 137          'n' => 39,
 138          'o' => 40,
 139          'p' => 41,
 140          'q' => 42,
 141          'r' => 43,
 142          's' => 44,
 143          't' => 45,
 144          'u' => 46,
 145          'v' => 47,
 146          'w' => 48,
 147          'x' => 49,
 148          'y' => 50,
 149          'z' => 51,
 150          0 => 52,
 151          1 => 53,
 152          2 => 54,
 153          3 => 55,
 154          4 => 56,
 155          5 => 57,
 156          6 => 58,
 157          7 => 59,
 158          8 => 60,
 159          9 => 61,
 160          '+' => 62,
 161          '/' => 63,
 162      ];
 163  
 164      /**
 165       * Convert to base64
 166       *
 167       * @param int $value
 168       *
 169       * @return string
 170       */
 171      public static function encode($value)
 172      {
 173          return self::$encodingMap[$value];
 174      }
 175  
 176      /**
 177       * Convert from base64
 178       *
 179       * @param string $value
 180       *
 181       * @return int
 182       */
 183      public static function decode($value)
 184      {
 185          return self::$decodingMap[$value];
 186      }
 187  }