1
0
mirror of synced 2025-02-20 06:03:15 +03:00

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

This commit is contained in:
jwage 2009-08-26 22:03:39 +00:00
parent b17ad38eed
commit f83fd8e950
23 changed files with 101 additions and 106 deletions

View File

@ -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.');
}
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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]();

View File

@ -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;

View File

@ -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());

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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__);
}
}

View File

@ -304,6 +304,6 @@ abstract class AbstractHydrator
}
}
throw DoctrineException::updateMe("No owner found for field '$fieldName' during hydration.");
throw DoctrineException::noOwnerFoundForField($class, $fieldName);
}
}

View File

@ -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];
}

View File

@ -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;

View File

@ -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 <entity...> attributes

View File

@ -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

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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);
}