Commit f83fd8e9 authored by jwage's avatar jwage

[2.0] Updating exceptions to use methods so that we can later provide better exception messages

parent b17ad38e
...@@ -61,9 +61,15 @@ class DoctrineException extends \Exception ...@@ -61,9 +61,15 @@ class DoctrineException extends \Exception
* @param string $class Class name * @param string $class Class name
* @throws DoctrineException * @throws DoctrineException
*/ */
public static function notImplemented($method, $class) public static function notImplemented($method = null, $class = null)
{ {
return new self("The method '$method' is not implemented in class '$class'."); if ($method && $class) {
return new self("The method '$method' is not implemented in class '$class'.");
} else if ($method && ! $class) {
return new self($method);
} else {
return new self('Functionality is not implemented.');
}
} }
/** /**
......
...@@ -103,7 +103,7 @@ abstract class AbstractPlatform ...@@ -103,7 +103,7 @@ abstract class AbstractPlatform
*/ */
public function getRegexpExpression() public function getRegexpExpression()
{ {
throw DoctrineException::updateMe('Regular expression operator is not supported by this database driver.'); throw DoctrineException::regularExpressionOperatorNotSupported($this);
} }
/** /**
...@@ -374,7 +374,7 @@ abstract class AbstractPlatform ...@@ -374,7 +374,7 @@ abstract class AbstractPlatform
$values = $this->getIdentifiers($values); $values = $this->getIdentifiers($values);
if (count($values) == 0) { if (count($values) == 0) {
throw DoctrineException::updateMe('Values array for IN operator should not be empty.'); throw DoctrineException::valuesArrayForInOperatorInvalid();
} }
return $column . ' IN (' . implode(', ', $values) . ')'; return $column . ' IN (' . implode(', ', $values) . ')';
} }
...@@ -532,7 +532,7 @@ abstract class AbstractPlatform ...@@ -532,7 +532,7 @@ abstract class AbstractPlatform
*/ */
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1) public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
{ {
throw DoctrineException::updateMe('Create sequence not supported by this driver.'); throw DoctrineException::createSequenceNotSupported($this);
} }
/** /**
...@@ -586,7 +586,7 @@ abstract class AbstractPlatform ...@@ -586,7 +586,7 @@ abstract class AbstractPlatform
public function getCreateIndexSql($table, $name, array $definition) public function getCreateIndexSql($table, $name, array $definition)
{ {
if ( ! isset($definition['fields'])) { if ( ! isset($definition['fields'])) {
throw DoctrineException::updateMe('You must specify an array of fields to create the index for'); throw DoctrineException::indexFieldsArrayRequired();
} }
$type = ''; $type = '';
...@@ -596,7 +596,7 @@ abstract class AbstractPlatform ...@@ -596,7 +596,7 @@ abstract class AbstractPlatform
$type = strtoupper($definition['type']) . ' '; $type = strtoupper($definition['type']) . ' ';
break; break;
default: default:
throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); throw DoctrineException::unknownIndexType($definition['type']);
} }
} }
...@@ -652,7 +652,7 @@ abstract class AbstractPlatform ...@@ -652,7 +652,7 @@ abstract class AbstractPlatform
*/ */
public function getAlterTableSql($name, array $changes, $check = false) public function getAlterTableSql($name, array $changes, $check = false)
{ {
throw DoctrineException::updateMe('Alter table not supported by this driver.'); throw DoctrineException::alterTableNotSupported($this);
} }
/** /**
...@@ -837,12 +837,12 @@ abstract class AbstractPlatform ...@@ -837,12 +837,12 @@ abstract class AbstractPlatform
if (strtolower($definition['type']) == 'unique') { if (strtolower($definition['type']) == 'unique') {
$type = strtoupper($definition['type']) . ' '; $type = strtoupper($definition['type']) . ' ';
} else { } else {
throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); throw DoctrineException::unknownIndexType($definition['type']);
} }
} }
if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) { if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) {
throw DoctrineException::updateMe('No index columns given.'); throw DoctrineException::indexFieldsArrayRequired();
} }
$query = $type . 'INDEX ' . $name; $query = $type . 'INDEX ' . $name;
...@@ -898,7 +898,7 @@ abstract class AbstractPlatform ...@@ -898,7 +898,7 @@ abstract class AbstractPlatform
*/ */
public function getShowDatabasesSql() public function getShowDatabasesSql()
{ {
throw DoctrineException::updateMe('Show databases not supported by this driver.'); throw DoctrineException::showDatabasesNotSupported($this);
} }
/** /**
...@@ -990,7 +990,7 @@ abstract class AbstractPlatform ...@@ -990,7 +990,7 @@ abstract class AbstractPlatform
return $upper; return $upper;
break; break;
default: default:
throw DoctrineException::updateMe('Unknown foreign key referential action \'' . $upper . '\' given.'); throw DoctrineException::unknownForeignKeyReferentialAction($upper);
} }
} }
...@@ -1010,13 +1010,13 @@ abstract class AbstractPlatform ...@@ -1010,13 +1010,13 @@ abstract class AbstractPlatform
$sql .= 'FOREIGN KEY ('; $sql .= 'FOREIGN KEY (';
if ( ! isset($definition['local'])) { if ( ! isset($definition['local'])) {
throw DoctrineException::updateMe('Local reference field missing from definition.'); throw DoctrineException::localReferenceFieldMissing();
} }
if ( ! isset($definition['foreign'])) { if ( ! isset($definition['foreign'])) {
throw DoctrineException::updateMe('Foreign reference field missing from definition.'); throw DoctrineException::foreignReferenceFieldMissing();
} }
if ( ! isset($definition['foreignTable'])) { if ( ! isset($definition['foreignTable'])) {
throw DoctrineException::updateMe('Foreign reference table missing from definition.'); throw DoctrineException::foreignReferenceTableMissing();
} }
if ( ! is_array($definition['local'])) { if ( ! is_array($definition['local'])) {
...@@ -1091,7 +1091,7 @@ abstract class AbstractPlatform ...@@ -1091,7 +1091,7 @@ abstract class AbstractPlatform
*/ */
public function getMatchPatternExpression($pattern, $operator = null, $field = null) public function getMatchPatternExpression($pattern, $operator = null, $field = null)
{ {
throw DoctrineException::updateMe("Method not implemented."); throw DoctrineException::matchPatternExpressionNotSupported($this);
} }
/** /**
...@@ -1221,88 +1221,88 @@ abstract class AbstractPlatform ...@@ -1221,88 +1221,88 @@ abstract class AbstractPlatform
case Connection::TRANSACTION_SERIALIZABLE: case Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE'; return 'SERIALIZABLE';
default: default:
throw DoctrineException::updateMe('isolation level is not supported: ' . $isolation); throw DoctrineException::isolationLevelNotSupported($isolation);
} }
} }
public function getListDatabasesSql() public function getListDatabasesSql()
{ {
throw DoctrineException::updateMe('List databases not supported by this driver.'); throw DoctrineException::listDatabasesNotSupported($this);
} }
public function getListFunctionsSql() public function getListFunctionsSql()
{ {
throw DoctrineException::updateMe('List functions not supported by this driver.'); throw DoctrineException::listFunctionsNotSupported($this);
} }
public function getListTriggersSql($table = null) public function getListTriggersSql($table = null)
{ {
throw DoctrineException::updateMe('List triggers not supported by this driver.'); throw DoctrineException::listTriggersNotSupported($this);
} }
public function getListSequencesSql($database) public function getListSequencesSql($database)
{ {
throw DoctrineException::updateMe('List sequences not supported by this driver.'); throw DoctrineException::listSequencesNotSupported($this);
} }
public function getListTableConstraintsSql($table) public function getListTableConstraintsSql($table)
{ {
throw DoctrineException::updateMe('List table constraints not supported by this driver.'); throw DoctrineException::listTableConstraintsNotSupported($this);
} }
public function getListTableColumnsSql($table) public function getListTableColumnsSql($table)
{ {
throw DoctrineException::updateMe('List table columns not supported by this driver.'); throw DoctrineException::listTableColumnsNotSupported($this);
} }
public function getListTablesSql() public function getListTablesSql()
{ {
throw DoctrineException::updateMe('List tables not supported by this driver.'); throw DoctrineException::listTablesNotSupported($this);
} }
public function getListUsersSql() public function getListUsersSql()
{ {
throw DoctrineException::updateMe('List users not supported by this driver.'); throw DoctrineException::listUsersNotSupported($this);
} }
public function getListViewsSql() public function getListViewsSql()
{ {
throw DoctrineException::updateMe('List views not supported by this driver.'); throw DoctrineException::listViewsNotSupported($this);
} }
public function getListTableIndexesSql($table) public function getListTableIndexesSql($table)
{ {
throw DoctrineException::updateMe('List table indexes not supported by this driver.'); throw DoctrineException::listTableIndexesNotSupported($this);
} }
public function getListTableForeignKeysSql($table) public function getListTableForeignKeysSql($table)
{ {
throw DoctrineException::updateMe('List table foreign keys not supported by this driver.'); throw DoctrineException::listTableForeignKeysNotSupported($this);
} }
public function getCreateViewSql($name, $sql) public function getCreateViewSql($name, $sql)
{ {
throw DoctrineException::updateMe('Create view not supported by this driver'); throw DoctrineException::createViewNotSupported($this);
} }
public function getDropViewSql($name) public function getDropViewSql($name)
{ {
throw DoctrineException::updateMe('Drop view not supported by this driver'); throw DoctrineException::dropViewNotSupported($this);
} }
public function getDropSequenceSql($sequenceName) public function getDropSequenceSql($sequenceName)
{ {
throw DoctrineException::updateMe('Drop sequence not supported by this driver.'); throw DoctrineException::dropSequenceNotSupported($this);
} }
public function getSequenceNextValSql($sequenceName) public function getSequenceNextValSql($sequenceName)
{ {
throw DoctrineException::updateMe('Sequences not supported by this driver.'); throw DoctrineException::sequenceNotSupported($this);
} }
public function getCreateDatabaseSql($database) public function getCreateDatabaseSql($database)
{ {
throw DoctrineException::updateMe('Create database not supported by this driver.'); throw DoctrineException::createDatabaseNotSupported($this);
} }
/** /**
...@@ -1312,7 +1312,7 @@ abstract class AbstractPlatform ...@@ -1312,7 +1312,7 @@ abstract class AbstractPlatform
*/ */
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
throw DoctrineException::updateMe('Set transaction isolation not supported by this platform.'); throw DoctrineException::setTransactionIsolationLevelNotSupported($this);
} }
/** /**
...@@ -1325,7 +1325,7 @@ abstract class AbstractPlatform ...@@ -1325,7 +1325,7 @@ abstract class AbstractPlatform
*/ */
public function getCharsetFieldDeclaration($charset) public function getCharsetFieldDeclaration($charset)
{ {
throw DoctrineException::updateMe('Get charset field declaration not supported by this platform.'); throw DoctrineException::getCharsetFieldDeclarationNotSupported($this);
} }
/** /**
...@@ -1337,7 +1337,7 @@ abstract class AbstractPlatform ...@@ -1337,7 +1337,7 @@ abstract class AbstractPlatform
*/ */
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration) public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
{ {
throw DoctrineException::updateMe('Get datetime type declaration not supported by this platform.'); throw DoctrineException::getDateTimeTypeDeclarationNotSupported($this);
} }
/** /**
......
...@@ -59,7 +59,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -59,7 +59,7 @@ class MsSqlPlatform extends AbstractPlatform
$offset = intval($offset); $offset = intval($offset);
if ($offset < 0) { if ($offset < 0) {
throw \Doctrine\Common\DoctrineException::updateMe("LIMIT argument offset=$offset is not valid"); throw \Doctrine\Common\DoctrineException::limitOffsetInvalid($offset);
} }
$orderby = stristr($query, 'ORDER BY'); $orderby = stristr($query, 'ORDER BY');
...@@ -99,7 +99,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -99,7 +99,7 @@ class MsSqlPlatform extends AbstractPlatform
case 'name': case 'name':
break; break;
default: default:
throw \Doctrine\Common\DoctrineException::updateMe('alterTable: change type "' . $changeName . '" not yet supported'); throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName);
} }
} }
......
...@@ -104,7 +104,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -104,7 +104,7 @@ class MySqlPlatform extends AbstractPlatform
$match = $field.'LIKE BINARY '; $match = $field.'LIKE BINARY ';
break; break;
default: default:
throw DoctrineException::updateMe('not a supported operator type:'. $operator); throw DoctrineException::operatorNotSupported($operator);
} }
} }
$match.= "'"; $match.= "'";
...@@ -400,10 +400,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -400,10 +400,10 @@ class MySqlPlatform extends AbstractPlatform
public function getCreateTableSql($name, array $fields, array $options = array()) public function getCreateTableSql($name, array $fields, array $options = array())
{ {
if ( ! $name) { if ( ! $name) {
throw DoctrineException::updateMe('no valid table name specified'); throw DoctrineException::missingTableName();
} }
if (empty($fields)) { if (empty($fields)) {
throw DoctrineException::updateMe('no fields specified for table "'.$name.'"'); throw DoctrineException::missingFieldsArrayForTable($name);
} }
$queryFields = $this->getColumnDeclarationListSql($fields); $queryFields = $this->getColumnDeclarationListSql($fields);
...@@ -591,7 +591,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -591,7 +591,7 @@ class MySqlPlatform extends AbstractPlatform
public function getAlterTableSql($name, array $changes, $check = false) public function getAlterTableSql($name, array $changes, $check = false)
{ {
if ( ! $name) { if ( ! $name) {
throw DoctrineException::updateMe('no valid table name specified'); throw DoctrineException::missingTableName();
} }
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
...@@ -603,7 +603,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -603,7 +603,7 @@ class MySqlPlatform extends AbstractPlatform
case 'name': case 'name':
break; break;
default: default:
throw DoctrineException::updateMe('change type "' . $changeName . '" not yet supported'); throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName);
} }
} }
...@@ -749,12 +749,12 @@ class MySqlPlatform extends AbstractPlatform ...@@ -749,12 +749,12 @@ class MySqlPlatform extends AbstractPlatform
$type = strtoupper($definition['type']) . ' '; $type = strtoupper($definition['type']) . ' ';
break; break;
default: default:
throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); throw DoctrineException::invalidIndexType($definition['type']);
} }
} }
if ( ! isset($definition['fields'])) { if ( ! isset($definition['fields'])) {
throw DoctrineException::updateMe('No index columns given.'); throw DoctrineException::indexFieldsArrayRequired();
} }
if ( ! is_array($definition['fields'])) { if ( ! is_array($definition['fields'])) {
$definition['fields'] = array($definition['fields']); $definition['fields'] = array($definition['fields']);
...@@ -794,7 +794,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -794,7 +794,7 @@ class MySqlPlatform extends AbstractPlatform
$fieldString .= ' ' . $sort; $fieldString .= ' ' . $sort;
break; break;
default: default:
throw DoctrineException::updateMe('Unknown index sorting option given.'); throw DoctrineException::unknownIndexSortingOption($sort);
} }
} }
} else { } else {
......
...@@ -389,7 +389,7 @@ END;'; ...@@ -389,7 +389,7 @@ END;';
public function getAlterTableSql($name, array $changes, $check = false) public function getAlterTableSql($name, array $changes, $check = false)
{ {
if ( ! $name) { if ( ! $name) {
throw DoctrineException::updateMe('no valid table name specified'); throw DoctrineException::missingTableName();
} }
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
switch ($changeName) { switch ($changeName) {
...@@ -400,7 +400,7 @@ END;'; ...@@ -400,7 +400,7 @@ END;';
case 'rename': case 'rename':
break; break;
default: default:
throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '" not yet supported'); throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName);
} }
} }
......
...@@ -194,7 +194,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -194,7 +194,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$match = $field.'LIKE '; $match = $field.'LIKE ';
break; break;
default: default:
throw DoctrineException::updateMe('not a supported operator type:'. $operator); throw DoctrineException::operatorNotSupported($operator);
} }
} }
$match.= "'"; $match.= "'";
...@@ -506,7 +506,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -506,7 +506,7 @@ class PostgreSqlPlatform extends AbstractPlatform
case 'rename': case 'rename':
break; break;
default: default:
throw DoctrineException::updateMe('change type "' . $changeName . '\" not yet supported'); throw DoctrineException::alterTableChangeNotSupported($changeName);
} }
} }
...@@ -536,7 +536,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -536,7 +536,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$serverInfo = $this->getServerVersion(); $serverInfo = $this->getServerVersion();
if (is_array($serverInfo) && $serverInfo['major'] < 8) { if (is_array($serverInfo) && $serverInfo['major'] < 8) {
throw DoctrineException::updateMe('changing column type for "'.$field['type'].'\" requires PostgreSQL 8.0 or above'); throw DoctrineException::changeColumnRequiresPostgreSQL8OrAbove($field['type']);
} }
$query = 'ALTER ' . $fieldName . ' TYPE ' . $this->getTypeDeclarationSql($field['definition']); $query = 'ALTER ' . $fieldName . ' TYPE ' . $this->getTypeDeclarationSql($field['definition']);
$sql[] = 'ALTER TABLE ' . $name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $name . ' ' . $query;
......
...@@ -160,7 +160,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager ...@@ -160,7 +160,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager
case 'rename': case 'rename':
case 'change': case 'change':
default: default:
throw \Doctrine\Common\DoctrineException::updateMe('alterTable: change type "' . $changeName . '" not yet supported'); throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName);
} }
} }
......
...@@ -318,7 +318,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -318,7 +318,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$res = $this->_conn->exec($query); $res = $this->_conn->exec($query);
} catch(Doctrine\DBAL\ConnectionException $e) { } catch(Doctrine\DBAL\ConnectionException $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table'); throw \Doctrine\Common\DoctrineException::createSequenceFailed($query);
} }
if ($start == 1) { if ($start == 1) {
...@@ -334,7 +334,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -334,7 +334,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
try { try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName); $res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch (\Exception $e) { } catch (\Exception $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table'); throw \Doctrine\Common\DoctrineException::couldNotDropSequenceTable($sequenceName);
} }
return $res; return $res;
......
...@@ -122,7 +122,7 @@ abstract class Type ...@@ -122,7 +122,7 @@ abstract class Type
{ {
if ( ! isset(self::$_typeObjects[$name])) { if ( ! isset(self::$_typeObjects[$name])) {
if ( ! isset(self::$_typesMap[$name])) { if ( ! isset(self::$_typesMap[$name])) {
throw DoctrineException::updateMe("Unknown type: $name"); throw DoctrineException::unknownColumnType($name);
} }
self::$_typeObjects[$name] = new self::$_typesMap[$name](); self::$_typeObjects[$name] = new self::$_typesMap[$name]();
......
...@@ -207,9 +207,7 @@ abstract class AbstractQuery ...@@ -207,9 +207,7 @@ abstract class AbstractQuery
public function setResultCache($resultCache = null) public function setResultCache($resultCache = null)
{ {
if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\Common\Cache\Cache)) { if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\Common\Cache\Cache)) {
throw DoctrineException::updateMe( throw DoctrineException::invalidResultCacheObject($resultCache);
'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.'
);
} }
$this->_resultCache = $resultCache; $this->_resultCache = $resultCache;
return $this; return $this;
......
...@@ -357,7 +357,7 @@ class EntityManager ...@@ -357,7 +357,7 @@ class EntityManager
$this->_unitOfWork->clear(); $this->_unitOfWork->clear();
} else { } else {
//TODO //TODO
throw DoctrineException::notImplemented(); throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__);
} }
} }
...@@ -454,7 +454,7 @@ class EntityManager ...@@ -454,7 +454,7 @@ class EntityManager
*/ */
public function copy($entity, $deep = false) public function copy($entity, $deep = false)
{ {
throw DoctrineException::notImplemented(); throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__);
} }
/** /**
...@@ -557,7 +557,7 @@ class EntityManager ...@@ -557,7 +557,7 @@ class EntityManager
$this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this); $this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this);
break; break;
default: default:
throw DoctrineException::updateMe("No hydrator found for hydration mode '$hydrationMode'."); throw DoctrineException::invalidHydrationMode($hydrationMode);
} }
} }
return $this->_hydrators[$hydrationMode]; return $this->_hydrators[$hydrationMode];
...@@ -591,10 +591,10 @@ class EntityManager ...@@ -591,10 +591,10 @@ class EntityManager
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager())); $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager()));
} else if ($conn instanceof Connection) { } else if ($conn instanceof Connection) {
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw DoctrineException::updateMe("Cannot use different EventManagers for EntityManager and Connection."); throw DoctrineException::invalidEventManager('Cannot use different EventManagers for EntityManager and Connection.');
} }
} else { } else {
throw DoctrineException::updateMe("Invalid parameter '$conn'."); throw DoctrineException::invalidParameter($conn);
} }
return new EntityManager($conn, $config, $conn->getEventManager()); return new EntityManager($conn, $config, $conn->getEventManager());
......
...@@ -138,7 +138,7 @@ class EntityRepository ...@@ -138,7 +138,7 @@ class EntityRepository
} }
if ( ! isset($arguments[0])) { if ( ! isset($arguments[0])) {
throw DoctrineException::updateMe('You must specify the value to findBy.'); throw DoctrineException::findByNameRequired();
} }
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
...@@ -146,7 +146,7 @@ class EntityRepository ...@@ -146,7 +146,7 @@ class EntityRepository
if ($this->_class->hasField($fieldName)) { if ($this->_class->hasField($fieldName)) {
return $this->$method(array($fieldName => $arguments[0])); return $this->$method(array($fieldName => $arguments[0]));
} else { } else {
throw \Doctrine\Common\DoctrineException::updateMe('Cannot find by: ' . $by . '. Invalid field.'); throw \Doctrine\Common\DoctrineException::invalidFindBy($by);
} }
} }
} }
\ No newline at end of file
...@@ -62,7 +62,7 @@ class Assigned extends AbstractIdGenerator ...@@ -62,7 +62,7 @@ class Assigned extends AbstractIdGenerator
} }
if ( ! $identifier) { if ( ! $identifier) {
throw DoctrineException::updateMe("Entity of type '" . get_class($entity) . "' is missing an assigned ID."); throw DoctrineException::entityMissingAssignedId($entity);
} }
return $identifier; return $identifier;
......
...@@ -14,6 +14,6 @@ class TableGenerator extends AbstractIdGenerator ...@@ -14,6 +14,6 @@ class TableGenerator extends AbstractIdGenerator
{ {
public function generate(EntityManager $em, $entity) public function generate(EntityManager $em, $entity)
{ {
throw \Doctrine\Common\DoctrineException::updateMe("Not implemented"); throw \Doctrine\Common\DoctrineException::notImplemented(__CLASS__ . '::' . __FUNCTION__);
} }
} }
\ No newline at end of file
...@@ -304,6 +304,6 @@ abstract class AbstractHydrator ...@@ -304,6 +304,6 @@ abstract class AbstractHydrator
} }
} }
throw DoctrineException::updateMe("No owner found for field '$fieldName' during hydration."); throw DoctrineException::noOwnerFoundForField($class, $fieldName);
} }
} }
...@@ -537,7 +537,7 @@ final class ClassMetadata ...@@ -537,7 +537,7 @@ final class ClassMetadata
public function getSingleIdReflectionProperty() public function getSingleIdReflectionProperty()
{ {
if ($this->isIdentifierComposite) { if ($this->isIdentifierComposite) {
throw DoctrineException::updateMe("getSingleIdReflectionProperty called on entity with composite key."); throw DoctrineException::singleIdNotAllowedOnCompositePrimaryKey();
} }
return $this->reflFields[$this->identifier[0]]; return $this->reflFields[$this->identifier[0]];
} }
...@@ -830,8 +830,7 @@ final class ClassMetadata ...@@ -830,8 +830,7 @@ final class ClassMetadata
public function getSingleIdentifierFieldName() public function getSingleIdentifierFieldName()
{ {
if ($this->isIdentifierComposite) { if ($this->isIdentifierComposite) {
throw DoctrineException::updateMe("Calling getSingleIdentifierFieldName " throw DoctrineException::singleIdNotAllowedOnCompositePrimaryKey();
. "on a class that uses a composite identifier is not allowed.");
} }
return $this->identifier[0]; return $this->identifier[0];
} }
......
...@@ -67,7 +67,7 @@ class AnnotationDriver implements Driver ...@@ -67,7 +67,7 @@ class AnnotationDriver implements Driver
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) { } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else { } else {
throw DoctrineException::updateMe("$className is no entity or mapped superclass."); throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className);
} }
// Evaluate DoctrineTable annotation // Evaluate DoctrineTable annotation
...@@ -155,7 +155,7 @@ class AnnotationDriver implements Driver ...@@ -155,7 +155,7 @@ class AnnotationDriver implements Driver
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) {
if ($columnAnnot->type == null) { if ($columnAnnot->type == null) {
throw DoctrineException::updateMe("Missing type on property " . $property->getName()); throw DoctrineException::propertyTypeIsRequired($property->getName());
} }
$mapping['type'] = $columnAnnot->type; $mapping['type'] = $columnAnnot->type;
$mapping['length'] = $columnAnnot->length; $mapping['length'] = $columnAnnot->length;
......
...@@ -52,7 +52,7 @@ class XmlDriver extends AbstractFileDriver ...@@ -52,7 +52,7 @@ class XmlDriver extends AbstractFileDriver
} else if ($xmlRoot->getName() == 'mapped-superclass') { } else if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else { } else {
throw DoctrineException::updateMe("$className is no entity or mapped superclass."); throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className);
} }
// Evaluate <entity...> attributes // Evaluate <entity...> attributes
......
...@@ -53,7 +53,7 @@ class YamlDriver extends AbstractFileDriver ...@@ -53,7 +53,7 @@ class YamlDriver extends AbstractFileDriver
} else if ($element['type'] == 'mappedSuperclass') { } else if ($element['type'] == 'mappedSuperclass') {
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else { } else {
throw DoctrineException::updateMe("$className is no entity or mapped superclass."); throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className);
} }
// Evaluate root level properties // Evaluate root level properties
......
...@@ -60,7 +60,7 @@ abstract class Base ...@@ -60,7 +60,7 @@ abstract class Base
$class = get_class($arg); $class = get_class($arg);
if ( ! in_array($class, $this->_allowedClasses)) { if ( ! in_array($class, $this->_allowedClasses)) {
throw \Doctrine\Common\DoctrineException::updateMe("Class '{$class}' is not allowed in " . get_class($this) . " instance."); throw \Doctrine\Common\DoctrineException::classNotAllowed($class, $this);
} }
} }
......
...@@ -421,12 +421,10 @@ class SqlWalker implements TreeWalker ...@@ -421,12 +421,10 @@ class SqlWalker implements TreeWalker
break; break;
case AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION: case AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION:
throw DoctrineException::updateMe("Not yet implemented."); throw DoctrineException::notImplemented();
default: default:
throw DoctrineException::updateMe( throw DoctrineException::invalidPathExpression($pathExpr->type);
"Encountered invalid PathExpression during SQL construction."
);
} }
return $sql; return $sql;
...@@ -753,9 +751,7 @@ class SqlWalker implements TreeWalker ...@@ -753,9 +751,7 @@ class SqlWalker implements TreeWalker
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias); $columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName); $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName);
} else { } else {
throw DoctrineException::updateMe( throw DoctrineException::invalidPathExpression($expr->type);
"Encountered invalid PathExpression during SQL construction."
);
} }
} else if ($expr instanceof AST\AggregateExpression) { } else if ($expr instanceof AST\AggregateExpression) {
if ( ! $selectExpression->fieldIdentificationVariable) { if ( ! $selectExpression->fieldIdentificationVariable) {
......
...@@ -176,9 +176,7 @@ class Cli ...@@ -176,9 +176,7 @@ class Cli
$task->basicHelp(); // Fallback of not-valid task arguments $task->basicHelp(); // Fallback of not-valid task arguments
} }
} else { } else {
throw \Doctrine\Common\DoctrineException::updateMe( throw \Doctrine\Common\DoctrineException::taskDoesNotExist($taskName);
'Unexistent task or attached task class does not exist.'
);
} }
} }
} catch (\Doctrine\Common\DoctrineException $e) { } catch (\Doctrine\Common\DoctrineException $e) {
......
...@@ -580,8 +580,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -580,8 +580,7 @@ class UnitOfWork implements PropertyChangedListener
$this->_entityChangeSets[$oid] = $changeSet; $this->_entityChangeSets[$oid] = $changeSet;
$this->_originalEntityData[$oid] = $data; $this->_originalEntityData[$oid] = $data;
} else if ($state == self::STATE_REMOVED) { } else if ($state == self::STATE_REMOVED) {
throw DoctrineException::updateMe("Removed entity in collection detected during flush." throw DoctrineException::removedEntityInCollectionDetected();
. " Make sure you properly remove deleted entities from collections.");
} }
// MANAGED associated entities are already taken into account // MANAGED associated entities are already taken into account
// during changeset calculation anyway, since they are in the identity map. // during changeset calculation anyway, since they are in the identity map.
...@@ -819,13 +818,13 @@ class UnitOfWork implements PropertyChangedListener ...@@ -819,13 +818,13 @@ class UnitOfWork implements PropertyChangedListener
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if (isset($this->_entityUpdates[$oid])) { if (isset($this->_entityUpdates[$oid])) {
throw DoctrineException::updateMe("Dirty object can't be registered as new."); throw DoctrineException::dirtyObjectCannotBeRegisteredAsNew();
} }
if (isset($this->_entityDeletions[$oid])) { if (isset($this->_entityDeletions[$oid])) {
throw DoctrineException::updateMe("Removed object can't be registered as new."); throw DoctrineException::removedObjectCannotBeRegisteredAsNew();
} }
if (isset($this->_entityInsertions[$oid])) { if (isset($this->_entityInsertions[$oid])) {
throw DoctrineException::updateMe("Object already registered as new. Can't register twice."); throw DoctrineException::objectAlreadyRegisteredAsNew();
} }
$this->_entityInsertions[$oid] = $entity; $this->_entityInsertions[$oid] = $entity;
...@@ -855,11 +854,10 @@ class UnitOfWork implements PropertyChangedListener ...@@ -855,11 +854,10 @@ class UnitOfWork implements PropertyChangedListener
{ {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if ( ! isset($this->_entityIdentifiers[$oid])) { if ( ! isset($this->_entityIdentifiers[$oid])) {
throw DoctrineException::updateMe("Entity without identity " throw DoctrineException::entityWithoutIdentityCannotBeRegisteredAsDirty();
. "can't be registered as dirty.");
} }
if (isset($this->_entityDeletions[$oid])) { if (isset($this->_entityDeletions[$oid])) {
throw DoctrineException::updateMe("Removed object can't be registered as dirty."); throw DoctrineException::removedObjectCannotBeRegisteredAsDirty();
} }
if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) { if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) {
...@@ -961,8 +959,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -961,8 +959,7 @@ class UnitOfWork implements PropertyChangedListener
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = implode(' ', $this->_entityIdentifiers[spl_object_hash($entity)]); $idHash = implode(' ', $this->_entityIdentifiers[spl_object_hash($entity)]);
if ($idHash === '') { if ($idHash === '') {
throw DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) throw DoctrineException::entityMustHaveIdentifyToBeAddedToIdentityMap($entity);
. "' has no identity and therefore can't be added to the identity map.");
} }
$className = $classMetadata->rootEntityName; $className = $classMetadata->rootEntityName;
if (isset($this->_identityMap[$className][$idHash])) { if (isset($this->_identityMap[$className][$idHash])) {
...@@ -1024,8 +1021,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1024,8 +1021,7 @@ class UnitOfWork implements PropertyChangedListener
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = implode(' ', $this->_entityIdentifiers[$oid]); $idHash = implode(' ', $this->_entityIdentifiers[$oid]);
if ($idHash === '') { if ($idHash === '') {
throw DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) throw DoctrineException::entityMustHaveIdentifyToBeRemovedFromIdentityMap($entity);
. "' has no identity and therefore can't be removed from the identity map.");
} }
$className = $classMetadata->rootEntityName; $className = $classMetadata->rootEntityName;
if (isset($this->_identityMap[$className][$idHash])) { if (isset($this->_identityMap[$className][$idHash])) {
...@@ -1131,8 +1127,9 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1131,8 +1127,9 @@ class UnitOfWork implements PropertyChangedListener
$visited[$oid] = $entity; // Mark visited $visited[$oid] = $entity; // Mark visited
$class = $this->_em->getClassMetadata(get_class($entity)); $class = $this->_em->getClassMetadata(get_class($entity));
switch ($this->getEntityState($entity, self::STATE_NEW)) { $entityState = $this->getEntityState($entity, self::STATE_NEW);
switch ($entityState) {
case self::STATE_MANAGED: case self::STATE_MANAGED:
// Nothing to do, except if policy is "deferred explicit" // Nothing to do, except if policy is "deferred explicit"
if ($class->isChangeTrackingDeferredExplicit()) { if ($class->isChangeTrackingDeferredExplicit()) {
...@@ -1162,7 +1159,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1162,7 +1159,7 @@ class UnitOfWork implements PropertyChangedListener
$this->scheduleForInsert($entity); $this->scheduleForInsert($entity);
break; break;
case self::STATE_DETACHED: case self::STATE_DETACHED:
throw DoctrineException::updateMe("Behavior of save() for a detached entity " throw DoctrineException::notImplemented("Behavior of save() for a detached entity "
. "is not yet defined."); . "is not yet defined.");
case self::STATE_REMOVED: case self::STATE_REMOVED:
// Entity becomes managed again // Entity becomes managed again
...@@ -1174,7 +1171,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1174,7 +1171,7 @@ class UnitOfWork implements PropertyChangedListener
} }
break; break;
default: default:
throw DoctrineException::updateMe("Encountered invalid entity state."); throw DoctrineException::invalidEntityState($entityState);
} }
$this->_cascadePersist($entity, $visited); $this->_cascadePersist($entity, $visited);
...@@ -1211,7 +1208,8 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1211,7 +1208,8 @@ class UnitOfWork implements PropertyChangedListener
$visited[$oid] = $entity; // mark visited $visited[$oid] = $entity; // mark visited
$class = $this->_em->getClassMetadata(get_class($entity)); $class = $this->_em->getClassMetadata(get_class($entity));
switch ($this->getEntityState($entity)) { $entityState = $this->getEntityState($entity);
switch ($entityState) {
case self::STATE_NEW: case self::STATE_NEW:
case self::STATE_REMOVED: case self::STATE_REMOVED:
// nothing to do // nothing to do
...@@ -1226,11 +1224,11 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1226,11 +1224,11 @@ class UnitOfWork implements PropertyChangedListener
$this->scheduleForDelete($entity); $this->scheduleForDelete($entity);
break; break;
case self::STATE_DETACHED: case self::STATE_DETACHED:
throw new \InvalidArgumentException("A detached entity can not be removed."); throw DoctrineException::detachedEntityCannotBeRemoved();
default: default:
throw DoctrineException::updateMe("Encountered invalid entity state."); throw DoctrineException::invalidEntityState($entityState);
} }
$this->_cascadeRemove($entity, $visited); $this->_cascadeRemove($entity, $visited);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment