Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

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