get(self::SERVICE_ID); } /** * @var array */ private $mediaSources; /** * Return all configured media sources * * @return MediaBrowser[] */ protected function getMediaSources(): array { if (is_null($this->mediaSources)) { $this->mediaSources = []; foreach ($this->getOption(self::OPTION_SOURCE) as $mediaSourceId => $mediaSource) { $this->mediaSources[$mediaSourceId] = $this->propagate($mediaSource); } } return $this->mediaSources; } /** * Returns the media source specified by $mediaSourceId * * @throws common_Exception */ public function getMediaSource(string $mediaSourceId): MediaBrowser { $sources = $this->getMediaSources(); if (!isset($sources[$mediaSourceId])) { throw new common_Exception('Media Sources Configuration for source ' . $mediaSourceId . ' not found'); } return $sources[$mediaSourceId]; } /** * Returns all media sources that are browsable * * @return MediaBrowser[] */ public function getBrowsableSources(): array { $returnValue = []; foreach ($this->getMediaSources() as $id => $source) { if ($source instanceof MediaBrowser) { $returnValue[$id] = $source; } } return $returnValue; } /** * Returns all media sources that can write * * @return MediaManagement[] */ public function getWritableSources(): array { $returnValue = []; foreach ($this->getMediaSources() as $id => $source) { if ($source instanceof MediaManagement) { $returnValue[$id] = $source; } } return $returnValue; } /** * Adds a media source to Tao * * WARNING: Will always add the mediasource as 'mediamanager' as other * identifiers are not supported by js widget */ public function addMediaSource(MediaBrowser $source): bool { // ensure loaded $mediaSources = $this->getMediaSources(); // only mediaSource called 'mediamanager' supported $mediaSources['mediamanager'] = $source; return $this->registerMediaSources($mediaSources); } /** * Removes a media source for tao */ public function removeMediaSource(string $sourceId): bool { // ensure loaded $mediaSources = $this->getMediaSources(); unset($mediaSources[$sourceId]); return $this->registerMediaSources($mediaSources); } /** * @throws InvalidServiceManagerException * @throws common_Exception */ public function registerMediaSources($sources): bool { $this->setOption(self::OPTION_SOURCE, $sources); $this->getServiceManager()->register(self::SERVICE_ID, $this); return true; } }