From f83fd8e95028058cdb502ebea4958403b9ba67f4 Mon Sep 17 00:00:00 2001 From: jwage Date: Wed, 26 Aug 2009 22:03:39 +0000 Subject: [PATCH] [2.0] Updating exceptions to use methods so that we can later provide better exception messages --- lib/Doctrine/Common/DoctrineException.php | 10 ++- .../DBAL/Platforms/AbstractPlatform.php | 68 +++++++++---------- lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php | 4 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 16 ++--- .../DBAL/Platforms/OraclePlatform.php | 4 +- .../DBAL/Platforms/PostgreSqlPlatform.php | 6 +- .../DBAL/Schema/MsSqlSchemaManager.php | 2 +- .../DBAL/Schema/MySqlSchemaManager.php | 4 +- lib/Doctrine/DBAL/Types/Type.php | 2 +- lib/Doctrine/ORM/AbstractQuery.php | 4 +- lib/Doctrine/ORM/EntityManager.php | 10 +-- lib/Doctrine/ORM/EntityRepository.php | 4 +- lib/Doctrine/ORM/Id/Assigned.php | 2 +- lib/Doctrine/ORM/Id/TableGenerator.php | 2 +- .../Internal/Hydration/AbstractHydrator.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 5 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- .../ORM/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ORM/Query/Expr/Base.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 10 +-- lib/Doctrine/ORM/Tools/Cli.php | 4 +- lib/Doctrine/ORM/UnitOfWork.php | 38 +++++------ 23 files changed, 101 insertions(+), 106 deletions(-) diff --git a/lib/Doctrine/Common/DoctrineException.php b/lib/Doctrine/Common/DoctrineException.php index ccb4697b2..a68907a60 100644 --- a/lib/Doctrine/Common/DoctrineException.php +++ b/lib/Doctrine/Common/DoctrineException.php @@ -61,9 +61,15 @@ class DoctrineException extends \Exception * @param string $class Class name * @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.'); + } } /** diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 7c10d8ed7..1e37ad2cb 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -103,7 +103,7 @@ abstract class AbstractPlatform */ 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 $values = $this->getIdentifiers($values); if (count($values) == 0) { - throw DoctrineException::updateMe('Values array for IN operator should not be empty.'); + throw DoctrineException::valuesArrayForInOperatorInvalid(); } return $column . ' IN (' . implode(', ', $values) . ')'; } @@ -532,7 +532,7 @@ abstract class AbstractPlatform */ 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 public function getCreateIndexSql($table, $name, array $definition) { if ( ! isset($definition['fields'])) { - throw DoctrineException::updateMe('You must specify an array of fields to create the index for'); + throw DoctrineException::indexFieldsArrayRequired(); } $type = ''; @@ -596,7 +596,7 @@ abstract class AbstractPlatform $type = strtoupper($definition['type']) . ' '; break; default: - throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); + throw DoctrineException::unknownIndexType($definition['type']); } } @@ -652,7 +652,7 @@ abstract class AbstractPlatform */ 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 if (strtolower($definition['type']) == 'unique') { $type = strtoupper($definition['type']) . ' '; } else { - throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); + throw DoctrineException::unknownIndexType($definition['type']); } } if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) { - throw DoctrineException::updateMe('No index columns given.'); + throw DoctrineException::indexFieldsArrayRequired(); } $query = $type . 'INDEX ' . $name; @@ -898,7 +898,7 @@ abstract class AbstractPlatform */ public function getShowDatabasesSql() { - throw DoctrineException::updateMe('Show databases not supported by this driver.'); + throw DoctrineException::showDatabasesNotSupported($this); } /** @@ -990,7 +990,7 @@ abstract class AbstractPlatform return $upper; break; default: - throw DoctrineException::updateMe('Unknown foreign key referential action \'' . $upper . '\' given.'); + throw DoctrineException::unknownForeignKeyReferentialAction($upper); } } @@ -1010,13 +1010,13 @@ abstract class AbstractPlatform $sql .= 'FOREIGN KEY ('; if ( ! isset($definition['local'])) { - throw DoctrineException::updateMe('Local reference field missing from definition.'); + throw DoctrineException::localReferenceFieldMissing(); } if ( ! isset($definition['foreign'])) { - throw DoctrineException::updateMe('Foreign reference field missing from definition.'); + throw DoctrineException::foreignReferenceFieldMissing(); } if ( ! isset($definition['foreignTable'])) { - throw DoctrineException::updateMe('Foreign reference table missing from definition.'); + throw DoctrineException::foreignReferenceTableMissing(); } if ( ! is_array($definition['local'])) { @@ -1091,7 +1091,7 @@ abstract class AbstractPlatform */ 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 case Connection::TRANSACTION_SERIALIZABLE: return 'SERIALIZABLE'; default: - throw DoctrineException::updateMe('isolation level is not supported: ' . $isolation); + throw DoctrineException::isolationLevelNotSupported($isolation); } } public function getListDatabasesSql() { - throw DoctrineException::updateMe('List databases not supported by this driver.'); + throw DoctrineException::listDatabasesNotSupported($this); } public function getListFunctionsSql() { - throw DoctrineException::updateMe('List functions not supported by this driver.'); + throw DoctrineException::listFunctionsNotSupported($this); } public function getListTriggersSql($table = null) { - throw DoctrineException::updateMe('List triggers not supported by this driver.'); + throw DoctrineException::listTriggersNotSupported($this); } public function getListSequencesSql($database) { - throw DoctrineException::updateMe('List sequences not supported by this driver.'); + throw DoctrineException::listSequencesNotSupported($this); } public function getListTableConstraintsSql($table) { - throw DoctrineException::updateMe('List table constraints not supported by this driver.'); + throw DoctrineException::listTableConstraintsNotSupported($this); } public function getListTableColumnsSql($table) { - throw DoctrineException::updateMe('List table columns not supported by this driver.'); + throw DoctrineException::listTableColumnsNotSupported($this); } public function getListTablesSql() { - throw DoctrineException::updateMe('List tables not supported by this driver.'); + throw DoctrineException::listTablesNotSupported($this); } public function getListUsersSql() { - throw DoctrineException::updateMe('List users not supported by this driver.'); + throw DoctrineException::listUsersNotSupported($this); } public function getListViewsSql() { - throw DoctrineException::updateMe('List views not supported by this driver.'); + throw DoctrineException::listViewsNotSupported($this); } public function getListTableIndexesSql($table) { - throw DoctrineException::updateMe('List table indexes not supported by this driver.'); + throw DoctrineException::listTableIndexesNotSupported($this); } 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) { - throw DoctrineException::updateMe('Create view not supported by this driver'); + throw DoctrineException::createViewNotSupported($this); } public function getDropViewSql($name) { - throw DoctrineException::updateMe('Drop view not supported by this driver'); + throw DoctrineException::dropViewNotSupported($this); } public function getDropSequenceSql($sequenceName) { - throw DoctrineException::updateMe('Drop sequence not supported by this driver.'); + throw DoctrineException::dropSequenceNotSupported($this); } public function getSequenceNextValSql($sequenceName) { - throw DoctrineException::updateMe('Sequences not supported by this driver.'); + throw DoctrineException::sequenceNotSupported($this); } 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 */ 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 */ 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 */ public function getDateTimeTypeDeclarationSql(array $fieldDeclaration) { - throw DoctrineException::updateMe('Get datetime type declaration not supported by this platform.'); + throw DoctrineException::getDateTimeTypeDeclarationNotSupported($this); } /** diff --git a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php index da6e73c2b..265aa9004 100644 --- a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php @@ -59,7 +59,7 @@ class MsSqlPlatform extends AbstractPlatform $offset = intval($offset); 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'); @@ -99,7 +99,7 @@ class MsSqlPlatform extends AbstractPlatform case 'name': break; default: - throw \Doctrine\Common\DoctrineException::updateMe('alterTable: change type "' . $changeName . '" not yet supported'); + throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName); } } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index a793bc152..6c7836c0e 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -104,7 +104,7 @@ class MySqlPlatform extends AbstractPlatform $match = $field.'LIKE BINARY '; break; default: - throw DoctrineException::updateMe('not a supported operator type:'. $operator); + throw DoctrineException::operatorNotSupported($operator); } } $match.= "'"; @@ -400,10 +400,10 @@ class MySqlPlatform extends AbstractPlatform public function getCreateTableSql($name, array $fields, array $options = array()) { if ( ! $name) { - throw DoctrineException::updateMe('no valid table name specified'); + throw DoctrineException::missingTableName(); } if (empty($fields)) { - throw DoctrineException::updateMe('no fields specified for table "'.$name.'"'); + throw DoctrineException::missingFieldsArrayForTable($name); } $queryFields = $this->getColumnDeclarationListSql($fields); @@ -591,7 +591,7 @@ class MySqlPlatform extends AbstractPlatform public function getAlterTableSql($name, array $changes, $check = false) { if ( ! $name) { - throw DoctrineException::updateMe('no valid table name specified'); + throw DoctrineException::missingTableName(); } foreach ($changes as $changeName => $change) { @@ -603,7 +603,7 @@ class MySqlPlatform extends AbstractPlatform case 'name': break; default: - throw DoctrineException::updateMe('change type "' . $changeName . '" not yet supported'); + throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName); } } @@ -749,12 +749,12 @@ class MySqlPlatform extends AbstractPlatform $type = strtoupper($definition['type']) . ' '; break; default: - throw DoctrineException::updateMe('Unknown index type ' . $definition['type']); + throw DoctrineException::invalidIndexType($definition['type']); } } if ( ! isset($definition['fields'])) { - throw DoctrineException::updateMe('No index columns given.'); + throw DoctrineException::indexFieldsArrayRequired(); } if ( ! is_array($definition['fields'])) { $definition['fields'] = array($definition['fields']); @@ -794,7 +794,7 @@ class MySqlPlatform extends AbstractPlatform $fieldString .= ' ' . $sort; break; default: - throw DoctrineException::updateMe('Unknown index sorting option given.'); + throw DoctrineException::unknownIndexSortingOption($sort); } } } else { diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index f74c38976..638d555a5 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -389,7 +389,7 @@ END;'; public function getAlterTableSql($name, array $changes, $check = false) { if ( ! $name) { - throw DoctrineException::updateMe('no valid table name specified'); + throw DoctrineException::missingTableName(); } foreach ($changes as $changeName => $change) { switch ($changeName) { @@ -400,7 +400,7 @@ END;'; case 'rename': break; default: - throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '" not yet supported'); + throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName); } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 860f949e1..a44d5cd9e 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -194,7 +194,7 @@ class PostgreSqlPlatform extends AbstractPlatform $match = $field.'LIKE '; break; default: - throw DoctrineException::updateMe('not a supported operator type:'. $operator); + throw DoctrineException::operatorNotSupported($operator); } } $match.= "'"; @@ -506,7 +506,7 @@ class PostgreSqlPlatform extends AbstractPlatform case 'rename': break; default: - throw DoctrineException::updateMe('change type "' . $changeName . '\" not yet supported'); + throw DoctrineException::alterTableChangeNotSupported($changeName); } } @@ -536,7 +536,7 @@ class PostgreSqlPlatform extends AbstractPlatform $serverInfo = $this->getServerVersion(); 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']); $sql[] = 'ALTER TABLE ' . $name . ' ' . $query; diff --git a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php index 649bc3739..8a78f57c3 100644 --- a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php @@ -160,7 +160,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager case 'rename': case 'change': default: - throw \Doctrine\Common\DoctrineException::updateMe('alterTable: change type "' . $changeName . '" not yet supported'); + throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName); } } diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 34b0404f0..29d6d7a07 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -318,7 +318,7 @@ class MySqlSchemaManager extends AbstractSchemaManager $res = $this->_conn->exec($query); } catch(Doctrine\DBAL\ConnectionException $e) { - throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table'); + throw \Doctrine\Common\DoctrineException::createSequenceFailed($query); } if ($start == 1) { @@ -334,7 +334,7 @@ class MySqlSchemaManager extends AbstractSchemaManager try { $res = $this->_conn->exec('DROP TABLE ' . $sequenceName); } catch (\Exception $e) { - throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table'); + throw \Doctrine\Common\DoctrineException::couldNotDropSequenceTable($sequenceName); } return $res; diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 50445bcad..da3fe9ccf 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -122,7 +122,7 @@ abstract class Type { if ( ! isset(self::$_typeObjects[$name])) { if ( ! isset(self::$_typesMap[$name])) { - throw DoctrineException::updateMe("Unknown type: $name"); + throw DoctrineException::unknownColumnType($name); } self::$_typeObjects[$name] = new self::$_typesMap[$name](); diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3479d673a..769588fda 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -207,9 +207,7 @@ abstract class AbstractQuery public function setResultCache($resultCache = null) { if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\Common\Cache\Cache)) { - throw DoctrineException::updateMe( - 'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.' - ); + throw DoctrineException::invalidResultCacheObject($resultCache); } $this->_resultCache = $resultCache; return $this; diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 9c84fe893..b5ed0550f 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -357,7 +357,7 @@ class EntityManager $this->_unitOfWork->clear(); } else { //TODO - throw DoctrineException::notImplemented(); + throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__); } } @@ -454,7 +454,7 @@ class EntityManager */ public function copy($entity, $deep = false) { - throw DoctrineException::notImplemented(); + throw DoctrineException::notImplemented(__FUNCTION__, __CLASS__); } /** @@ -557,7 +557,7 @@ class EntityManager $this->_hydrators[$hydrationMode] = new Internal\Hydration\SingleScalarHydrator($this); break; default: - throw DoctrineException::updateMe("No hydrator found for hydration mode '$hydrationMode'."); + throw DoctrineException::invalidHydrationMode($hydrationMode); } } return $this->_hydrators[$hydrationMode]; @@ -591,10 +591,10 @@ class EntityManager $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager())); } else if ($conn instanceof Connection) { 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 { - throw DoctrineException::updateMe("Invalid parameter '$conn'."); + throw DoctrineException::invalidParameter($conn); } return new EntityManager($conn, $config, $conn->getEventManager()); diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index f30f26c2c..dbb2c2b86 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -138,7 +138,7 @@ class EntityRepository } 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)); @@ -146,7 +146,7 @@ class EntityRepository if ($this->_class->hasField($fieldName)) { return $this->$method(array($fieldName => $arguments[0])); } else { - throw \Doctrine\Common\DoctrineException::updateMe('Cannot find by: ' . $by . '. Invalid field.'); + throw \Doctrine\Common\DoctrineException::invalidFindBy($by); } } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Id/Assigned.php b/lib/Doctrine/ORM/Id/Assigned.php index 3311084bc..a92ec76a7 100644 --- a/lib/Doctrine/ORM/Id/Assigned.php +++ b/lib/Doctrine/ORM/Id/Assigned.php @@ -62,7 +62,7 @@ class Assigned extends AbstractIdGenerator } if ( ! $identifier) { - throw DoctrineException::updateMe("Entity of type '" . get_class($entity) . "' is missing an assigned ID."); + throw DoctrineException::entityMissingAssignedId($entity); } return $identifier; diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index 31cd375aa..2a71bf40a 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -14,6 +14,6 @@ class TableGenerator extends AbstractIdGenerator { 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 diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 6a05e5c1a..8114ea320 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -304,6 +304,6 @@ abstract class AbstractHydrator } } - throw DoctrineException::updateMe("No owner found for field '$fieldName' during hydration."); + throw DoctrineException::noOwnerFoundForField($class, $fieldName); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 646dcb082..ce8a46e2a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -537,7 +537,7 @@ final class ClassMetadata public function getSingleIdReflectionProperty() { if ($this->isIdentifierComposite) { - throw DoctrineException::updateMe("getSingleIdReflectionProperty called on entity with composite key."); + throw DoctrineException::singleIdNotAllowedOnCompositePrimaryKey(); } return $this->reflFields[$this->identifier[0]]; } @@ -830,8 +830,7 @@ final class ClassMetadata public function getSingleIdentifierFieldName() { if ($this->isIdentifierComposite) { - throw DoctrineException::updateMe("Calling getSingleIdentifierFieldName " - . "on a class that uses a composite identifier is not allowed."); + throw DoctrineException::singleIdNotAllowedOnCompositePrimaryKey(); } return $this->identifier[0]; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index d21ae9260..6384a49cc 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -67,7 +67,7 @@ class AnnotationDriver implements Driver } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) { $metadata->isMappedSuperclass = true; } else { - throw DoctrineException::updateMe("$className is no entity or mapped superclass."); + throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className); } // Evaluate DoctrineTable annotation @@ -155,7 +155,7 @@ class AnnotationDriver implements Driver // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { if ($columnAnnot->type == null) { - throw DoctrineException::updateMe("Missing type on property " . $property->getName()); + throw DoctrineException::propertyTypeIsRequired($property->getName()); } $mapping['type'] = $columnAnnot->type; $mapping['length'] = $columnAnnot->length; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index cb519523e..34fc161fe 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -52,7 +52,7 @@ class XmlDriver extends AbstractFileDriver } else if ($xmlRoot->getName() == 'mapped-superclass') { $metadata->isMappedSuperclass = true; } else { - throw DoctrineException::updateMe("$className is no entity or mapped superclass."); + throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className); } // Evaluate attributes diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 0220ee42f..17082c85b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -53,7 +53,7 @@ class YamlDriver extends AbstractFileDriver } else if ($element['type'] == 'mappedSuperclass') { $metadata->isMappedSuperclass = true; } else { - throw DoctrineException::updateMe("$className is no entity or mapped superclass."); + throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className); } // Evaluate root level properties diff --git a/lib/Doctrine/ORM/Query/Expr/Base.php b/lib/Doctrine/ORM/Query/Expr/Base.php index e96ed6c18..a651b5308 100644 --- a/lib/Doctrine/ORM/Query/Expr/Base.php +++ b/lib/Doctrine/ORM/Query/Expr/Base.php @@ -60,7 +60,7 @@ abstract class Base $class = get_class($arg); 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); } } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0547392c8..fe8d878ac 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -421,12 +421,10 @@ class SqlWalker implements TreeWalker break; case AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION: - throw DoctrineException::updateMe("Not yet implemented."); + throw DoctrineException::notImplemented(); default: - throw DoctrineException::updateMe( - "Encountered invalid PathExpression during SQL construction." - ); + throw DoctrineException::invalidPathExpression($pathExpr->type); } return $sql; @@ -753,9 +751,7 @@ class SqlWalker implements TreeWalker $columnAlias = $this->_platform->getSqlResultCasing($columnAlias); $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName); } else { - throw DoctrineException::updateMe( - "Encountered invalid PathExpression during SQL construction." - ); + throw DoctrineException::invalidPathExpression($expr->type); } } else if ($expr instanceof AST\AggregateExpression) { if ( ! $selectExpression->fieldIdentificationVariable) { diff --git a/lib/Doctrine/ORM/Tools/Cli.php b/lib/Doctrine/ORM/Tools/Cli.php index 8bc1a3a84..012623567 100644 --- a/lib/Doctrine/ORM/Tools/Cli.php +++ b/lib/Doctrine/ORM/Tools/Cli.php @@ -176,9 +176,7 @@ class Cli $task->basicHelp(); // Fallback of not-valid task arguments } } else { - throw \Doctrine\Common\DoctrineException::updateMe( - 'Unexistent task or attached task class does not exist.' - ); + throw \Doctrine\Common\DoctrineException::taskDoesNotExist($taskName); } } } catch (\Doctrine\Common\DoctrineException $e) { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 50eb56ecb..f2f7810db 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -580,8 +580,7 @@ class UnitOfWork implements PropertyChangedListener $this->_entityChangeSets[$oid] = $changeSet; $this->_originalEntityData[$oid] = $data; } else if ($state == self::STATE_REMOVED) { - throw DoctrineException::updateMe("Removed entity in collection detected during flush." - . " Make sure you properly remove deleted entities from collections."); + throw DoctrineException::removedEntityInCollectionDetected(); } // MANAGED associated entities are already taken into account // during changeset calculation anyway, since they are in the identity map. @@ -819,13 +818,13 @@ class UnitOfWork implements PropertyChangedListener $oid = spl_object_hash($entity); if (isset($this->_entityUpdates[$oid])) { - throw DoctrineException::updateMe("Dirty object can't be registered as new."); + throw DoctrineException::dirtyObjectCannotBeRegisteredAsNew(); } if (isset($this->_entityDeletions[$oid])) { - throw DoctrineException::updateMe("Removed object can't be registered as new."); + throw DoctrineException::removedObjectCannotBeRegisteredAsNew(); } if (isset($this->_entityInsertions[$oid])) { - throw DoctrineException::updateMe("Object already registered as new. Can't register twice."); + throw DoctrineException::objectAlreadyRegisteredAsNew(); } $this->_entityInsertions[$oid] = $entity; @@ -855,11 +854,10 @@ class UnitOfWork implements PropertyChangedListener { $oid = spl_object_hash($entity); if ( ! isset($this->_entityIdentifiers[$oid])) { - throw DoctrineException::updateMe("Entity without identity " - . "can't be registered as dirty."); + throw DoctrineException::entityWithoutIdentityCannotBeRegisteredAsDirty(); } 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])) { @@ -961,8 +959,7 @@ class UnitOfWork implements PropertyChangedListener $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = implode(' ', $this->_entityIdentifiers[spl_object_hash($entity)]); if ($idHash === '') { - throw DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) - . "' has no identity and therefore can't be added to the identity map."); + throw DoctrineException::entityMustHaveIdentifyToBeAddedToIdentityMap($entity); } $className = $classMetadata->rootEntityName; if (isset($this->_identityMap[$className][$idHash])) { @@ -1024,8 +1021,7 @@ class UnitOfWork implements PropertyChangedListener $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = implode(' ', $this->_entityIdentifiers[$oid]); if ($idHash === '') { - throw DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) - . "' has no identity and therefore can't be removed from the identity map."); + throw DoctrineException::entityMustHaveIdentifyToBeRemovedFromIdentityMap($entity); } $className = $classMetadata->rootEntityName; if (isset($this->_identityMap[$className][$idHash])) { @@ -1131,8 +1127,9 @@ class UnitOfWork implements PropertyChangedListener $visited[$oid] = $entity; // Mark visited - $class = $this->_em->getClassMetadata(get_class($entity)); - switch ($this->getEntityState($entity, self::STATE_NEW)) { + $class = $this->_em->getClassMetadata(get_class($entity)); + $entityState = $this->getEntityState($entity, self::STATE_NEW); + switch ($entityState) { case self::STATE_MANAGED: // Nothing to do, except if policy is "deferred explicit" if ($class->isChangeTrackingDeferredExplicit()) { @@ -1162,7 +1159,7 @@ class UnitOfWork implements PropertyChangedListener $this->scheduleForInsert($entity); break; 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."); case self::STATE_REMOVED: // Entity becomes managed again @@ -1174,7 +1171,7 @@ class UnitOfWork implements PropertyChangedListener } break; default: - throw DoctrineException::updateMe("Encountered invalid entity state."); + throw DoctrineException::invalidEntityState($entityState); } $this->_cascadePersist($entity, $visited); @@ -1211,7 +1208,8 @@ class UnitOfWork implements PropertyChangedListener $visited[$oid] = $entity; // mark visited $class = $this->_em->getClassMetadata(get_class($entity)); - switch ($this->getEntityState($entity)) { + $entityState = $this->getEntityState($entity); + switch ($entityState) { case self::STATE_NEW: case self::STATE_REMOVED: // nothing to do @@ -1226,11 +1224,11 @@ class UnitOfWork implements PropertyChangedListener $this->scheduleForDelete($entity); break; case self::STATE_DETACHED: - throw new \InvalidArgumentException("A detached entity can not be removed."); + throw DoctrineException::detachedEntityCannotBeRemoved(); default: - throw DoctrineException::updateMe("Encountered invalid entity state."); + throw DoctrineException::invalidEntityState($entityState); } - + $this->_cascadeRemove($entity, $visited); }