1<?php 2 3 4namespace ComboStrap; 5 6 7use renderer_plugin_combo_analytics; 8 9abstract class PathAbs implements Path 10{ 11 12 13 public function getExtension() 14 { 15 return pathinfo($this->getLastName(), PATHINFO_EXTENSION); 16 } 17 18 /** 19 * 20 * @return Mime based on the {@link PathAbs::getExtension()} 21 */ 22 public function getMime(): ?Mime 23 { 24 $extension = $this->getExtension(); 25 switch ($extension) { 26 case ImageSvg::EXTENSION: 27 /** 28 * Svg is authorized when viewing but is not part 29 * of the {@link File::getKnownMime()} 30 */ 31 return new Mime(Mime::SVG); 32 case JavascriptLibrary::EXTENSION: 33 return new Mime(Mime::JAVASCRIPT); 34 case renderer_plugin_combo_analytics::RENDERER_NAME_MODE: 35 case Json::EXTENSION: 36 return new Mime(Mime::JSON); 37 case "txt": 38 return new Mime(Mime::PLAIN_TEXT); 39 case "xhtml": 40 case "html": 41 return new Mime(Mime::HTML); 42 case "png": 43 return new Mime(Mime::PNG); 44 default: 45 $mime = mimetype($this->getLastName(), true)[1]; 46 if ($mime === null || $mime === false) { 47 return null; 48 } 49 return new Mime($mime); 50 } 51 } 52 53 public function getLastNameWithoutExtension() 54 { 55 return pathinfo($this->getLastName(), PATHINFO_FILENAME); 56 } 57 58 public function __toString() 59 { 60 return $this->toString(); 61 } 62 63 64} 65