mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-16 22:51:23 +02:00
[ticket/13904] Pass request service to upload instead of using global
PHPBB3-13904
This commit is contained in:
@@ -23,3 +23,4 @@ services:
|
|||||||
- @filesystem
|
- @filesystem
|
||||||
- @files.factory
|
- @files.factory
|
||||||
- @language
|
- @language
|
||||||
|
- @request
|
||||||
|
@@ -13,7 +13,10 @@
|
|||||||
|
|
||||||
namespace phpbb\files;
|
namespace phpbb\files;
|
||||||
|
|
||||||
|
use \phpbb\filesystem\filesystem_interface;
|
||||||
use \phpbb\language\language;
|
use \phpbb\language\language;
|
||||||
|
use \phpbb\plupload\plupload;
|
||||||
|
use \phpbb\request\request_interface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File upload class
|
* File upload class
|
||||||
@@ -57,18 +60,23 @@ class upload
|
|||||||
/** @var \phpbb\language\language Language class */
|
/** @var \phpbb\language\language Language class */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var \phpbb\request\request_interface Request class */
|
||||||
|
protected $request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init file upload class.
|
* Init file upload class.
|
||||||
*
|
*
|
||||||
* @param \phpbb\filesystem\filesystem_interface $filesystem
|
* @param \phpbb\filesystem\filesystem_interface $filesystem
|
||||||
* @param \phpbb\files\factory $factory Files factory
|
* @param \phpbb\files\factory $factory Files factory
|
||||||
* @param \phpbb\language\language $language Language class
|
* @param \phpbb\language\language $language Language class
|
||||||
|
* @param \phpbb\request\request_interface $request Request class
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, factory $factory, language $language)
|
public function __construct(filesystem_interface $filesystem, factory $factory, language $language, request_interface $request)
|
||||||
{
|
{
|
||||||
$this->filesystem = $filesystem;
|
$this->filesystem = $filesystem;
|
||||||
$this->factory = $factory;
|
$this->factory = $factory;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,11 +186,9 @@ class upload
|
|||||||
* @return filespec $file Object "filespec" is returned, all further operations can be done with this object
|
* @return filespec $file Object "filespec" is returned, all further operations can be done with this object
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function form_upload($form_name, \phpbb\plupload\plupload $plupload = null)
|
function form_upload($form_name, plupload $plupload = null)
|
||||||
{
|
{
|
||||||
global $request;
|
$upload = $this->request->file($form_name);
|
||||||
|
|
||||||
$upload = $request->file($form_name);
|
|
||||||
unset($upload['local_mode']);
|
unset($upload['local_mode']);
|
||||||
|
|
||||||
if ($plupload)
|
if ($plupload)
|
||||||
@@ -264,8 +270,6 @@ class upload
|
|||||||
*/
|
*/
|
||||||
function local_upload($source_file, $filedata = false)
|
function local_upload($source_file, $filedata = false)
|
||||||
{
|
{
|
||||||
global $request;
|
|
||||||
|
|
||||||
$upload = array();
|
$upload = array();
|
||||||
|
|
||||||
$upload['local_mode'] = true;
|
$upload['local_mode'] = true;
|
||||||
@@ -331,7 +335,7 @@ class upload
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->common_checks($file);
|
$this->common_checks($file);
|
||||||
$request->overwrite('local', $upload, \phpbb\request\request_interface::FILES);
|
$this->request->overwrite('local', $upload, request_interface::FILES);
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
@@ -657,8 +661,7 @@ class upload
|
|||||||
*/
|
*/
|
||||||
function is_valid($form_name)
|
function is_valid($form_name)
|
||||||
{
|
{
|
||||||
global $request;
|
$upload = $this->request->file($form_name);
|
||||||
$upload = $request->file($form_name);
|
|
||||||
|
|
||||||
return (!empty($upload) && $upload['name'] !== 'none');
|
return (!empty($upload) && $upload['name'] !== 'none');
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
/** @var \phpbb\language\language */
|
/** @var \phpbb\language\language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var \phpbb\request\request_interface */
|
||||||
|
protected $request;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -44,6 +47,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
|
|
||||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
||||||
|
$this->request = $this->getMock('\phpbb\request\request');
|
||||||
|
|
||||||
$container = new phpbb_mock_container_builder();
|
$container = new phpbb_mock_container_builder();
|
||||||
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language));
|
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language));
|
||||||
@@ -61,7 +65,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
public function test_invalid_extension()
|
public function test_invalid_extension()
|
||||||
{
|
{
|
||||||
/** @var \phpbb\files\upload $upload */
|
/** @var \phpbb\files\upload $upload */
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_error_prefix('')
|
$upload->set_error_prefix('')
|
||||||
->set_allowed_extensions(array('jpg'))
|
->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
@@ -72,7 +76,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
public function test_empty_file()
|
public function test_empty_file()
|
||||||
{
|
{
|
||||||
/** @var \phpbb\files\upload $upload */
|
/** @var \phpbb\files\upload $upload */
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_error_prefix('')
|
$upload->set_error_prefix('')
|
||||||
->set_allowed_extensions(array('jpg'))
|
->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
@@ -83,7 +87,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
public function test_successful_upload()
|
public function test_successful_upload()
|
||||||
{
|
{
|
||||||
/** @var \phpbb\files\upload $upload */
|
/** @var \phpbb\files\upload $upload */
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_error_prefix('')
|
$upload->set_error_prefix('')
|
||||||
->set_allowed_extensions(array('gif'))
|
->set_allowed_extensions(array('gif'))
|
||||||
->set_max_filesize(1000);
|
->set_max_filesize(1000);
|
||||||
@@ -95,7 +99,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
|||||||
public function test_too_large()
|
public function test_too_large()
|
||||||
{
|
{
|
||||||
/** @var \phpbb\files\upload $upload */
|
/** @var \phpbb\files\upload $upload */
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_error_prefix('')
|
$upload->set_error_prefix('')
|
||||||
->set_allowed_extensions(array('gif'))
|
->set_allowed_extensions(array('gif'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
|
@@ -30,11 +30,13 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
/** @var \phpbb\language\language */
|
/** @var \phpbb\language\language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var \phpbb\request\request_interface */
|
||||||
|
protected $request;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// Global $config required by unique_id
|
// Global $config required by unique_id
|
||||||
// Global $request required by form_upload, local_upload and is_valid
|
global $config, $phpbb_root_path, $phpEx;
|
||||||
global $config, $request, $phpbb_root_path, $phpEx;
|
|
||||||
|
|
||||||
if (!is_array($config))
|
if (!is_array($config))
|
||||||
{
|
{
|
||||||
@@ -44,7 +46,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
$config['rand_seed'] = '';
|
$config['rand_seed'] = '';
|
||||||
$config['rand_seed_last_update'] = time() + 600;
|
$config['rand_seed_last_update'] = time() + 600;
|
||||||
|
|
||||||
$request = new phpbb_mock_request();
|
$this->request = $this->getMock('\phpbb\request\request');
|
||||||
|
|
||||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
||||||
@@ -83,7 +85,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_common_checks_invalid_extension()
|
public function test_common_checks_invalid_extension()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('png'))
|
$upload->set_allowed_extensions(array('png'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
$file = $this->gen_valid_filespec();
|
$file = $this->gen_valid_filespec();
|
||||||
@@ -93,7 +95,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_common_checks_invalid_filename()
|
public function test_common_checks_invalid_filename()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
$file = $this->gen_valid_filespec();
|
$file = $this->gen_valid_filespec();
|
||||||
@@ -104,7 +106,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_common_checks_too_large()
|
public function test_common_checks_too_large()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(100);
|
->set_max_filesize(100);
|
||||||
$file = $this->gen_valid_filespec();
|
$file = $this->gen_valid_filespec();
|
||||||
@@ -115,7 +117,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_common_checks_valid_file()
|
public function test_common_checks_valid_file()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(1000);
|
->set_max_filesize(1000);
|
||||||
$file = $this->gen_valid_filespec();
|
$file = $this->gen_valid_filespec();
|
||||||
@@ -125,7 +127,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_local_upload()
|
public function test_local_upload()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(1000);
|
->set_max_filesize(1000);
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_move_existent_file()
|
public function test_move_existent_file()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(1000);
|
->set_max_filesize(1000);
|
||||||
|
|
||||||
@@ -151,7 +153,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_move_existent_file_overwrite()
|
public function test_move_existent_file_overwrite()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(array('jpg'))
|
$upload->set_allowed_extensions(array('jpg'))
|
||||||
->set_max_filesize(1000);
|
->set_max_filesize(1000);
|
||||||
|
|
||||||
@@ -166,7 +168,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
|||||||
|
|
||||||
public function test_valid_dimensions()
|
public function test_valid_dimensions()
|
||||||
{
|
{
|
||||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language);
|
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
|
||||||
$upload->set_allowed_extensions(false)
|
$upload->set_allowed_extensions(false)
|
||||||
->set_max_filesize(false)
|
->set_max_filesize(false)
|
||||||
->set_allowed_dimensions(1, 1, 100, 100);
|
->set_allowed_dimensions(1, 1, 100, 100);
|
||||||
|
Reference in New Issue
Block a user