Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

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