From b82a2de2313f339894d8fad3c1cc59e211cce464 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 3 Feb 2024 11:05:47 +0200 Subject: [PATCH] add getData method --- README.md | 12 ++++++++++++ src/Dokuwiki/Filesystem.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 39a4a2a..4d5bea5 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,18 @@ var_dump ( ); ``` +#### Filesystem::getData + +Return file content if path match storage item + +``` +var_dump ( + $filesystem->getData( + '/full/path/to/page.txt' + ) +); +``` + ### Helper Useful methods to minify controller codebase diff --git a/src/Dokuwiki/Filesystem.php b/src/Dokuwiki/Filesystem.php index 03aa337..8f91d04 100644 --- a/src/Dokuwiki/Filesystem.php +++ b/src/Dokuwiki/Filesystem.php @@ -163,6 +163,18 @@ class Filesystem return $path; } + public function getData(string $path): ?string + { + if (isset($this->_list[$path]) && is_file($path) || is_readable($path)) + { + return file_get_contents( + $path + ); + } + + return null; + } + private function _index(string $path, ?array $blacklist = ['.', '..', 'sidebar.txt', '__template.txt']): void { foreach ((array) scandir($path) as $file)