1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

updated for Nette 2.0 beta: exceptions

This commit is contained in:
David Grudl
2011-07-01 07:58:27 +02:00
parent 508e8638e8
commit ac1f45b397
18 changed files with 90 additions and 93 deletions

View File

@@ -45,12 +45,12 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('interbase')) {
throw new NotSupportedException("PHP extension 'interbase' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'interbase' is not loaded.");
}
}
@@ -170,7 +170,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
public function begin($savepoint = NULL)
{
if ($savepoint !== NULL) {
throw new NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
throw new DibiNotSupportedException('Savepoints are not supported in Firebird/Interbase.');
}
$this->transaction = ibase_trans($this->resource);
$this->inTransaction = TRUE;
@@ -187,7 +187,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
public function commit($savepoint = NULL)
{
if ($savepoint !== NULL) {
throw new NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
throw new DibiNotSupportedException('Savepoints are not supported in Firebird/Interbase.');
}
if (!ibase_commit($this->transaction)) {
@@ -208,7 +208,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
public function rollback($savepoint = NULL)
{
if ($savepoint !== NULL) {
throw new NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
throw new DibiNotSupportedException('Savepoints are not supported in Firebird/Interbase.');
}
if (!ibase_rollback($this->transaction)) {
@@ -312,7 +312,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
*/
public function escapeLike($value, $pos)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -410,7 +410,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
*/
public function seek($row)
{
throw new NotSupportedException("Firebird/Interbase do not support seek in result set.");
throw new DibiNotSupportedException("Firebird/Interbase do not support seek in result set.");
}
@@ -444,7 +444,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
*/
public function getResultColumns()
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}

View File

@@ -38,12 +38,12 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('mssql')) {
throw new NotSupportedException("PHP extension 'mssql' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'mssql' is not loaded.");
}
}
@@ -189,7 +189,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
*/
public function getReflector()
{
throw new NotSupportedException;
throw new DibiNotSupportedException;
}
@@ -292,7 +292,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
if ($offset) {
throw new NotImplementedException('Offset is not implemented.');
throw new DibiNotImplementedException('Offset is not implemented.');
}
}

View File

@@ -42,12 +42,12 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('sqlsrv')) {
throw new NotSupportedException("PHP extension 'sqlsrv' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'sqlsrv' is not loaded.");
}
}
@@ -197,7 +197,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
*/
public function getReflector()
{
throw new NotSupportedException;
throw new DibiNotSupportedException;
}
@@ -300,7 +300,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
}
if ($offset) {
throw new NotImplementedException('Offset is not implemented.');
throw new DibiNotImplementedException('Offset is not implemented.');
}
}
@@ -327,7 +327,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
*/
public function getRowCount()
{
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
@@ -351,7 +351,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
*/
public function seek($row)
{
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}

View File

@@ -54,12 +54,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('mysql')) {
throw new NotSupportedException("PHP extension 'mysql' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'mysql' is not loaded.");
}
}
@@ -398,7 +398,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
public function getRowCount()
{
if (!$this->buffered) {
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
return mysql_num_rows($this->resultSet);
}
@@ -426,7 +426,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
public function seek($row)
{
if (!$this->buffered) {
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}
return mysql_data_seek($this->resultSet, $row);

View File

@@ -125,7 +125,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
*/
public function getForeignKeys($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
}

View File

@@ -55,12 +55,12 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('mysqli')) {
throw new NotSupportedException("PHP extension 'mysqli' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'mysqli' is not loaded.");
}
}
@@ -394,7 +394,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
public function getRowCount()
{
if (!$this->buffered) {
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
return mysqli_num_rows($this->resultSet);
}
@@ -422,7 +422,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
public function seek($row)
{
if (!$this->buffered) {
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}
return mysqli_data_seek($this->resultSet, $row);
}

View File

@@ -43,12 +43,12 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('odbc')) {
throw new NotSupportedException("PHP extension 'odbc' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'odbc' is not loaded.");
}
}
@@ -133,7 +133,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
*/
public function getInsertId($sequence)
{
throw new NotSupportedException('ODBC does not support autoincrementing.');
throw new DibiNotSupportedException('ODBC does not support autoincrementing.');
}
@@ -314,7 +314,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
}
if ($offset) throw new NotSupportedException('Offset is not implemented in driver odbc.');
if ($offset) throw new DibiNotSupportedException('Offset is not implemented in driver odbc.');
}
@@ -484,7 +484,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
*/
public function getIndexes($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -496,7 +496,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
*/
public function getForeignKeys($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
}

View File

@@ -45,12 +45,12 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('oci8')) {
throw new NotSupportedException("PHP extension 'oci8' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'oci8' is not loaded.");
}
}
@@ -124,7 +124,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getAffectedRows()
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -269,7 +269,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function escapeLike($value, $pos)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -332,7 +332,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getRowCount()
{
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
@@ -356,7 +356,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function seek($row)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -437,7 +437,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getColumns($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -449,7 +449,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getIndexes($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -461,7 +461,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getForeignKeys($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
}

View File

@@ -47,12 +47,12 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('pdo')) {
throw new NotSupportedException("PHP extension 'pdo' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'pdo' is not loaded.");
}
}
@@ -230,7 +230,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
return new DibiSqliteReflector($this);
default:
throw new NotSupportedException;
throw new DibiNotSupportedException;
}
}
@@ -315,7 +315,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
*/
public function escapeLike($value, $pos)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
@@ -381,7 +381,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
// intentionally break omitted
default:
throw new NotSupportedException('PDO or driver does not support applying limit or offset.');
throw new DibiNotSupportedException('PDO or driver does not support applying limit or offset.');
}
}
@@ -421,7 +421,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
*/
public function seek($row)
{
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}
@@ -449,7 +449,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
for ($i = 0; $i < $count; $i++) {
$row = @$this->resultSet->getColumnMeta($i); // intentionally @
if ($row === FALSE) {
throw new NotSupportedException('Driver does not support meta data.');
throw new DibiNotSupportedException('Driver does not support meta data.');
}
// PHP < 5.2.3 compatibility
// @see: http://php.net/manual/en/pdostatement.getcolumnmeta.php#pdostatement.getcolumnmeta.changelog

View File

@@ -44,12 +44,12 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('pgsql')) {
throw new NotSupportedException("PHP extension 'pgsql' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'pgsql' is not loaded.");
}
}
@@ -323,7 +323,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
$value = pg_escape_string($this->connection, $value);
} else {
$value = pg_escape_string($value);
}
}
$value = strtr($value, array( '%' => '\\\\%', '_' => '\\\\_'));
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
@@ -578,7 +578,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
*/
public function getForeignKeys($table)
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
}

