1<?php 2 3 4namespace ComboStrap\Meta\Field; 5 6 7 8use ComboStrap\LogUtility; 9use ComboStrap\MarkupPath; 10use ComboStrap\ResourceCombo; 11use ComboStrap\WikiPath; 12 13class Alias 14{ 15 16 const CANONICAL = "alias"; 17 18 19 private WikiPath $path; // the path of the alias 20 private MarkupPath $page; 21 /** 22 * @var string 23 */ 24 private string $type = AliasType::REDIRECT; 25 26 /** 27 * Alias constructor. 28 * @param MarkupPath $page 29 * @param WikiPath $path 30 */ 31 public function __construct(MarkupPath $page, WikiPath $path) 32 { 33 $this->page = $page; 34 35 $this->path = $path; 36 } 37 38 /** 39 * @return WikiPath 40 */ 41 public function getPath(): WikiPath 42 { 43 return $this->path; 44 } 45 46 47 48 /** 49 * @return MarkupPath 50 */ 51 public 52 function getPage(): MarkupPath 53 { 54 return $this->page; 55 } 56 57 /** 58 * @return string 59 */ 60 public 61 function getType(): string 62 { 63 return $this->type; 64 } 65 66 67 public 68 static function create(ResourceCombo $page, WikiPath $alias): Alias 69 { 70 return new Alias($page, $alias); 71 } 72 73 public 74 function setType(string $type): Alias 75 { 76 if (!in_array($type, AliasType::ALIAS_TYPE_VALUES)) { 77 $pageAnchor = $this->getPage()->getHtmlAnchorLink(); 78 LogUtility::msg("Bad Alias Type. The alias type value ($type) for the alias path ({$this->getPath()}) of the page ({$pageAnchor})"); 79 return $this; 80 } 81 $this->type = $type; 82 return $this; 83 } 84 85 public 86 function __toString() 87 { 88 return "Alias: ($this->page) to ($this->path)"; 89 } 90 91 92} 93