From 39b57f47790815a100c31625c44f696214565fa3 Mon Sep 17 00:00:00 2001 From: Patrick Barroca <pbarroca@afi-sa.fr> Date: Wed, 2 Nov 2022 16:39:36 +0000 Subject: [PATCH] add filesystem fopen --- src/Storm/FileSystem/Abstract.php | 3 +++ src/Storm/FileSystem/Disk.php | 8 ++++++++ src/Storm/FileSystem/Volatile.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/Storm/FileSystem/Abstract.php b/src/Storm/FileSystem/Abstract.php index 0f6c0f9d..9a505698 100644 --- a/src/Storm/FileSystem/Abstract.php +++ b/src/Storm/FileSystem/Abstract.php @@ -55,4 +55,7 @@ abstract class Storm_FileSystem_Abstract { abstract public function readfile(string $path); abstract public function mkdir($path); + + abstract public function fopen(string $filename, string $mode, bool $use_include_path=false, $context=null); + } diff --git a/src/Storm/FileSystem/Disk.php b/src/Storm/FileSystem/Disk.php index df973afd..c9248e3a 100644 --- a/src/Storm/FileSystem/Disk.php +++ b/src/Storm/FileSystem/Disk.php @@ -92,6 +92,14 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract { } + public function fopen(string $filename, + string $mode, + bool $use_include_path=false, + $context=null) { + return fopen($filename, $mode, $use_include_path, $context); + } + + public function directoryNamesAt($path) { if (!file_exists($path) || !is_readable($path) ) return []; diff --git a/src/Storm/FileSystem/Volatile.php b/src/Storm/FileSystem/Volatile.php index 1ee0f509..c2efb0e8 100644 --- a/src/Storm/FileSystem/Volatile.php +++ b/src/Storm/FileSystem/Volatile.php @@ -147,6 +147,20 @@ class Storm_FileSystem_Volatile extends Storm_FileSystem_Abstract { } + public function fopen(string $filename, + string $mode, + bool $use_include_path=false, + $context=null) { + if (null === ($file_content = $this->fileGetContents($filename))) + return false; + + $content = fopen('php://memory', 'r+'); + fwrite($content, $file_content); + rewind($content); + return $content; + } + + public function asPath($path) { return (new Storm_FileSystem_Volatile_Path($path, $this->_current_directory)); } -- GitLab