mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 00:02:18 +02:00
[ticket/11832] Inject dependencies for phpbb_get_web_root_path (also moving)
Function moved from phpbb_get_web_root_path to filesystem::get_web_root_path PHPBB3-11832
This commit is contained in:
parent
2146d0c36b
commit
f30b87519e
@ -47,7 +47,7 @@ if (!defined('PHPBB_INSTALLED'))
|
||||
|
||||
// Eliminate . and .. from the path
|
||||
require($phpbb_root_path . 'phpbb/filesystem.' . $phpEx);
|
||||
$phpbb_filesystem = new phpbb_filesystem();
|
||||
$phpbb_filesystem = new phpbb_filesystem($phpbb_root_path);
|
||||
$script_path = $phpbb_filesystem->clean_path($script_path);
|
||||
|
||||
$url = (($secure) ? 'https://' : 'http://') . $server_name;
|
||||
|
@ -169,6 +169,8 @@ services:
|
||||
|
||||
filesystem:
|
||||
class: phpbb_filesystem
|
||||
arguments:
|
||||
- %core.root_path%
|
||||
|
||||
groupposition.legend:
|
||||
class: phpbb_groupposition_legend
|
||||
|
@ -7,8 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
@ -2413,7 +2411,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
||||
{
|
||||
global $_SID, $_EXTRA_URL, $phpbb_hook;
|
||||
global $phpbb_dispatcher;
|
||||
global $symfony_request, $phpbb_root_path;
|
||||
global $symfony_request, $phpbb_root_path, $phpbb_container;
|
||||
|
||||
if ($params === '' || (is_array($params) && empty($params)))
|
||||
{
|
||||
@ -2421,7 +2419,8 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
||||
$params = false;
|
||||
}
|
||||
|
||||
$corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : '';
|
||||
$phpbb_filesystem = $phpbb_container->get('filesystem');
|
||||
$corrected_path = $phpbb_filesystem->get_web_root_path($symfony_request);
|
||||
if ($corrected_path)
|
||||
{
|
||||
$url = substr($corrected_path . $url, strlen($phpbb_root_path));
|
||||
@ -5218,7 +5217,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
||||
// This path is sent with the base template paths in the assign_vars()
|
||||
// call below. We need to correct it in case we are accessing from a
|
||||
// controller because the web paths will be incorrect otherwise.
|
||||
$corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : '';
|
||||
$phpbb_filesystem = $phpbb_container->get('filesystem');
|
||||
$corrected_path = $phpbb_filesystem->get_web_root_path($symfony_request);
|
||||
$web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path;
|
||||
|
||||
// Send a proper content-language to the output
|
||||
@ -5725,42 +5725,3 @@ function phpbb_create_symfony_request(phpbb_request $request)
|
||||
$symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters);
|
||||
return $symfony_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a relative root path from the current URL
|
||||
*
|
||||
* @param Request $symfony_request Symfony Request object
|
||||
*/
|
||||
function phpbb_get_web_root_path(Request $symfony_request, $phpbb_root_path = '')
|
||||
{
|
||||
global $phpbb_container;
|
||||
|
||||
static $path;
|
||||
if (null !== $path)
|
||||
{
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path_info = $symfony_request->getPathInfo();
|
||||
if ($path_info === '/')
|
||||
{
|
||||
$path = $phpbb_root_path;
|
||||
return $path;
|
||||
}
|
||||
|
||||
$filesystem = $phpbb_container->get('filesystem');
|
||||
$path_info = $filesystem->clean_path($path_info);
|
||||
|
||||
// Do not count / at start of path
|
||||
$corrections = substr_count(substr($path_info, 1), '/');
|
||||
|
||||
// When URL Rewriting is enabled, app.php is optional. We have to
|
||||
// correct for it not being there
|
||||
if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false)
|
||||
{
|
||||
$corrections -= 1;
|
||||
}
|
||||
|
||||
$path = $phpbb_root_path . str_repeat('../', $corrections);
|
||||
return $path;
|
||||
}
|
||||
|
@ -6,6 +6,9 @@
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
@ -20,6 +23,72 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
class phpbb_filesystem
|
||||
{
|
||||
/** @var string */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct($phpbb_root_path)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phpBB root path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_phpbb_root_path()
|
||||
{
|
||||
return $this->phpbb_root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a relative root path from the current URL
|
||||
*
|
||||
* @param Request $symfony_request Symfony Request object
|
||||
* @return string
|
||||
*/
|
||||
function get_web_root_path(Request $symfony_request = null)
|
||||
{
|
||||
if ($symfony_request === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
static $path;
|
||||
if (null !== $path)
|
||||
{
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path_info = $symfony_request->getPathInfo();
|
||||
if ($path_info === '/')
|
||||
{
|
||||
$path = $this->phpbb_root_path;
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path_info = $this->clean_path($path_info);
|
||||
|
||||
// Do not count / at start of path
|
||||
$corrections = substr_count(substr($path_info, 1), '/');
|
||||
|
||||
// When URL Rewriting is enabled, app.php is optional. We have to
|
||||
// correct for it not being there
|
||||
if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false)
|
||||
{
|
||||
$corrections -= 1;
|
||||
}
|
||||
|
||||
$path = $this->phpbb_root_path . str_repeat('../', $corrections);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eliminates useless . and .. components from specified path.
|
||||
*
|
||||
|
@ -59,7 +59,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
$container,
|
||||
$this->db,
|
||||
$this->config,
|
||||
new phpbb_filesystem(),
|
||||
new phpbb_filesystem(dirname(__FILE__) . '/../../phpBB/'),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/../../phpBB/',
|
||||
'php',
|
||||
|
@ -114,7 +114,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
$container,
|
||||
$db,
|
||||
$config,
|
||||
new phpbb_filesystem(),
|
||||
new phpbb_filesystem($phpbb_root_path),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
$php_ext,
|
||||
|
@ -65,7 +65,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
||||
$container,
|
||||
$this->db,
|
||||
$this->config,
|
||||
new phpbb_filesystem(),
|
||||
new phpbb_filesystem($this->phpbb_root_path),
|
||||
'phpbb_ext',
|
||||
$this->phpbb_root_path,
|
||||
$this->phpEx,
|
||||
|
@ -14,7 +14,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->filesystem = new phpbb_filesystem();
|
||||
$this->filesystem = new phpbb_filesystem(__DIR__ . './../../phpBB/');
|
||||
}
|
||||
|
||||
public function clean_path_data()
|
||||
|
@ -14,6 +14,6 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = 'php';
|
||||
$this->extensions = $extensions;
|
||||
$this->filesystem = new phpbb_filesystem();
|
||||
$this->filesystem = new phpbb_filesystem($phpbb_root_path);
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$container,
|
||||
$db,
|
||||
$config,
|
||||
new phpbb_filesystem(),
|
||||
new phpbb_filesystem($phpbb_root_path),
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
dirname(__FILE__) . '/',
|
||||
$php_ext,
|
||||
|
Loading…
x
Reference in New Issue
Block a user