From 946f0348a275f76dc24e78b9e42d97a4d971a107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 7 Aug 2017 19:54:11 +0200 Subject: [PATCH] [ticket/15276] Add methods to get file info PHPBB3-15276 --- phpBB/phpbb/storage/adapter/local.php | 15 +++++++ phpBB/phpbb/storage/file_info.php | 65 +++++++++++++++++++++++++++ phpBB/phpbb/storage/storage.php | 5 +++ 3 files changed, 85 insertions(+) create mode 100644 phpBB/phpbb/storage/file_info.php diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index de63d0f6a5..a614860030 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -235,4 +235,19 @@ class local implements adapter_interface, stream_interface throw new exception('STORAGE_CANNOT_COPY_RESOURCE'); } } + + public function get_file_info($path) + { + return []; + } + + public function get_size($path) + { + return filesize($this->root_path . $path); + } + + public function get_mimetype($path) + { + return mime_content_type($this->root_path . $path); + } } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php new file mode 100644 index 0000000000..a3bcfbabba --- /dev/null +++ b/phpBB/phpbb/storage/file_info.php @@ -0,0 +1,65 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\storage; + +use phpbb\storage\exception\not_implemented; + +class file_info +{ + protected $adapter; + + protected $path; + + protected $properties; + + public function __construct($adapter, $path) + { + $this->adapter = $adapter; + $this->path = $path; + } + + protected function fill_properties($path) + { + if ($this->properties === null) + { + $this->properties = []; + + foreach($this->adapter->get_file_info($this->path) as $name => $value) { + $this->properties[$name] = $value; + } + } + } + + public function get($name) + { + $this->fill_properties(); + + if (!isset($this->properties[$name])) + { + if (!method_exists($this->adapter, 'get_' . $name)) + { + throw new not_implemented(); + } + + $this->properties[$name] = call_user_func($this->adapter, 'get_' . $name); + } + + return $this->properties[$name]; + } + + public function __get($name) + { + return $this->get($name); + } +} diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index a2eb89ecb3..3ecf0f97af 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -192,4 +192,9 @@ class storage $adapter->put_contents($path, stream_get_contents($resource)); } } + + public function get_fileinfo($path) + { + return new file_info($adapter, $path); + } }