1<?php 2 3 4namespace ComboStrap; 5 6 7use ComboStrap\Meta\Api\Metadata; 8use ComboStrap\Meta\Api\MetadataText; 9use DateTime; 10 11/** 12 13 * @package ComboStrap 14 * Represents the wiki id of a resource 15 */ 16class DokuwikiId extends MetadataText 17{ 18 19 20 public const DOKUWIKI_ID_ATTRIBUTE = "id"; 21 22 public static function createForPage(ResourceCombo $page): DokuwikiId 23 { 24 return (new DokuwikiId()) 25 ->setResource($page); 26 } 27 28 public function getDefaultValue(): ?DateTime 29 { 30 return null; 31 } 32 33 public function getValue(): string 34 { 35 $path = $this->getResource()->getPathObject(); 36 if($path instanceof WikiPath){ 37 return $path->getWikiId(); 38 } 39 if($path instanceof LocalPath){ 40 try { 41 return $path->toWikiPath()->getWikiId(); 42 } catch (ExceptionBadArgument $e) { 43 throw new ExceptionNotFound($e->getMessage()); 44 } 45 } 46 throw new ExceptionNotFound("Unknown path, the dokuwiki id cannot be determined"); 47 48 } 49 50 51 public static function getName(): string 52 { 53 return self::DOKUWIKI_ID_ATTRIBUTE; 54 } 55 56 57 public static function getPersistenceType(): string 58 { 59 return Metadata::DERIVED_METADATA; 60 } 61 62 63 public static function getTab(): ?string 64 { 65 return null; 66 } 67 68 public static function getDescription(): string 69 { 70 return "The id of a resource represents the path of a resource from its root directory"; 71 } 72 73 public static function getLabel(): string 74 { 75 return "Wiki Id"; 76 } 77 78 public static function isMutable(): bool 79 { 80 return false; 81 } 82 83 84} 85