1<?php 2 3namespace ComboStrap; 4 5use ComboStrap\Web\Url; 6 7/** 8 * Return raw files. 9 * The mime is determined by the path. 10 */ 11class FetcherRawLocalPath extends IFetcherAbs implements IFetcherPath, IFetcherSource 12{ 13 14 use FetcherTraitWikiPath; 15 16 public const SRC_QUERY_PARAMETER = "src"; 17 const NAME = "raw"; 18 19 20 public static function createFromPath(WikiPath $wikiPath): FetcherRawLocalPath 21 { 22 $fetcherRaw = self::createEmpty(); 23 $fetcherRaw->setSourcePath($wikiPath); 24 return $fetcherRaw; 25 } 26 27 /** 28 * Empty because a fetch is mostly build through an URL 29 * @return FetcherRawLocalPath 30 */ 31 public static function createEmpty(): FetcherRawLocalPath 32 { 33 return new FetcherRawLocalPath(); 34 } 35 36 /** 37 * @throws ExceptionBadArgument 38 */ 39 public static function createLocalFromFetchUrl(Url $fetchUrl): FetcherRawLocalPath 40 { 41 $fetchRaw = FetcherRawLocalPath::createEmpty(); 42 $fetchRaw->buildFromUrl($fetchUrl); 43 return $fetchRaw; 44 } 45 46 47 /** 48 * @return Url - an URL to download the media 49 */ 50 function getFetchUrl(Url $url = null): Url 51 { 52 53 $url = parent::getFetchUrl($url); 54 $this->addLocalPathParametersToFetchUrl($url, MediaMarkup::$MEDIA_QUERY_PARAMETER); 55 return $url; 56 57 } 58 59 /** 60 * @param TagAttributes $tagAttributes 61 * @return FetcherRawLocalPath 62 * @throws ExceptionBadArgument - if the media/id was not found 63 * @throws ExceptionBadSyntax 64 * @throws ExceptionNotExists 65 * @throws ExceptionNotFound 66 */ 67 public function buildFromTagAttributes(TagAttributes $tagAttributes): FetcherRawLocalPath 68 { 69 70 $this->buildOriginalPathFromTagAttributes($tagAttributes); 71 parent::buildFromTagAttributes($tagAttributes); 72 return $this; 73 74 } 75 76 function getFetchPath(): LocalPath 77 { 78 return $this->getSourcePath()->toLocalPath(); 79 } 80 81 82 /** 83 * Buster for the {@link IFetcher} interface 84 * @throws ExceptionNotFound 85 */ 86 function getBuster(): string 87 { 88 return FileSystems::getCacheBuster($this->getSourcePath()); 89 } 90 91 92 public 93 function getFetcherName(): string 94 { 95 return self::NAME; 96 } 97 98 public function getLabel(): string 99 { 100 $sourcePath = $this->getSourcePath(); 101 return ResourceName::getFromPath($sourcePath); 102 } 103} 104