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