Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| NoneEncoder | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| encode | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 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-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * @author Mikhail Kamarouski, <kamarouski@1pt.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoItems\model\pack\encoders; |
| 24 | |
| 25 | use oat\tao\helpers\Base64; |
| 26 | use oat\tao\model\media\MediaAsset; |
| 27 | use tao_models_classes_FileNotFoundException; |
| 28 | use oat\tao\model\media\sourceStrategy\HttpSource; |
| 29 | |
| 30 | /** |
| 31 | * Class NoneEncoder |
| 32 | * |
| 33 | * @package oat\taoItems\model\pack\encoders |
| 34 | */ |
| 35 | class NoneEncoder implements Encoding |
| 36 | { |
| 37 | /** |
| 38 | * NoneEncoder constructor. |
| 39 | */ |
| 40 | public function __construct() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * @param mixed $data |
| 47 | * |
| 48 | * @throws tao_models_classes_FileNotFoundException |
| 49 | * |
| 50 | * @return mixed|string |
| 51 | */ |
| 52 | public function encode($data) |
| 53 | { |
| 54 | if ($data instanceof MediaAsset) { |
| 55 | $mediaSource = $data->getMediaSource(); |
| 56 | $mediaIdentifier = $data->getMediaIdentifier(); |
| 57 | |
| 58 | if ($mediaSource instanceof HttpSource || Base64::isEncodedImage($mediaIdentifier)) { |
| 59 | return $mediaIdentifier; |
| 60 | } |
| 61 | |
| 62 | return $mediaSource->getBaseName($mediaIdentifier); |
| 63 | } |
| 64 | |
| 65 | return $data; |
| 66 | } |
| 67 | } |