Exemplo n.º 1
0
 /**
  * Resolve a taomedia url to a media asset
  * 
  * @param string $url
  * @throws \Exception
  * @return \oat\tao\model\media\MediaAsset
  */
 public function resolve($url)
 {
     $urlParts = parse_url($url);
     if (isset($urlParts['scheme']) && $urlParts['scheme'] === MediaService::SCHEME_NAME && isset($urlParts['host'])) {
         $mediaService = new MediaService();
         $mediaSource = $mediaService->getMediaSource($urlParts['host']);
         $mediaId = isset($urlParts['path']) ? trim($urlParts['path'], '/') : '';
         return new MediaAsset($mediaSource, $mediaId);
     } elseif (isset($urlParts['scheme']) && in_array($urlParts['scheme'], array('http', 'https'))) {
         return new MediaAsset(new HttpSource(), $url);
     } else {
         throw new TaoMediaException('Cannot resolve ' . $url);
     }
 }