View File

@@ -52,12 +52,12 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('sqlite')) {
throw new NotSupportedException("PHP extension 'sqlite' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'sqlite' is not loaded.");
}
}
@@ -279,7 +279,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function escapeLike($value, $pos)
{
throw new NotSupportedException;
throw new DibiNotSupportedException;
}
@@ -327,7 +327,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
public function getRowCount()
{
if (!$this->buffered) {
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
return sqlite_num_rows($this->resultSet);
}
@@ -367,7 +367,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
public function seek($row)
{
if (!$this->buffered) {
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}
return sqlite_seek($this->resultSet, $row);
}

View File

@@ -150,7 +150,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
public function getForeignKeys($table)
{
if (!($this->driver instanceof DibiSqlite3Driver)) {
// throw new NotSupportedException; // @see http://www.sqlite.org/foreignkeys.html
// throw new DibiNotSupportedException; // @see http://www.sqlite.org/foreignkeys.html
}
$res = $this->driver->query("PRAGMA foreign_key_list([$table])");
$keys = array();

View File

@@ -47,12 +47,12 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
/**
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function __construct()
{
if (!extension_loaded('sqlite3')) {
throw new NotSupportedException("PHP extension 'sqlite3' is not loaded.");
throw new DibiNotSupportedException("PHP extension 'sqlite3' is not loaded.");
}
}
@@ -327,11 +327,11 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
/**
* Returns the number of rows in a result set.
* @return int
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function getRowCount()
{
throw new NotSupportedException('Row count is not available for unbuffered queries.');
throw new DibiNotSupportedException('Row count is not available for unbuffered queries.');
}
@@ -364,11 +364,11 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
* Moves cursor position without fetching row.
* @param int the 0-based cursor pos to seek to
* @return boolean TRUE on success, FALSE if unable to seek to specified record
* @throws NotSupportedException
* @throws DibiNotSupportedException
*/
public function seek($row)
{
throw new NotSupportedException('Cannot seek an unbuffered result set.');
throw new DibiNotSupportedException('Cannot seek an unbuffered result set.');
}

View File

@@ -689,7 +689,7 @@ class DibiConnection extends DibiObject
$handle = @fopen($file, 'r'); // intentionally @
if (!$handle) {
throw new FileNotFoundException("Cannot open file '$file'.");
throw new RuntimeException("Cannot open file '$file'.");
}
$count = 0;
@@ -726,7 +726,7 @@ class DibiConnection extends DibiObject
*/
public function __wakeup()
{
throw new NotSupportedException('You cannot serialize or unserialize ' . $this->getClass() . ' instances.');
throw new DibiNotSupportedException('You cannot serialize or unserialize ' . $this->getClass() . ' instances.');
}
@@ -736,7 +736,7 @@ class DibiConnection extends DibiObject
*/
public function __sleep()
{
throw new NotSupportedException('You cannot serialize or unserialize ' . $this->getClass() . ' instances.');
throw new DibiNotSupportedException('You cannot serialize or unserialize ' . $this->getClass() . ' instances.');
}
}

View File

@@ -325,7 +325,7 @@ class DibiTableInfo extends DibiObject
*/
protected function initForeignKeys()
{
throw new NotImplementedException;
throw new DibiNotImplementedException;
}
}

