Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| TaoMediaResolver | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| resolve | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
90 | |||
| getServiceLocator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\media; |
| 23 | |
| 24 | use oat\tao\model\media\sourceStrategy\HttpSource; |
| 25 | use oat\tao\model\media\sourceStrategy\InlineSource; |
| 26 | use oat\oatbox\service\ServiceManager; |
| 27 | |
| 28 | /** |
| 29 | * Base Media Resolver, that transforms an URL into a |
| 30 | * Media Asset |
| 31 | */ |
| 32 | class TaoMediaResolver |
| 33 | { |
| 34 | /** |
| 35 | * Resolve a taomedia url to a media asset |
| 36 | * |
| 37 | * @param string $url |
| 38 | * @throws \Exception |
| 39 | * @return \oat\tao\model\media\MediaAsset |
| 40 | */ |
| 41 | public function resolve($url) |
| 42 | { |
| 43 | $urlParts = parse_url($url); |
| 44 | if ( |
| 45 | isset($urlParts['scheme']) |
| 46 | && $urlParts['scheme'] === MediaService::SCHEME_NAME |
| 47 | && isset($urlParts['host']) |
| 48 | ) { |
| 49 | $mediaService = $this->getServiceLocator()->get(MediaService::SERVICE_ID); |
| 50 | $mediaSource = $mediaService->getMediaSource($urlParts['host']); |
| 51 | $mediaId = (isset($urlParts['path'])) ? trim($urlParts['path'], '/') : ''; |
| 52 | return new MediaAsset($mediaSource, $mediaId); |
| 53 | } elseif (isset($urlParts['scheme']) && $urlParts['scheme'] === 'data') { |
| 54 | return new MediaAsset(new InlineSource(), $url); |
| 55 | } elseif (isset($urlParts['scheme']) && in_array($urlParts['scheme'], ['http','https'])) { |
| 56 | return new MediaAsset(new HttpSource(), $url); |
| 57 | } else { |
| 58 | throw new TaoMediaException('Cannot resolve ' . $url); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @deprecated |
| 64 | * @return \oat\oatbox\service\ServiceManager |
| 65 | */ |
| 66 | public function getServiceLocator() |
| 67 | { |
| 68 | return ServiceManager::getServiceManager(); |
| 69 | } |
| 70 | } |