1<?php 2 3 4namespace ComboStrap; 5 6/** 7 * A Document that is generated by the page compiler 8 * @package ComboStrap 9 * Represent a compiled document. 10 */ 11abstract class PageCompilerDocument implements CachedDocument 12{ 13 14 /** 15 * @var Page 16 */ 17 protected $page; 18 19 /** 20 * @var string|null 21 */ 22 protected $content; 23 24 /** 25 * Document constructor. 26 * @param Page $page 27 */ 28 public function __construct(Page $page) 29 { 30 $this->page = $page; 31 } 32 33 34 /** 35 * @return Page 36 */ 37 function getPage(): Page 38 { 39 return $this->page; 40 } 41 42 /** 43 * @return string - the last part name of the renderer file without the php extension 44 * known inside dokuwiki as the mode 45 * 46 * For instance for the renderer 47 * renderer_plugin_combo_analytics 48 * the name is 49 * combo_analytics 50 */ 51 abstract function getRendererName(): string; 52 53 /** 54 * Get the data from the cache file 55 * or compile the content 56 * 57 * @return mixed - array ({@link InstructionsDocument)) or string 58 */ 59 public function getOrProcessContent() 60 { 61 62 if ($this->shouldProcess()) { 63 64 /** 65 * Cache Miss 66 */ 67 $this->process(); 68 69 } 70 71 return $this->getContent(); 72 73 74 } 75 76 /** 77 * @return array|string|null 78 */ 79 public function getContent() 80 { 81 82 if ($this->content !== null) { 83 return $this->content; 84 } else { 85 return $this->getFileContent(); 86 } 87 88 } 89 90 91 /** 92 * 93 * @return null|mixed the content of the file (by default in a text format) 94 */ 95 public function getFileContent() 96 { 97 if (!FileSystems::exists($this->getCachePath())) { 98 return null; 99 } 100 return FileSystems::getContent($this->getCachePath()); 101 } 102 103 104 105 /** 106 * @param $content 107 * @return mixed 108 */ 109 protected function setContent($content) 110 { 111 $this->content = $content; 112 $this->storeContent($content); 113 return $this; 114 } 115 116 117} 118