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 case "css": 45 return new Mime(Mime::CSS); 46 default: 47 $mime = mimetype($this->getLastName(), true)[1]; 48 if ($mime === null || $mime === false) { 49 return null; 50 } 51 return new Mime($mime); 52 } 53 } 54 55 public function getLastNameWithoutExtension() 56 { 57 return pathinfo($this->getLastName(), PATHINFO_FILENAME); 58 } 59 60 public function __toString() 61 { 62 return $this->toUriString(); 63 } 64 65 66 public function toUriString(): string 67 { 68 return $this->toString(); 69 } 70 71 /** 72 * @throws ExceptionCombo 73 */ 74 function toDokuPath(): DokuPath 75 { 76 if($this instanceof DokuPath){ 77 return $this; 78 } 79 if($this instanceof LocalPath){ 80 return $this->toDokuPath(); 81 } 82 throw new ExceptionCombo("This is not a doku path or local path"); 83 } 84 85 86} 87