View File

@@ -13,14 +13,11 @@
if (!defined('NETTE')) {
class NotImplementedException extends LogicException {}
class NotSupportedException extends LogicException {}
class MemberAccessException extends LogicException {}
class InvalidStateException extends RuntimeException {}
class IOException extends RuntimeException {}
class FileNotFoundException extends IOException {}
}
class DibiNotImplementedException extends LogicException
{}
class DibiNotSupportedException extends LogicException
{}

View File

@@ -87,14 +87,14 @@ abstract class DibiObject
* @param string method name
* @param array arguments
* @return mixed
* @throws \MemberAccessException
* @throws \LogicException
*/
public function __call($name, $args)
{
$class = get_class($this);
if ($name === '') {
throw new MemberAccessException("Call to class '$class' method without name.");
throw new LogicException("Call to class '$class' method without name.");
}
// event functionality
@@ -122,7 +122,7 @@ abstract class DibiObject
return call_user_func_array($cb, $args);
}
throw new MemberAccessException("Call to undefined method $class::$name().");
throw new LogicException("Call to undefined method $class::$name().");
}
@@ -132,12 +132,12 @@ abstract class DibiObject
* @param string method name (in lower case!)
* @param array arguments
* @return mixed
* @throws \MemberAccessException
* @throws \LogicException
*/
public static function __callStatic($name, $args)
{
$class = get_called_class();
throw new MemberAccessException("Call to undefined static method $class::$name().");
throw new LogicException("Call to undefined static method $class::$name().");
}
@@ -208,14 +208,14 @@ abstract class DibiObject
* Returns property value. Do not call directly.
* @param string property name
* @return mixed property value
* @throws \MemberAccessException if the property is not defined.
* @throws \LogicException if the property is not defined.
*/
public function &__get($name)
{
$class = get_class($this);
if ($name === '') {
throw new MemberAccessException("Cannot read a class '$class' property without name.");
throw new LogicException("Cannot read a class '$class' property without name.");
}
// property getter support
@@ -236,7 +236,7 @@ abstract class DibiObject
}
$name = func_get_arg(0);
throw new MemberAccessException("Cannot read an undeclared property $class::\$$name.");
throw new LogicException("Cannot read an undeclared property $class::\$$name.");
}
@@ -246,14 +246,14 @@ abstract class DibiObject
* @param string property name
* @param mixed property value
* @return void
* @throws \MemberAccessException if the property is not defined or is read-only
* @throws \LogicException if the property is not defined or is read-only
*/
public function __set($name, $value)
{
$class = get_class($this);
if ($name === '') {
throw new MemberAccessException("Cannot assign to a class '$class' property without name.");
throw new LogicException("Cannot assign to a class '$class' property without name.");
}
// property setter support
@@ -266,12 +266,12 @@ abstract class DibiObject
} else {
$name = func_get_arg(0);
throw new MemberAccessException("Cannot assign to a read-only property $class::\$$name.");
throw new LogicException("Cannot assign to a read-only property $class::\$$name.");
}
}
$name = func_get_arg(0);
throw new MemberAccessException("Cannot assign to an undeclared property $class::\$$name.");
throw new LogicException("Cannot assign to an undeclared property $class::\$$name.");
}
@@ -293,12 +293,12 @@ abstract class DibiObject
* Access to undeclared property.
* @param string property name
* @return void
* @throws \MemberAccessException
* @throws \LogicException
*/
public function __unset($name)
{
$class = get_class($this);
throw new MemberAccessException("Cannot unset the property $class::\$$name.");
throw new LogicException("Cannot unset the property $class::\$$name.");
}

View File

@@ -107,12 +107,12 @@ class DibiResult extends DibiObject implements IDataSource
/**
* Safe access to property $driver.
* @return IDibiResultDriver
* @throws InvalidStateException
* @throws RuntimeException
*/
private function getDriver()
{
if ($this->driver === NULL) {
throw new InvalidStateException('Result-set was released from memory.');
throw new RuntimeException('Result-set was released from memory.');
}
return $this->driver;