mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-08 18:05:17 +02:00
[ticket/15276] Add methods to get file info
PHPBB3-15276
This commit is contained in:
parent
4c5114c14d
commit
946f0348a2
@ -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);
|
||||
}
|
||||
}
|
||||
|
65
phpBB/phpbb/storage/file_info.php
Normal file
65
phpBB/phpbb/storage/file_info.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user