forked from Public/pics
Replace deprecated trigger_error calls with exceptions
This commit is contained in:
@@ -173,10 +173,10 @@ class Database
|
||||
list ($values, $connection) = $this->db_callback;
|
||||
|
||||
if (!isset($matches[2]))
|
||||
trigger_error('Invalid value inserted or no type specified.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Invalid value inserted or no type specified.');
|
||||
|
||||
if (!isset($values[$matches[2]]))
|
||||
trigger_error('The database value you\'re trying to insert does not exist: ' . htmlspecialchars($matches[2]), E_USER_ERROR);
|
||||
throw new UnexpectedValueException('The database value you\'re trying to insert does not exist: ' . htmlspecialchars($matches[2]));
|
||||
|
||||
$replacement = $values[$matches[2]];
|
||||
|
||||
@@ -184,7 +184,7 @@ class Database
|
||||
{
|
||||
case 'int':
|
||||
if ((!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) && $replacement !== 'NULL')
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Integer expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Integer expected.');
|
||||
return $replacement !== 'NULL' ? (string) (int) $replacement : 'NULL';
|
||||
break;
|
||||
|
||||
@@ -197,12 +197,12 @@ class Database
|
||||
if (is_array($replacement))
|
||||
{
|
||||
if (empty($replacement))
|
||||
trigger_error('Database error, given array of integer values is empty.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Database error, given array of integer values is empty.');
|
||||
|
||||
foreach ($replacement as $key => $value)
|
||||
{
|
||||
if (!is_numeric($value) || (string) $value !== (string) (int) $value)
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.');
|
||||
|
||||
$replacement[$key] = (string) (int) $value;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ class Database
|
||||
return implode(', ', $replacement);
|
||||
}
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.');
|
||||
|
||||
break;
|
||||
|
||||
@@ -218,7 +218,7 @@ class Database
|
||||
if (is_array($replacement))
|
||||
{
|
||||
if (empty($replacement))
|
||||
trigger_error('Database error, given array of string values is empty.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Database error, given array of string values is empty.');
|
||||
|
||||
foreach ($replacement as $key => $value)
|
||||
$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
|
||||
@@ -226,7 +226,7 @@ class Database
|
||||
return implode(', ', $replacement);
|
||||
}
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of strings expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of strings expected.');
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
@@ -235,7 +235,7 @@ class Database
|
||||
elseif ($replacement === 'NULL')
|
||||
return 'NULL';
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Date expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Date expected.');
|
||||
break;
|
||||
|
||||
case 'datetime':
|
||||
@@ -246,12 +246,12 @@ class Database
|
||||
elseif ($replacement === 'NULL')
|
||||
return 'NULL';
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. DateTime expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. DateTime expected.');
|
||||
break;
|
||||
|
||||
case 'float':
|
||||
if (!is_numeric($replacement) && $replacement !== 'NULL')
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Floating point number expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Floating point number expected.');
|
||||
return $replacement !== 'NULL' ? (string) (float) $replacement : 'NULL';
|
||||
break;
|
||||
|
||||
@@ -271,7 +271,7 @@ class Database
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('Undefined type <b>' . $matches[1] . '</b> used in the database query', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Undefined type <b>' . $matches[1] . '</b> used in the database query');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -289,7 +289,7 @@ class Database
|
||||
|
||||
// Please, just use new style queries.
|
||||
if (strpos($db_string, '\'') !== false && !$security_override)
|
||||
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Hack attempt!', 'Illegal character (\') used in query.');
|
||||
|
||||
if (!$security_override && !empty($db_values))
|
||||
{
|
||||
@@ -313,7 +313,7 @@ class Database
|
||||
catch (Exception $e)
|
||||
{
|
||||
$clean_sql = implode("\n", array_map('trim', explode("\n", $db_string)));
|
||||
trigger_error($this->error() . '<br>' . $clean_sql, E_USER_ERROR);
|
||||
throw new UnexpectedValueException($this->error() . '<br>' . $clean_sql);
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -327,7 +327,7 @@ class Database
|
||||
{
|
||||
// Please, just use new style queries.
|
||||
if (strpos($db_string, '\'') !== false)
|
||||
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Hack attempt!', 'Illegal character (\') used in query.');
|
||||
|
||||
// Save some values for use in the callback function.
|
||||
$this->db_callback = [$db_values, $this->connection];
|
||||
|
||||
@@ -24,7 +24,7 @@ class Registry
|
||||
public static function get($key)
|
||||
{
|
||||
if (!isset(self::$storage[$key]))
|
||||
trigger_error('Key does not exist in Registry: ' . $key, E_USER_ERROR);
|
||||
throw new Exception('Key does not exist in Registry: ' . $key);
|
||||
|
||||
return self::$storage[$key];
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class Registry
|
||||
public static function remove($key)
|
||||
{
|
||||
if (!isset(self::$storage[$key]))
|
||||
trigger_error('Key does not exist in Registry: ' . $key, E_USER_ERROR);
|
||||
throw new Exception('Key does not exist in Registry: ' . $key);
|
||||
|
||||
unset(self::$storage[$key]);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Session
|
||||
public static function getSessionToken()
|
||||
{
|
||||
if (empty($_SESSION['session_token']))
|
||||
trigger_error('Call to getSessionToken without a session token being set!', E_USER_ERROR);
|
||||
throw new Exception('Call to getSessionToken without a session token being set!');
|
||||
|
||||
return $_SESSION['session_token'];
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class Session
|
||||
public static function getSessionTokenKey()
|
||||
{
|
||||
if (empty($_SESSION['session_token_key']))
|
||||
trigger_error('Call to getSessionTokenKey without a session token key being set!', E_USER_ERROR);
|
||||
throw new Exception('Call to getSessionTokenKey without a session token key being set!');
|
||||
|
||||
return $_SESSION['session_token_key'];
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ class Tag
|
||||
$data);
|
||||
|
||||
if (!$res)
|
||||
trigger_error('Could not create the requested tag.', E_USER_ERROR);
|
||||
throw new Exception('Could not create the requested tag.');
|
||||
|
||||
$data['id_tag'] = $db->insert_id();
|
||||
return $return_format === 'object' ? new Tag($data) : $data;
|
||||
|
||||
Reference in New Issue
Block a user