mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-10 10:44:20 +02:00
[ticket/15311] Move get_temp_dir to another service
PHPBB3-15311
This commit is contained in:
@@ -36,4 +36,5 @@ services:
|
||||
- '@dispatcher'
|
||||
- '@plupload'
|
||||
- '@storage.attachment'
|
||||
- '@temp'
|
||||
- '@user'
|
||||
|
@@ -34,7 +34,7 @@ services:
|
||||
class: phpbb\db\extractor\mssql_extractor
|
||||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@request'
|
||||
- '@dbal.conn.driver'
|
||||
|
||||
@@ -42,7 +42,7 @@ services:
|
||||
class: phpbb\db\extractor\mysql_extractor
|
||||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@request'
|
||||
- '@dbal.conn.driver'
|
||||
|
||||
@@ -50,7 +50,7 @@ services:
|
||||
class: phpbb\db\extractor\oracle_extractor
|
||||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@request'
|
||||
- '@dbal.conn.driver'
|
||||
|
||||
@@ -58,7 +58,7 @@ services:
|
||||
class: phpbb\db\extractor\postgres_extractor
|
||||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@request'
|
||||
- '@dbal.conn.driver'
|
||||
|
||||
@@ -66,6 +66,6 @@ services:
|
||||
class: phpbb\db\extractor\sqlite3_extractor
|
||||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@request'
|
||||
- '@dbal.conn.driver'
|
||||
|
@@ -71,11 +71,10 @@ services:
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@files.factory'
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@language'
|
||||
- '@php_ini'
|
||||
- '@request'
|
||||
- '%core.root_path%'
|
||||
|
||||
files.types.remote_storage:
|
||||
class: phpbb\files\types\remote_storage
|
||||
@@ -83,8 +82,7 @@ services:
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@files.factory'
|
||||
- '@filesystem'
|
||||
- '@temp'
|
||||
- '@language'
|
||||
- '@php_ini'
|
||||
- '@request'
|
||||
- '%core.root_path%'
|
||||
|
@@ -4,5 +4,9 @@ parameters:
|
||||
services:
|
||||
filesystem:
|
||||
class: phpbb\filesystem\filesystem
|
||||
|
||||
temp:
|
||||
class: phpbb\filesystem\temp
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '%core.filesystem.cache_temp_dir%'
|
||||
|
@@ -215,7 +215,7 @@ class compress_zip extends compress
|
||||
global $phpbb_filesystem;
|
||||
|
||||
$this->fp = @fopen($file, $mode . 'b');
|
||||
$this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem('');
|
||||
$this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem();
|
||||
|
||||
if (!$this->fp)
|
||||
{
|
||||
@@ -582,7 +582,7 @@ class compress_tar extends compress
|
||||
$this->type = &$type;
|
||||
$this->open();
|
||||
|
||||
$this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem('');
|
||||
$this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,6 +21,7 @@ use \phpbb\language\language;
|
||||
use \phpbb\mimetype\guesser;
|
||||
use \phpbb\plupload\plupload;
|
||||
use \phpbb\storage\storage;
|
||||
use \phpbb\filesystem\temp;
|
||||
use \phpbb\user;
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,9 @@ class upload
|
||||
/** @var storage */
|
||||
protected $storage;
|
||||
|
||||
/** @var temp */
|
||||
protected $temp;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
@@ -80,9 +84,10 @@ class upload
|
||||
* @param guesser $mimetype_guesser
|
||||
* @param dispatcher $phpbb_dispatcher
|
||||
* @param plupload $plupload
|
||||
* @param temp $temp
|
||||
* @param user $user
|
||||
*/
|
||||
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, user $user)
|
||||
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, temp $temp, user $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@@ -93,6 +98,7 @@ class upload
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$this->plupload = $plupload;
|
||||
$this->storage = $storage;
|
||||
$this->temp = $temp;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
@@ -234,7 +240,7 @@ class upload
|
||||
{
|
||||
$source = $this->file->get('filename');
|
||||
$destination_name = 'thumb_' . $this->file->get('realname');
|
||||
$destination = sys_get_temp_dir() . '/' . $destination_name;
|
||||
$destination = $this->temp->get_temp_dir() . '/' . $destination_name;
|
||||
|
||||
if (create_thumbnail($source, $destination, $this->file->get('mimetype')))
|
||||
{
|
||||
|
2
phpBB/phpbb/cache/driver/file.php
vendored
2
phpBB/phpbb/cache/driver/file.php
vendored
@@ -35,7 +35,7 @@ class file extends \phpbb\cache\driver\base
|
||||
global $phpbb_container;
|
||||
|
||||
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir');
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem('');
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
|
||||
if (!is_dir($this->cache_dir))
|
||||
{
|
||||
|
@@ -402,7 +402,7 @@ class installer
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
$filesystem = new \phpbb\filesystem\filesystem('');
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
|
||||
return $filesystem->is_writable([
|
||||
$this->root_path . $this->composer_filename,
|
||||
|
@@ -22,9 +22,9 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception;
|
||||
abstract class base_extractor implements extractor_interface
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\filesystem\filesystem
|
||||
* @var \phpbb\filesystem\temp
|
||||
*/
|
||||
protected $filesystem;
|
||||
protected $temp;
|
||||
|
||||
/**
|
||||
* @var \phpbb\request\request_interface
|
||||
@@ -84,12 +84,13 @@ abstract class base_extractor implements extractor_interface
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\filesystem\temp $temp
|
||||
* @param \phpbb\request\request_interface $request
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
*/
|
||||
public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
|
||||
public function __construct(\phpbb\filesystem\temp $temp, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
|
||||
{
|
||||
$this->filesystem = $filesystem;
|
||||
$this->temp = $temp;
|
||||
$this->request = $request;
|
||||
$this->db = $db;
|
||||
$this->fp = null;
|
||||
@@ -163,7 +164,7 @@ abstract class base_extractor implements extractor_interface
|
||||
|
||||
if ($store === true)
|
||||
{
|
||||
$file = $this->filesystem->get_temp_dir() . '/' . $filename . $ext;
|
||||
$file = $this->temp->get_temp_dir() . '/' . $filename . $ext;
|
||||
|
||||
$this->fp = $open($file, 'w');
|
||||
|
||||
|
@@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use phpbb\config\config;
|
||||
use phpbb\files\factory;
|
||||
use phpbb\files\filespec;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\filesystem\temp;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
|
||||
@@ -29,8 +29,8 @@ class remote extends base
|
||||
/** @var factory Files factory */
|
||||
protected $factory;
|
||||
|
||||
/** @var filesystem Filesystem */
|
||||
protected $filesystem;
|
||||
/** @var filesystem Filesystem temp */
|
||||
protected $temp;
|
||||
|
||||
/** @var language */
|
||||
protected $language;
|
||||
@@ -41,29 +41,24 @@ class remote extends base
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Construct a form upload type
|
||||
*
|
||||
* @param config $config phpBB config
|
||||
* @param factory $factory Files factory
|
||||
* @param filesystem $filesystem Filesystem
|
||||
* @param temp $temp Filesystem temp
|
||||
* @param language $language Language class
|
||||
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||
* @param request_interface $request Request object
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
*/
|
||||
public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->factory = $factory;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->temp = $temp;
|
||||
$this->language = $language;
|
||||
$this->php_ini = $php_ini;
|
||||
$this->request = $request;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +146,7 @@ class remote extends base
|
||||
|
||||
$data = $response->getBody();
|
||||
|
||||
$filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-');
|
||||
$filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-');
|
||||
|
||||
if (!($fp = @fopen($filename, 'wb')))
|
||||
{
|
||||
|
@@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use phpbb\config\config;
|
||||
use phpbb\files\factory;
|
||||
use phpbb\files\filespec;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\filesystem\temp;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
|
||||
@@ -29,8 +29,8 @@ class remote_storage extends base
|
||||
/** @var factory Files factory */
|
||||
protected $factory;
|
||||
|
||||
/** @var filesystem Filesystem */
|
||||
protected $filesystem;
|
||||
/** @var temp Filesystem temp */
|
||||
protected $temp;
|
||||
|
||||
/** @var language */
|
||||
protected $language;
|
||||
@@ -41,29 +41,24 @@ class remote_storage extends base
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Construct a form upload type
|
||||
*
|
||||
* @param config $config phpBB config
|
||||
* @param factory $factory Files factory
|
||||
* @param filesystem $filesystem Filesystem
|
||||
* @param temp $temp Filesystem temp
|
||||
* @param language $language Language class
|
||||
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||
* @param request_interface $request Request object
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
*/
|
||||
public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->factory = $factory;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->temp = $temp;
|
||||
$this->language = $language;
|
||||
$this->php_ini = $php_ini;
|
||||
$this->request = $request;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +145,7 @@ class remote_storage extends base
|
||||
|
||||
$data = $response->getBody();
|
||||
|
||||
$filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-');
|
||||
$filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-');
|
||||
|
||||
if (!($fp = @fopen($filename, 'wb')))
|
||||
{
|
||||
|
@@ -42,25 +42,14 @@ class filesystem implements filesystem_interface
|
||||
*/
|
||||
protected $symfony_filesystem;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_temp_dir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $temp_dir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($cache_temp_dir)
|
||||
public function __construct()
|
||||
{
|
||||
$this->chmod_info = array();
|
||||
$this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem();
|
||||
$this->working_directory = null;
|
||||
$this->cache_temp_dir = $cache_temp_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -753,33 +742,4 @@ class filesystem implements filesystem_interface
|
||||
{
|
||||
return helper::resolve_path($path, $prefix, $absolute, $return_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary directory to write files
|
||||
*
|
||||
* @return string returns the directory
|
||||
*/
|
||||
public function get_temp_dir()
|
||||
{
|
||||
if (!isset($this->temp_dir))
|
||||
{
|
||||
$tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
|
||||
|
||||
// Prevent trying to write to system temp dir in case of open_basedir
|
||||
// restrictions being in effect
|
||||
if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
|
||||
{
|
||||
$tmp_dir = $this->cache_temp_dir;
|
||||
|
||||
if (!is_dir($tmp_dir))
|
||||
{
|
||||
$this->mkdir($tmp_dir, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
$this->temp_dir = helper::realpath($tmp_dir);
|
||||
}
|
||||
|
||||
return $this->temp_dir;
|
||||
}
|
||||
}
|
||||
|
54
phpBB/phpbb/filesystem/temp.php
Normal file
54
phpBB/phpbb/filesystem/temp.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\filesystem;
|
||||
|
||||
class temp
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $temp_dir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($filesystem, $cache_temp_dir)
|
||||
{
|
||||
$tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
|
||||
|
||||
// Prevent trying to write to system temp dir in case of open_basedir
|
||||
// restrictions being in effect
|
||||
if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
|
||||
{
|
||||
$tmp_dir = $cache_temp_dir;
|
||||
|
||||
if (!is_dir($tmp_dir))
|
||||
{
|
||||
$filesystem->mkdir($tmp_dir, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
$this->temp_dir = helper::realpath($tmp_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary directory to write files
|
||||
*
|
||||
* @return string returns the directory
|
||||
*/
|
||||
public function get_temp_dir()
|
||||
{
|
||||
return $this->temp_dir;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user