1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 11:44:08 +02:00

[ticket/15253] Use storage helper methods instead of filesystem methods

PHPBB3-15253
This commit is contained in:
Rubén Calvo
2017-06-26 15:49:31 +02:00
parent 21c9b0eeae
commit ecb79539f4
62 changed files with 109 additions and 598 deletions

View File

@@ -20,20 +20,15 @@ class asset
/** @var \phpbb\path_helper **/
protected $path_helper;
/** @var \phpbb\filesystem\filesystem */
protected $filesystem;
/**
* Constructor
*
* @param string $url URL
* @param \phpbb\path_helper $path_helper Path helper object
* @param \phpbb\filesystem\filesystem $filesystem
*/
public function __construct($url, \phpbb\path_helper $path_helper, \phpbb\filesystem\filesystem $filesystem)
public function __construct($url, \phpbb\path_helper $path_helper)
{
$this->path_helper = $path_helper;
$this->filesystem = $filesystem;
$this->set_url($url);
}
@@ -158,7 +153,7 @@ class asset
public function set_path($path, $urlencode = false)
{
// Since 1.7.0 Twig returns the real path of the file. We need it to be relative.
$real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
$real_root_path = \phpbb\storage\helper::realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
// If the asset is under the phpBB root path we need to remove its path and then prepend $phpbb_root_path
if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
@@ -168,7 +163,7 @@ class asset
else
{
// Else we make the path relative to the current working directory
$real_root_path = $this->filesystem->realpath('.') . DIRECTORY_SEPARATOR;
$real_root_path = \phpbb\storage\helper::realpath('.') . DIRECTORY_SEPARATOR;
if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
{
$path = str_replace('\\', '/', substr($path, strlen($real_root_path)));

View File

@@ -20,24 +20,6 @@ class loader extends \Twig_Loader_Filesystem
{
protected $safe_directories = array();
/**
* @var \phpbb\filesystem\filesystem_interface
*/
protected $filesystem;
/**
* Constructor
*
* @param \phpbb\filesystem\filesystem_interface $filesystem
* @param string|array $paths
*/
public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $paths = array())
{
$this->filesystem = $filesystem;
parent::__construct($paths, $this->filesystem->realpath(dirname(__FILE__)));
}
/**
* Set safe directories
*
@@ -67,7 +49,7 @@ class loader extends \Twig_Loader_Filesystem
*/
public function addSafeDirectory($directory)
{
$directory = $this->filesystem->realpath($directory);
$directory = \phpbb\storage\helper::realpath($directory);
if ($directory !== false)
{
@@ -107,7 +89,7 @@ class loader extends \Twig_Loader_Filesystem
*/
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
{
return parent::addPath($this->filesystem->realpath($path), $namespace);
return parent::addPath(\phpbb\storage\helper::realpath($path), $namespace);
}
/**
@@ -147,7 +129,7 @@ class loader extends \Twig_Loader_Filesystem
// can now check if we're within a "safe" directory
// Find the real path of the directory the file is in
$directory = $this->filesystem->realpath(dirname($file));
$directory = \phpbb\storage\helper::realpath(dirname($file));
if ($directory === false)
{