/** * @param MediaInterface $media */ public function flushCdn(MediaInterface $media) { if ($media->getId() && $this->requireThumbnails() && !$media->getCdnIsFlushable()) { $flushPaths = array(); foreach ($this->getFormats() as $format => $settings) { if ('admin' === $format || substr($format, 0, strlen($media->getContext())) === $media->getContext()) { $flushPaths[] = $this->getFilesystem()->get($this->generatePrivateUrl($media, $format), true)->getKey(); } } if (!empty($flushPaths)) { $cdnFlushIdentifier = $this->getCdn()->flushPaths($flushPaths); $media->setCdnFlushIdentifier($cdnFlushIdentifier); $media->setCdnIsFlushable(true); $media->setCdnStatus(CDNInterface::STATUS_TO_FLUSH); } } }
/** * @param \Sonata\MediaBundle\Model\MediaInterface $media * @param string $format * @return string */ public function generatePublicUrl(MediaInterface $media, $format) { // todo: add a valid icon set return $this->getCdn()->getPath(sprintf('media_bundle/images/files/%s/file.png', $format), $media->getCdnIsFlushable()); }
/** * @param MediaInterface $media * * @return string * @internal param $format */ public function generateProtectedUrl(MediaInterface $media) { return $this->getCdn()->getPath($media->getId(), $media->getCdnIsFlushable()); }