3 namespace mdref\Generator
;
5 use http\Exception\RuntimeException
;
8 public function __construct(
13 public function source() {
14 return file_get_contents($this->file
, false, null, $this->offset
);
17 private function cache(string $cache_file) : string {
18 $cache_path = dirname($cache_file);
19 if (!is_dir($cache_path) && !mkdir($cache_path, 0700, true)) {
20 throw new RuntimeException(error_get_last()["message"]);
22 if (!file_put_contents($cache_file, '<?php namespace mdref\\Generator; ?>' . $this->source())) {
23 throw new RuntimeException(error_get_last()["message"]);
28 public function __toString() : string {
29 $cache_file = sys_get_temp_dir() . "/mdref/generate." . basename($this->file
) . ".md.tmp";
30 $cache_stat = @stat
($cache_file);
31 if ($cache_stat && $cache_stat["mtime"] >= filemtime($this->file
)) {
35 return $this->cache($cache_file);