1 | <?php |
||
14 | abstract class ReadableDocument |
||
15 | { |
||
16 | /** |
||
17 | * Do not read the file immediately at construction. The object will need to execute the self::refreshFileContent() |
||
18 | * manually at some point. |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $noReadOnConstructor = false; |
||
23 | |||
24 | /** @var string The content of the document's body. */ |
||
25 | protected $bodyContent = ''; |
||
26 | |||
27 | protected $metadata; |
||
28 | protected $file; |
||
29 | |||
30 | /** |
||
31 | * ReadableDocument Constructor. |
||
32 | * |
||
33 | * @throws FileNotFoundException When the file given in the constructor does not exist or may not be accessible. |
||
34 | */ |
||
35 | 127 | public function __construct(File $file) |
|
52 | |||
53 | /** |
||
54 | * Get the contents of this document. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 4 | public function getContent() |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 41 | public function getIndexName() |
|
70 | |||
71 | /** |
||
72 | * Get the relative path to the file, with respect to the site root. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 88 | final public function getRelativeFilePath() |
|
80 | |||
81 | /** |
||
82 | * Get the extension of the file. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 14 | final public function getExtension() |
|
90 | |||
91 | /** |
||
92 | * Get the name of the file without the extension. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 4 | final public function getBasename() |
|
100 | |||
101 | /** |
||
102 | * Get the absolute path to the file. |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 16 | final public function getAbsoluteFilePath() |
|
110 | |||
111 | /** |
||
112 | * Get the name of the file with its extension. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | final public function getFilename() |
||
120 | |||
121 | /** |
||
122 | * Read the contents of the file and handle any parsing that needs to be done. |
||
123 | * |
||
124 | * For example, if a file needs to parse and evaluate FrontMatter, that will need to be in this function call after |
||
125 | * reading the file contents. |
||
126 | * |
||
127 | * @throws \RuntimeException When the file cannot be read. |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | abstract public function readContent(); |
||
132 | } |
||
133 |