mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/10057] Use a class for error collection.
Replaced error collection functions with a class for a cleaner implementation. PHPBB3-10057
This commit is contained in:
parent
a4100fe709
commit
17693c2802
2 changed files with 41 additions and 39 deletions
|
@ -85,7 +85,8 @@ class dbal_postgres extends dbal
|
||||||
{
|
{
|
||||||
return $this->sql_error('pg_pconnect function does not exist, is pgsql extension installed?');
|
return $this->sql_error('pg_pconnect function does not exist, is pgsql extension installed?');
|
||||||
}
|
}
|
||||||
phpbb_start_error_collection();
|
$collector = new phpbb_error_collector;
|
||||||
|
$collector->install();
|
||||||
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -94,11 +95,12 @@ class dbal_postgres extends dbal
|
||||||
{
|
{
|
||||||
return $this->sql_error('pg_connect function does not exist, is pgsql extension installed?');
|
return $this->sql_error('pg_connect function does not exist, is pgsql extension installed?');
|
||||||
}
|
}
|
||||||
phpbb_start_error_collection();
|
$collector = new phpbb_error_collector;
|
||||||
|
$collector->install();
|
||||||
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = phpbb_stop_error_collection();
|
$collector->uninstall();
|
||||||
|
|
||||||
if ($this->db_connect_id)
|
if ($this->db_connect_id)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +116,7 @@ class dbal_postgres extends dbal
|
||||||
return $this->db_connect_id;
|
return $this->db_connect_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = phpbb_format_collected_errors($errors);
|
$errors = $collector->format_errors();
|
||||||
return $this->sql_error($errors);
|
return $this->sql_error($errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3928,35 +3928,34 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function phpbb_error_collection_handler($errno, $msg_text, $errfile, $errline)
|
class phpbb_error_collector
|
||||||
{
|
{
|
||||||
global $phpbb_collected_errors;
|
var $errors;
|
||||||
$phpbb_collected_errors[count($phpbb_collected_errors)-1][] = array($errno, $msg_text, $errfile, $errline);
|
|
||||||
|
function phpbb_error_collector()
|
||||||
|
{
|
||||||
|
$this->errors = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function phpbb_start_error_collection()
|
function install()
|
||||||
{
|
{
|
||||||
global $phpbb_collected_errors;
|
set_error_handler(array(&$this, 'error_handler'));
|
||||||
if (!isset($phpbb_collected_errors))
|
|
||||||
{
|
|
||||||
$phpbb_collected_errors = array();
|
|
||||||
}
|
|
||||||
$phpbb_collected_errors[] = array();
|
|
||||||
set_error_handler('phpbb_error_collection_handler');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function phpbb_stop_error_collection()
|
function uninstall()
|
||||||
{
|
{
|
||||||
global $phpbb_collected_errors;
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
$errors = array_pop($phpbb_collected_errors);
|
|
||||||
return $errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function phpbb_format_collected_errors($errors)
|
function error_handler($errno, $msg_text, $errfile, $errline)
|
||||||
|
{
|
||||||
|
$this->errors[] = array($errno, $msg_text, $errfile, $errline);
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_errors()
|
||||||
{
|
{
|
||||||
$text = '';
|
$text = '';
|
||||||
foreach ($errors as $error)
|
foreach ($this->errors as $error)
|
||||||
{
|
{
|
||||||
if (!empty($text))
|
if (!empty($text))
|
||||||
{
|
{
|
||||||
|
@ -3971,6 +3970,7 @@ function phpbb_format_collected_errors($errors)
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries the session table to get information about online guests
|
* Queries the session table to get information about online guests
|
||||||
|
|
Loading…
Add table
Reference in a new issue