mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-29 14:48:53 +00:00
[ticket/10714] Remove dependency injection and use global instead
This avoids loading functions_admin.php globally and was suggested by naderman PHPBB3-10714
This commit is contained in:
parent
d828ef93f2
commit
d289bc13ac
3 changed files with 13 additions and 43 deletions
|
@ -76,7 +76,6 @@ if (!empty($load_extensions) && function_exists('dl'))
|
||||||
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
||||||
|
|
||||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
||||||
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
|
||||||
|
|
||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
|
@ -119,6 +118,8 @@ $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
|
||||||
set_config(null, null, null, $config);
|
set_config(null, null, null, $config);
|
||||||
set_config_count(null, null, null, $config);
|
set_config_count(null, null, null, $config);
|
||||||
|
|
||||||
|
$phpbb_log = new phpbb_log(LOG_TABLE);
|
||||||
|
|
||||||
// load extensions
|
// load extensions
|
||||||
$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver());
|
$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver());
|
||||||
|
|
||||||
|
@ -140,14 +141,6 @@ foreach ($cache->obtain_hooks() as $hook)
|
||||||
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
|
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure add_log uses this log instance
|
|
||||||
$phpbb_log = new phpbb_log(LOG_TABLE);
|
|
||||||
add_log($phpbb_log); // "dependency injection" for a function
|
|
||||||
// Parameter 2 and 3 are passed by reference, so we need to create a variable for it.
|
|
||||||
$tmp_var = '';
|
|
||||||
view_log($phpbb_log, $tmp_var, $tmp_var); // "dependency injection" for a function
|
|
||||||
unset($tmp_var);
|
|
||||||
|
|
||||||
if (!$config['use_system_cron'])
|
if (!$config['use_system_cron'])
|
||||||
{
|
{
|
||||||
$cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
|
$cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
|
||||||
|
|
|
@ -3357,29 +3357,20 @@ function parse_cfg_file($filename, $lines = false)
|
||||||
*/
|
*/
|
||||||
function add_log()
|
function add_log()
|
||||||
{
|
{
|
||||||
// This is all just an ugly hack to add "Dependency Injection" to a function
|
global $phpbb_log;
|
||||||
// the only real code is the function call which maps this function to a method.
|
|
||||||
static $static_log = null;
|
|
||||||
|
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$log = (isset($args[0])) ? $args[0] : false;
|
$log = (isset($args[0])) ? $args[0] : false;
|
||||||
|
|
||||||
if ($log instanceof phpbb_log_interface)
|
if ($log === false)
|
||||||
{
|
|
||||||
$static_log = $log;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if ($log === false)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp_log = $static_log;
|
|
||||||
|
|
||||||
// no log class set, create a temporary one ourselves to keep backwards compatability
|
// no log class set, create a temporary one ourselves to keep backwards compatability
|
||||||
if ($tmp_log === null)
|
if ($phpbb_log === null)
|
||||||
{
|
{
|
||||||
$tmp_log = new phpbb_log(LOG_TABLE);
|
$phpbb_log = new phpbb_log(LOG_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mode = array_shift($args);
|
$mode = array_shift($args);
|
||||||
|
@ -3407,7 +3398,7 @@ function add_log()
|
||||||
$user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id'];
|
$user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id'];
|
||||||
$user_ip = (empty($user->ip)) ? '' : $user->ip;
|
$user_ip = (empty($user->ip)) ? '' : $user->ip;
|
||||||
|
|
||||||
return $tmp_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data);
|
return $phpbb_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2488,34 +2488,20 @@ function cache_moderators()
|
||||||
*/
|
*/
|
||||||
function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '')
|
function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '')
|
||||||
{
|
{
|
||||||
// This is all just an ugly hack to add "Dependency Injection" to a function
|
global $phpbb_log;
|
||||||
// the only real code is the function call which maps this function to a method.
|
|
||||||
static $static_log = null;
|
|
||||||
|
|
||||||
if ($mode instanceof phpbb_log_interface)
|
|
||||||
{
|
|
||||||
$static_log = $mode;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if ($mode === false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp_log = $static_log;
|
|
||||||
|
|
||||||
// no log class set, create a temporary one ourselves to keep backwards compatability
|
// no log class set, create a temporary one ourselves to keep backwards compatability
|
||||||
if ($tmp_log === null)
|
if ($phpbb_log === null)
|
||||||
{
|
{
|
||||||
$tmp_log = new phpbb_log(LOG_TABLE);
|
$phpbb_log = new phpbb_log(LOG_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count_logs = ($log_count !== false);
|
$count_logs = ($log_count !== false);
|
||||||
|
|
||||||
$log = $tmp_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords);
|
$log = $phpbb_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords);
|
||||||
$log_count = $tmp_log->get_log_count();
|
$log_count = $phpbb_log->get_log_count();
|
||||||
|
|
||||||
return $tmp_log->get_valid_offset();
|
return $phpbb_log->get_valid_offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue