1<?php 2 3 4namespace ComboStrap; 5 6/** 7 * Class Media 8 * @package ComboStrap 9 * 10 * * It represents a generated file: 11 * * if the image width is 20 -> the image is generated 12 * * same for svg ... 13 * 14 * This is why there is a cache attribute - this is the cache of the generated file 15 * if any 16 */ 17abstract class Media extends ResourceComboAbs 18{ 19 const RESOURCE_TYPE = "media"; 20 21 /** 22 * @var TagAttributes 23 */ 24 protected $attributes; 25 26 /** 27 * @var Path 28 */ 29 private $path; 30 31 /** 32 * Media constructor. 33 * The file system path and the attributes (properties) 34 */ 35 public function __construct(Path $path, $attributes = null) 36 { 37 if ($attributes === null) { 38 $attributes = TagAttributes::createEmpty(); 39 } 40 $this->attributes = $attributes; 41 42 $this->path = $path; 43 44 } 45 46 47 /** 48 * @return string $cache - one of {@link CacheMedia::CACHE_KEY} or null if not set 49 */ 50 public function getCache(): ?string 51 { 52 return $this->attributes->getValue(CacheMedia::CACHE_KEY); 53 54 } 55 56 public function getTitle() 57 { 58 return $this->attributes->getValue(TagAttributes::TITLE_KEY); 59 } 60 61 public function &getAttributes() 62 { 63 return $this->attributes; 64 } 65 66 67 public function getPath(): Path 68 { 69 return $this->path; 70 } 71 72 public function getName(): ?string 73 { 74 return ResourceName::createForResource($this) 75 ->getValue(); 76 } 77 78 public function getNameOrDefault(): string 79 { 80 return ResourceName::createForResource($this) 81 ->getValueOrDefault(); 82 } 83 84 /** 85 * The URL will change if the file change 86 * @param $queryParameters 87 */ 88 protected function addCacheBusterToQueryParameters(&$queryParameters) 89 { 90 $queryParameters[CacheMedia::CACHE_BUSTER_KEY] = $this->getBuster(); 91 } 92 93 /** 94 * @return mixed 95 */ 96 public abstract function getUrl(); 97 98 99 public function getReadStoreOrDefault(): MetadataStore 100 { 101 throw new ExceptionComboRuntime("To implement"); 102 } 103 104 function getType(): string 105 { 106 return self::RESOURCE_TYPE; 107 } 108 109 110 public function getUid(): Metadata 111 { 112 throw new ExceptionComboRuntime("To implement"); 113 } 114 115 public function __toString() 116 { 117 return $this->getPath()->toString(); 118 } 119 120 121} 122