*/ namespace oat\taoItems\model\pack\encoders; use oat\tao\model\media\MediaAsset; use oat\taoItems\model\pack\ExceptionMissingAsset; /** * Class Base64Encoder * Helper, encode file for embedding using base64 algorithm * @package oat\taoItems\model\pack\encoders */ class Base64Encoder implements Encoding { public function __construct() { } /** * @param string|MediaAsset $data content to encode * * @return string * @throws ExceptionMissingAsset */ public function encode($data) { if ($data instanceof MediaAsset) { $mediaSource = $data->getMediaSource(); $data = $mediaSource->getBaseName($data->getMediaIdentifier()); } if (is_string($data)) { return base64_encode($data); } throw new ExceptionMissingAsset('Incorrect asset type - cann\'t be encoded ' . $data); } }