| @@ 122-140 (lines=19) @@ | ||
| 119 | * @param int $transform |
|
| 120 | * @return string |
|
| 121 | */ |
|
| 122 | public static function transformData($data, $transform = Cache::TEXT) |
|
| 123 | { |
|
| 124 | Logger::log('Transform data in cache', LOG_DEBUG); |
|
| 125 | switch ($transform) { |
|
| 126 | case self::JSON: |
|
| 127 | $data = json_encode($data, JSON_PRETTY_PRINT); |
|
| 128 | break; |
|
| 129 | case self::JSONGZ: |
|
| 130 | $data = self::transformData($data, self::JSON); |
|
| 131 | $data = self::transformData($data, self::GZIP); |
|
| 132 | break; |
|
| 133 | case self::GZIP: |
|
| 134 | if (function_exists('gzcompress')) { |
|
| 135 | $data = gzcompress($data ?: ''); |
|
| 136 | } |
|
| 137 | break; |
|
| 138 | } |
|
| 139 | return $data; |
|
| 140 | } |
|
| 141 | ||
| 142 | /** |
|
| 143 | * @param string $path |
|
| @@ 97-115 (lines=19) @@ | ||
| 94 | * @param int $transform |
|
| 95 | * @return mixed |
|
| 96 | */ |
|
| 97 | public static function extractDataWithFormat($data = null, $transform = Cache::TEXT) |
|
| 98 | { |
|
| 99 | Logger::log('Extracting data from cache'); |
|
| 100 | switch ($transform) { |
|
| 101 | case self::JSON: |
|
| 102 | $data = json_decode($data, true); |
|
| 103 | break; |
|
| 104 | case self::JSONGZ: |
|
| 105 | $data = self::extractDataWithFormat($data, self::GZIP); |
|
| 106 | $data = self::extractDataWithFormat($data, self::JSON); |
|
| 107 | break; |
|
| 108 | case self::GZIP: |
|
| 109 | if (null !== $data && function_exists('gzuncompress')) { |
|
| 110 | $data = @gzuncompress($data ?: ''); |
|
| 111 | } |
|
| 112 | break; |
|
| 113 | } |
|
| 114 | return $data; |
|
| 115 | } |
|
| 116 | ||
| 117 | /** |
|
| 118 | * @param string $data |
|