/** * Serialize data and duration * * @param mixed $data * @param mixed $duration can be a number of seconds or any argument accepted by strtotime() */ protected static function serialize($data, $duration = 0) { switch (true) { case !$duration: $duration = strtotime('+1 week'); break; case !is_numeric($duration): $duration = strtotime($duration); break; case is_numeric($duration): $duration = intval($duration); break; default: throw new JigException('Invalid duration ' . $duration . ', caching not possible'); } $base64 = false; if (is_string($data) && StringUtils::isBinary($data)) { $data = base64_encode($data); $base64 = true; } $data = array('expires' => $duration, 'content' => $data, 'base64' => $base64); return json_encode($data); }
/** * Encode content to base64 if binary * * @param mixed $content * @return mixed|string */ protected static function encodeContent($content) { return static::$checkForBinary && is_string($content) && StringUtils::isBinary($content) ? base64_encode($content) : $content; }