1<?php 2 3 4namespace ComboStrap\Meta\Field; 5 6 7use ComboStrap\ExceptionCompile; 8use ComboStrap\MarkupPath; 9use ComboStrap\PageImageUsage; 10use ComboStrap\ResourceCombo; 11use ComboStrap\WikiPath; 12 13/** 14 * Represents the image of a page in a {@link PageImages} 15 * @deprecated 16 */ 17class PageImage 18{ 19 20 const PAGE_IMAGE = "page-image"; 21 22 23 /** 24 * A path and not a {@link FetcherImage} 25 * because: 26 * * it's basically a path (no processing information are needed) 27 * * it's easier to manipulate a path 28 * * in syntax component, we pass attribute to the fetcher that it should delete if used (Way to check the attribute usage) 29 * @var WikiPath 30 */ 31 private WikiPath $image; 32 private $usages; 33 /** 34 * @var MarkupPath 35 */ 36 private $page; 37 38 /** 39 * PageImage constructor. 40 */ 41 public function __construct(WikiPath $image, MarkupPath $page) 42 { 43 $this->image = $image; 44 $this->page = $page; 45 } 46 47 /** 48 * @param WikiPath $image 49 * @param MarkupPath $page 50 * @return PageImage 51 */ 52 public static function create(WikiPath $image, ResourceCombo $page): PageImage 53 { 54 return new PageImage($image, $page); 55 } 56 57 /** 58 * @param array $usages 59 * @return $this 60 * @throws ExceptionCompile 61 */ 62 public function setUsages(array $usages): PageImage 63 { 64 foreach ($usages as $usage) { 65 $value = trim($usage); 66 if ($value === "") { 67 continue; 68 } 69 if (!in_array($value, PageImageUsage::getUsageValues())) { 70 throw new ExceptionCompile("The page image usage value ($value) is not valid."); 71 } 72 $this->usages[$value] = $value; 73 } 74 return $this; 75 } 76 77 public function getImagePath(): WikiPath 78 { 79 return $this->image; 80 } 81 82 public function getUsages(): array 83 { 84 if ($this->usages === null) { 85 return $this->getDefaultUsage(); 86 } 87 return array_values($this->usages); 88 } 89 90 public function getDefaultUsage(): array 91 { 92 return [PageImageUsage::DEFAULT]; 93 } 94 95 /** 96 * @return MarkupPath 97 */ 98 public function getPage(): MarkupPath 99 { 100 return $this->page; 101 } 102 103 104} 105