mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/15276] Update file_info
PHPBB3-15276
This commit is contained in:
parent
8d7336e57c
commit
400e663347
3 changed files with 63 additions and 1 deletions
|
@ -85,4 +85,15 @@ interface adapter_interface
|
||||||
* When the file cannot be copied
|
* When the file cannot be copied
|
||||||
*/
|
*/
|
||||||
public function copy($path_orig, $path_dest);
|
public function copy($path_orig, $path_dest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get file info.
|
||||||
|
*
|
||||||
|
* @param string $path The file
|
||||||
|
*
|
||||||
|
* @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method
|
||||||
|
*
|
||||||
|
* @return \phpbb\storage\file_info Returns file_info object
|
||||||
|
*/
|
||||||
|
public function file_properties($path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,16 +236,43 @@ class local implements adapter_interface, stream_interface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function file_properties($path)
|
public function file_properties($path)
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get file size.
|
||||||
|
*
|
||||||
|
* @param string $path The file
|
||||||
|
*
|
||||||
|
* @throws \phpbb\storage\exception\exception When cannot get size
|
||||||
|
*
|
||||||
|
* @return int File size in bytes
|
||||||
|
*/
|
||||||
public function file_size($path)
|
public function file_size($path)
|
||||||
{
|
{
|
||||||
return filesize($this->root_path . $path);
|
$size = filesize($this->root_path . $path);
|
||||||
|
|
||||||
|
if ($size === null)
|
||||||
|
{
|
||||||
|
throw new exception('STORAGE_CANNOT_GET_FILESIZE');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get file mimetype.
|
||||||
|
*
|
||||||
|
* @param string $path The file
|
||||||
|
*
|
||||||
|
* @return string Mime type
|
||||||
|
*/
|
||||||
public function file_mimetype($path)
|
public function file_mimetype($path)
|
||||||
{
|
{
|
||||||
return mime_content_type($this->root_path . $path);
|
return mime_content_type($this->root_path . $path);
|
||||||
|
|
|
@ -17,10 +17,19 @@ use phpbb\storage\exception\not_implemented;
|
||||||
|
|
||||||
class file_info
|
class file_info
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \phpbb\storage\adapter\adapter_interface
|
||||||
|
*/
|
||||||
protected $adapter;
|
protected $adapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $path;
|
protected $path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $properties;
|
protected $properties;
|
||||||
|
|
||||||
public function __construct($adapter, $path)
|
public function __construct($adapter, $path)
|
||||||
|
@ -29,6 +38,11 @@ class file_info
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load propertys lazily.
|
||||||
|
*
|
||||||
|
* @param string path The file path.
|
||||||
|
*/
|
||||||
protected function fill_properties($path)
|
protected function fill_properties($path)
|
||||||
{
|
{
|
||||||
if ($this->properties === null)
|
if ($this->properties === null)
|
||||||
|
@ -42,6 +56,13 @@ class file_info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load propertys lazily.
|
||||||
|
*
|
||||||
|
* @param string name The property name.
|
||||||
|
*
|
||||||
|
* @return string Returns the property value
|
||||||
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
$this->fill_properties($this->path);
|
$this->fill_properties($this->path);
|
||||||
|
@ -59,6 +80,9 @@ class file_info
|
||||||
return $this->properties[$name];
|
return $this->properties[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias of \phpbb\storage\file_info->get()
|
||||||
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
return $this->get($name);
|
return $this->get($name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue