Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Base64Encoder | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
4.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| encode | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
3.04 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * @author Mikhail Kamarouski, <kamarouski@1pt.com> |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoItems\model\pack\encoders; |
| 23 | |
| 24 | use oat\tao\model\media\MediaAsset; |
| 25 | use oat\taoItems\model\pack\ExceptionMissingAsset; |
| 26 | |
| 27 | /** |
| 28 | * Class Base64Encoder |
| 29 | * Helper, encode file for embedding using base64 algorithm |
| 30 | * @package oat\taoItems\model\pack\encoders |
| 31 | */ |
| 32 | class Base64Encoder implements Encoding |
| 33 | { |
| 34 | public function __construct() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param string|MediaAsset $data content to encode |
| 40 | * |
| 41 | * @return string |
| 42 | * @throws ExceptionMissingAsset |
| 43 | */ |
| 44 | public function encode($data) |
| 45 | { |
| 46 | if ($data instanceof MediaAsset) { |
| 47 | $mediaSource = $data->getMediaSource(); |
| 48 | $data = $mediaSource->getBaseName($data->getMediaIdentifier()); |
| 49 | } |
| 50 | |
| 51 | if (is_string($data)) { |
| 52 | return base64_encode($data); |
| 53 | } |
| 54 | throw new ExceptionMissingAsset('Incorrect asset type - cann\'t be encoded ' . $data); |
| 55 | } |
| 56 | } |