mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/15276] Use mimetype guesser
PHPBB3-15276
This commit is contained in:
parent
09856aeb26
commit
c3e9aa1c18
4 changed files with 15 additions and 15 deletions
|
@ -39,6 +39,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- '@filesystem'
|
- '@filesystem'
|
||||||
- '@upload_imagesize'
|
- '@upload_imagesize'
|
||||||
|
- '@mimetype.guesser'
|
||||||
- '%core.root_path%'
|
- '%core.root_path%'
|
||||||
tags:
|
tags:
|
||||||
- { name: storage.adapter }
|
- { name: storage.adapter }
|
||||||
|
|
|
@ -18,6 +18,7 @@ use phpbb\storage\exception\exception;
|
||||||
use phpbb\filesystem\exception\filesystem_exception;
|
use phpbb\filesystem\exception\filesystem_exception;
|
||||||
use phpbb\filesystem\filesystem;
|
use phpbb\filesystem\filesystem;
|
||||||
use phpbb\filesystem\helper as filesystem_helper;
|
use phpbb\filesystem\helper as filesystem_helper;
|
||||||
|
use phpbb\mimetype\guesser;
|
||||||
use FastImageSize\FastImageSize;
|
use FastImageSize\FastImageSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,12 +34,19 @@ class local implements adapter_interface, stream_interface
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filesystem component
|
* FastImageSize
|
||||||
*
|
*
|
||||||
* @var \FastImageSize\FastImageSize
|
* @var \FastImageSize\FastImageSize
|
||||||
*/
|
*/
|
||||||
protected $imagesize;
|
protected $imagesize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mimetype Guesser component
|
||||||
|
*
|
||||||
|
* @var \phpbb\mimetype\guesser
|
||||||
|
*/
|
||||||
|
protected $mimetype_guesser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string path
|
* @var string path
|
||||||
*/
|
*/
|
||||||
|
@ -52,10 +60,11 @@ class local implements adapter_interface, stream_interface
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct(filesystem $filesystem, FastImageSize $imagesize, $phpbb_root_path)
|
public function __construct(filesystem $filesystem, FastImageSize $imagesize, guesser $mimetype_guesser, $phpbb_root_path)
|
||||||
{
|
{
|
||||||
$this->filesystem = $filesystem;
|
$this->filesystem = $filesystem;
|
||||||
$this->imagesize = $imagesize;
|
$this->imagesize = $imagesize;
|
||||||
|
$this->mimetype_guesser = $mimetype_guesser;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,17 +284,7 @@ class local implements adapter_interface, stream_interface
|
||||||
*/
|
*/
|
||||||
public function file_mimetype($path)
|
public function file_mimetype($path)
|
||||||
{
|
{
|
||||||
if (class_exists('finfo'))
|
return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $path)];
|
||||||
{
|
|
||||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
|
||||||
$mimetype = $finfo->file($this->root_path . $path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$mimetype = mime_content_type($this->root_path . $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['mimetype' => $mimetype];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
|
||||||
->will($this->returnArgument(0));
|
->will($this->returnArgument(0));
|
||||||
|
|
||||||
$filesystem = new \phpbb\filesystem\filesystem();
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path);
|
$adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
|
||||||
$adapter->configure(['path' => 'images/avatars/upload']);
|
$adapter->configure(['path' => 'images/avatars/upload']);
|
||||||
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
|
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
|
||||||
$adapter_factory_mock->expects($this->any())
|
$adapter_factory_mock->expects($this->any())
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
$filesystem = new \phpbb\filesystem\filesystem();
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
|
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
$this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path);
|
$this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
|
||||||
$this->adapter->configure(['path' => 'test_path']);
|
$this->adapter->configure(['path' => 'test_path']);
|
||||||
|
|
||||||
$this->path = $phpbb_root_path . 'test_path/';
|
$this->path = $phpbb_root_path . 'test_path/';
|
||||||
|
|
Loading…
Add table
Reference in a new issue