* */ namespace ComboStrap; use ComboStrap\Web\Url; /** * Class InternalMedia * Represent a HTML markup link * * * @package ComboStrap * * * * This is a link to a media (pdf, image, ...). * (ie img, svg, a) */ abstract class MediaLink { const CANONICAL = "image"; /** * @deprecated 2021-06-12 */ const LINK_PATTERN = "{{\s*([^|\s]*)\s*\|?.*}}"; protected MediaMarkup $mediaMarkup; public function __construct(MediaMarkup $mediaMarkup) { $this->mediaMarkup = $mediaMarkup; } /** * @param MediaMarkup $mediaMarkup * @return RasterImageLink|SvgImageLink|ThirdMediaLink|MediaLink * @throws ExceptionBadArgument * @throws ExceptionBadSyntax * @throws ExceptionNotExists * @throws ExceptionNotFound */ public static function createFromMediaMarkup(MediaMarkup $mediaMarkup) { /** * Processing */ $mime = $mediaMarkup->getFetcher()->getMime(); switch ($mime->toString()) { case Mime::SVG: return new SvgImageLink($mediaMarkup); default: if (!$mime->isImage()) { return new ThirdMediaLink($mediaMarkup); } else { return new RasterImageLink($mediaMarkup); } } } /** * @return string - the HTML of the image */ public abstract function renderMediaTag(): string; public function getFetchUrl(): Url { return $this->mediaMarkup->getFetchUrl(); } }