From 43b6791919efd6294f1a769b13770a18a339d0d1 Mon Sep 17 00:00:00 2001 From: jwage Date: Thu, 19 Feb 2009 07:07:44 +0000 Subject: [PATCH] [2.0] More replacing of old style of exceptions to intermediate step --- lib/Doctrine/DBAL/ConnectionException.php | 51 +++++++++++++++++++ .../DBAL/Platforms/AbstractPlatform.php | 4 +- lib/Doctrine/DBAL/Statement.php | 2 +- lib/Doctrine/DBAL/Types/Type.php | 2 +- lib/Doctrine/ORM/Cache/ApcCache.php | 2 +- lib/Doctrine/ORM/EntityManager.php | 4 +- lib/Doctrine/ORM/Export/ClassExporter.php | 2 +- 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 | 2 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 +- lib/Doctrine/ORM/PersistentCollection.php | 2 +- .../Persisters/AbstractEntityPersister.php | 2 +- lib/Doctrine/ORM/Query.php | 4 +- .../ORM/Query/AST/ArithmeticExpression.php | 4 +- lib/Doctrine/ORM/Query/Parser.php | 6 +-- lib/Doctrine/ORM/Query/SqlWalker.php | 8 +-- lib/Doctrine/ORM/UnitOfWork.php | 24 ++++----- 19 files changed, 90 insertions(+), 39 deletions(-) create mode 100644 lib/Doctrine/DBAL/ConnectionException.php diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php new file mode 100644 index 000000000..8c7fe9580 --- /dev/null +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -0,0 +1,51 @@ +. + */ + +namespace Doctrine\DBAL; + +use Doctrine\Common\DoctrineException; + +/** + * Doctrine\DBAL\ConnectionException + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision: 4628 $ + * @author Jonathan H. Wage _stmt = $stmt; if ($stmt === false) { - throw new DoctrineException('Unknown statement object given.'); + throw \Doctrine\Common\DoctrineException::updateMe('Unknown statement object given.'); } } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index b6fb3326c..b007d45fe 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -55,7 +55,7 @@ abstract class Type } if ( ! isset(self::$_typeObjects[$name])) { if ( ! isset(self::$_typesMap[$name])) { - throw new DoctrineException("Unknown type: $name"); + \Doctrine\Common\DoctrineException::updateMe("Unknown type: $name"); } self::$_typeObjects[$name] = new self::$_typesMap[$name](); } diff --git a/lib/Doctrine/ORM/Cache/ApcCache.php b/lib/Doctrine/ORM/Cache/ApcCache.php index 6192d3f34..9104ea4f8 100644 --- a/lib/Doctrine/ORM/Cache/ApcCache.php +++ b/lib/Doctrine/ORM/Cache/ApcCache.php @@ -39,7 +39,7 @@ class ApcCache implements Cache public function __construct() { if ( ! extension_loaded('apc')) { - throw new DoctrineException('The apc extension must be loaded in order to use the ApcCache.'); + \Doctrine\Common\DoctrineException::updateMe('The apc extension must be loaded in order to use the ApcCache.'); } } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index bee4be68e..38ac37287 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -561,7 +561,7 @@ class EntityManager $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\NoneHydrator($this); break; default: - throw new DoctrineException("No hydrator found for hydration mode '$hydrationMode'."); + \Doctrine\Common\DoctrineException::updateMe("No hydrator found for hydration mode '$hydrationMode'."); } } else if ($this->_hydrators[$hydrationMode] instanceof Closure) { $this->_hydrators[$hydrationMode] = $this->_hydrators[$hydrationMode]($this); @@ -596,7 +596,7 @@ class EntityManager if (is_array($conn)) { $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); } else if ( ! $conn instanceof Connection) { - throw new DoctrineException("Invalid parameter '$conn'."); + \Doctrine\Common\DoctrineException::updateMe("Invalid parameter '$conn'."); } if (is_null($config)) { diff --git a/lib/Doctrine/ORM/Export/ClassExporter.php b/lib/Doctrine/ORM/Export/ClassExporter.php index d1ac2edbc..108aefd36 100644 --- a/lib/Doctrine/ORM/Export/ClassExporter.php +++ b/lib/Doctrine/ORM/Export/ClassExporter.php @@ -121,7 +121,7 @@ class ClassExporter $foreignKeyConstraints[] = $constraint; } else if ($mapping->isOneToMany() && $mapping->isOwningSide()) { //... create join table, one-many through join table supported later - throw new DoctrineException("Not yet implemented."); + \Doctrine\Common\DoctrineException::updateMe("Not yet implemented."); } else if ($mapping->isManyToMany() && $mapping->isOwningSide()) { //... create join table $joinTableColumns = array(); diff --git a/lib/Doctrine/ORM/Id/Assigned.php b/lib/Doctrine/ORM/Id/Assigned.php index 9174b27b3..d8b0c3d54 100644 --- a/lib/Doctrine/ORM/Id/Assigned.php +++ b/lib/Doctrine/ORM/Id/Assigned.php @@ -61,7 +61,7 @@ class Assigned extends AbstractIdGenerator } if ( ! $identifier) { - throw new DoctrineException("Entity of type '" . get_class($entity) . "' is missing an assigned ID."); + \Doctrine\Common\DoctrineException::updateMe("Entity of type '" . get_class($entity) . "' is missing an assigned ID."); } return $identifier; diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index d5e20e7c2..6b98b63a3 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -12,7 +12,7 @@ class TableGenerator extends AbstractIdGenerator public function generate($entity) { - throw new \Exception("Not implemented"); + throw \Doctrine\Common\DoctrineException::updateMe("Not implemented"); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 3cbae67e9..b76d7485d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -353,7 +353,7 @@ abstract class AbstractHydrator } } - throw new DoctrineException("No field name found for column name '$lcColumnName' during hydration."); + \Doctrine\Common\DoctrineException::updateMe("No field name found for column name '$lcColumnName' during hydration."); } /** Needed only temporarily until the new parser is ready */ diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 0fa9d9d18..18865042f 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -389,7 +389,7 @@ final class ClassMetadata public function getSingleIdReflectionProperty() { if ($this->_isIdentifierComposite) { - throw new DoctrineException("getSingleIdReflectionProperty called on entity with composite key."); + \Doctrine\Common\DoctrineException::updateMe("getSingleIdReflectionProperty called on entity with composite key."); } return $this->_reflectionProperties[$this->_identifier[0]]; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 3d5ce3061..dcbdd1f91 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -48,7 +48,7 @@ class AnnotationDriver // Evaluate DoctrineEntity annotation if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) { - throw new MappingException("$className is no entity."); + throw \Doctrine\Common\DoctrineException::updateMe("$className is no entity."); } $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); @@ -109,7 +109,7 @@ class AnnotationDriver // DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) { if ($columnAnnot->type == null) { - throw new MappingException("Missing type on property " . $property->getName()); + throw \Doctrine\Common\DoctrineException::updateMe("Missing type on property " . $property->getName()); } $mapping['type'] = $columnAnnot->type; $mapping['length'] = $columnAnnot->length; diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 9a3b341d5..88dd0fa75 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -127,7 +127,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection $this->_ownerClass = $em->getClassMetadata($type); if ($keyField !== null) { if ( ! $this->_ownerClass->hasField($keyField)) { - throw new DoctrineException("Invalid field '$keyField' can't be used as key."); + \Doctrine\Common\DoctrineException::updateMe("Invalid field '$keyField' can't be used as key."); } $this->_keyField = $keyField; } diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php index a9bbd072d..bba16614d 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php @@ -173,7 +173,7 @@ abstract class AbstractEntityPersister $mapping = $this->_classMetadata->getFieldMapping($fieldName); return $mapping['inherited']; } - throw new DoctrineException("Unable to find defining class of field '$fieldName'."); + \Doctrine\Common\DoctrineException::updateMe("Unable to find defining class of field '$fieldName'."); } /** diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 6fd618f26..e290b6ca6 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -328,7 +328,7 @@ class Query extends AbstractQuery public function setResultCache($resultCache) { if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\ORM\Cache\Cache)) { - throw new DoctrineException( + \Doctrine\Common\DoctrineException::updateMe( 'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.' ); } @@ -410,7 +410,7 @@ class Query extends AbstractQuery public function setQueryCache($queryCache) { if ($queryCache !== null && ! ($queryCache instanceof \Doctrine\ORM\Cache\Cache)) { - throw new DoctrineException( + \Doctrine\Common\DoctrineException::updateMe( 'Method setResultCache() accepts only an instance of Doctrine_ORM_Cache_Interface or null.' ); } diff --git a/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php b/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php index f35a2d29b..6e008a61b 100644 --- a/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php @@ -18,13 +18,13 @@ class ArithmeticExpression extends Node public function setSimpleArithmeticExpression($simpleArithmeticExpr) { - if ($this->_subselect) throw new Doctrine_Exception; + if ($this->_subselect) throw \Doctrine\Common\DoctrineException::updateMe(); $this->_simpleArithmeticExpression = $simpleArithmeticExpr; } public function setSubselect($subselect) { - if ($this->_simpleArithmeticExpression) throw new Doctrine_Exception; + if ($this->_simpleArithmeticExpression) throw \Doctrine\Common\DoctrineException::updateMe(); $this->_subselect = $subselect; } diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index ad7e78e51..cdddc4481 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -244,7 +244,7 @@ class Parser $message .= "'{$this->_lexer->lookahead['value']}'"; } - throw new QueryException($message); + throw \Doctrine\Common\DoctrineException::updateMe($message); } /** @@ -259,7 +259,7 @@ class Parser $token = $this->_lexer->token; } //TODO: Include $token in $message - throw new QueryException($message); + throw \Doctrine\Common\DoctrineException::updateMe($message); } /** @@ -1139,7 +1139,7 @@ class Parser default: $this->syntaxError(); } - throw new QueryException("Not yet implemented."); + throw \Doctrine\Common\DoctrineException::updateMe("Not yet implemented."); //TODO... } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 81fb98441..a63cc649b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -174,9 +174,9 @@ class SqlWalker $sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName) . ' AS ' . $sqlTableAlias . '__' . $class->getColumnName($fieldName); } else if ($pathExpression->isSimpleStateFieldAssociationPathExpression()) { - throw new DoctrineException("Not yet implemented."); + \Doctrine\Common\DoctrineException::updateMe("Not yet implemented."); } else { - throw new DoctrineException("Encountered invalid PathExpression during SQL construction."); + \Doctrine\Common\DoctrineException::updateMe("Encountered invalid PathExpression during SQL construction."); } } else if ($selectExpression->getExpression() instanceof AST\AggregateExpression) { @@ -380,9 +380,9 @@ class SqlWalker $sqlTableAlias = $this->_dqlToSqlAliasMap[$dqlAlias]; $sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName); } else if ($pathExpr->isSimpleStateFieldAssociationPathExpression()) { - throw new DoctrineException("Not yet implemented."); + \Doctrine\Common\DoctrineException::updateMe("Not yet implemented."); } else { - throw new DoctrineException("Encountered invalid PathExpression during SQL construction."); + \Doctrine\Common\DoctrineException::updateMe("Encountered invalid PathExpression during SQL construction."); } return $sql; } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 602974c11..4a44a2a5a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -470,7 +470,7 @@ class UnitOfWork $this->_entityChangeSets[$oid] = $changeSet; $this->_originalEntityData[$oid] = $data; } else if ($state == self::STATE_DELETED) { - throw new DoctrineException("Deleted entity in collection detected during flush."); + \Doctrine\Common\DoctrineException::updateMe("Deleted entity in collection detected during flush."); } // MANAGED associated entities are already taken into account // during changeset calculation anyway, since they are in the identity map. @@ -605,13 +605,13 @@ class UnitOfWork $oid = spl_object_hash($entity); if (isset($this->_entityUpdates[$oid])) { - throw new DoctrineException("Dirty object can't be registered as new."); + \Doctrine\Common\DoctrineException::updateMe("Dirty object can't be registered as new."); } if (isset($this->_entityDeletions[$oid])) { - throw new DoctrineException("Removed object can't be registered as new."); + \Doctrine\Common\DoctrineException::updateMe("Removed object can't be registered as new."); } if (isset($this->_entityInsertions[$oid])) { - throw new DoctrineException("Object already registered as new. Can't register twice."); + \Doctrine\Common\DoctrineException::updateMe("Object already registered as new. Can't register twice."); } $this->_entityInsertions[$oid] = $entity; @@ -642,11 +642,11 @@ class UnitOfWork { $oid = spl_object_hash($entity); if ( ! isset($this->_entityIdentifiers[$oid])) { - throw new DoctrineException("Entity without identity " + \Doctrine\Common\DoctrineException::updateMe("Entity without identity " . "can't be registered as dirty."); } if (isset($this->_entityDeletions[$oid])) { - throw new DoctrineException("Removed object can't be registered as dirty."); + \Doctrine\Common\DoctrineException::updateMe("Removed object can't be registered as dirty."); } if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) { @@ -784,7 +784,7 @@ class UnitOfWork $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[spl_object_hash($entity)]); if ($idHash === '') { - throw new DoctrineException("Entity with oid '" . spl_object_hash($entity) + \Doctrine\Common\DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) . "' has no identity and therefore can't be added to the identity map."); } $className = $classMetadata->getRootClassName(); @@ -827,7 +827,7 @@ class UnitOfWork $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[$oid]); if ($idHash === '') { - throw new DoctrineException("Entity with oid '" . spl_object_hash($entity) + \Doctrine\Common\DoctrineException::updateMe("Entity with oid '" . spl_object_hash($entity) . "' has no identity and therefore can't be removed from the identity map."); } $className = $classMetadata->getRootClassName(); @@ -989,7 +989,7 @@ class UnitOfWork $this->registerNew($entity); break; case self::STATE_DETACHED: - throw new DoctrineException("Behavior of save() for a detached entity " + \Doctrine\Common\DoctrineException::updateMe("Behavior of save() for a detached entity " . "is not yet defined."); case self::STATE_DELETED: // entity becomes managed again @@ -1003,7 +1003,7 @@ class UnitOfWork break; default: //TODO: throw UnitOfWorkException::invalidEntityState() - throw new DoctrineException("Encountered invalid entity state."); + \Doctrine\Common\DoctrineException::updateMe("Encountered invalid entity state."); } $this->_cascadeSave($entity, $visited, $insertNow); } @@ -1045,9 +1045,9 @@ class UnitOfWork $this->registerDeleted($entity); break; case self::STATE_DETACHED: - throw new DoctrineException("A detached entity can't be deleted."); + \Doctrine\Common\DoctrineException::updateMe("A detached entity can't be deleted."); default: - throw new DoctrineException("Encountered invalid entity state."); + \Doctrine\Common\DoctrineException::updateMe("Encountered invalid entity state."); } $this->_cascadeDelete($entity, $visited); }