6 * A path made out of a base dir and an thereof relative path name.
17 * The base directory where path is located
20 protected $baseDir = "";
23 * @param string $baseDir
26 function __construct($baseDir = "", $path = "") {
27 $this->baseDir
= $baseDir;
32 * Create a copy of this path with a different path name
37 function __invoke($path) {
44 * Retrurns the full path as string
47 function __toString() {
48 return $this->getFullPath();
55 function getBaseDir() {
56 return $this->baseDir
;
60 * The path name relative to the base dir
63 function getPathName() {
69 * @param string $ext extension
72 function getFullPath($ext = "") {
74 if (strlen($this->baseDir
)) {
75 $path .= $this->baseDir
. DIRECTORY_SEPARATOR
;
77 if (strlen($this->path
)) {
85 * Retrieve a another subpath within the base dir
89 function getSubPath($path) {
90 return trim(substr($path, strlen($this->baseDir
)), DIRECTORY_SEPARATOR
);
93 function isFile($ext = ".md") {
94 return is_file($this->getFullPath($ext));
98 $head = sprintf("<h1>%s</h1>\n", htmlspecialchars(basename($this->getPathName())));
99 if ($this->isFile()) {
100 $html = htmlspecialchars(file_get_contents($this->getFullPath()));
101 } elseif ($this->isFile("")) {
102 $html = htmlspecialchars(file_get_contents($this->getFullPath("")));
104 throw new \http\Controller\
Exception(404, "Not Found: {$this->getPathName()}");
106 return $head . "<pre>" . $html ."</pre>";