Commit 43b67919 authored by jwage's avatar jwage

[2.0] More replacing of old style of exceptions to intermediate step

parent 5582f07b
<?php
/*
* $Id: Exception.php 4628 2008-07-04 16:32:19Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
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 <jonwage@gmail.com
*/
class ConnectionException extends DoctrineException
{
public static function invalidPDOInstance()
{
return new self("Invalid PDO instance provided on connection creation.");
}
public static function driverRequired()
{
return new self("Please provide a driver or a driverClass to be able to start a Connection.");
}
public static function unknownDriver($driver)
{
return new self("Unknown Connection driver '$driver'.");
}
}
\ No newline at end of file
...@@ -1831,7 +1831,7 @@ abstract class AbstractPlatform ...@@ -1831,7 +1831,7 @@ abstract class AbstractPlatform
case Connection::TRANSACTION_SERIALIZABLE: case Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE'; return 'SERIALIZABLE';
default: default:
throw new Doctrine_Common_Exceptions_DoctrineException('isolation level is not supported: ' . $isolation); throw \Doctrine\Common\DoctrineException::updateMe('isolation level is not supported: ' . $isolation);
} }
} }
...@@ -1842,7 +1842,7 @@ abstract class AbstractPlatform ...@@ -1842,7 +1842,7 @@ abstract class AbstractPlatform
*/ */
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
throw new DoctrineException('Set transaction isolation not supported by this platform.'); throw \Doctrine\Common\DoctrineException::updateMe('Set transaction isolation not supported by this platform.');
} }
/** /**
......
...@@ -57,7 +57,7 @@ class Statement ...@@ -57,7 +57,7 @@ class Statement
$this->_stmt = $stmt; $this->_stmt = $stmt;
if ($stmt === false) { if ($stmt === false) {
throw new DoctrineException('Unknown statement object given.'); throw \Doctrine\Common\DoctrineException::updateMe('Unknown statement object given.');
} }
} }
......
...@@ -55,7 +55,7 @@ abstract class Type ...@@ -55,7 +55,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 new DoctrineException("Unknown type: $name"); \Doctrine\Common\DoctrineException::updateMe("Unknown type: $name");
} }
self::$_typeObjects[$name] = new self::$_typesMap[$name](); self::$_typeObjects[$name] = new self::$_typesMap[$name]();
} }
......
...@@ -39,7 +39,7 @@ class ApcCache implements Cache ...@@ -39,7 +39,7 @@ class ApcCache implements Cache
public function __construct() public function __construct()
{ {
if ( ! extension_loaded('apc')) { 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.');
} }
} }
......
...@@ -561,7 +561,7 @@ class EntityManager ...@@ -561,7 +561,7 @@ class EntityManager
$this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\NoneHydrator($this); $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\NoneHydrator($this);
break; break;
default: 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) { } else if ($this->_hydrators[$hydrationMode] instanceof Closure) {
$this->_hydrators[$hydrationMode] = $this->_hydrators[$hydrationMode]($this); $this->_hydrators[$hydrationMode] = $this->_hydrators[$hydrationMode]($this);
...@@ -596,7 +596,7 @@ class EntityManager ...@@ -596,7 +596,7 @@ class EntityManager
if (is_array($conn)) { if (is_array($conn)) {
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
} else if ( ! $conn instanceof Connection) { } else if ( ! $conn instanceof Connection) {
throw new DoctrineException("Invalid parameter '$conn'."); \Doctrine\Common\DoctrineException::updateMe("Invalid parameter '$conn'.");
} }
if (is_null($config)) { if (is_null($config)) {
......
...@@ -121,7 +121,7 @@ class ClassExporter ...@@ -121,7 +121,7 @@ class ClassExporter
$foreignKeyConstraints[] = $constraint; $foreignKeyConstraints[] = $constraint;
} else if ($mapping->isOneToMany() && $mapping->isOwningSide()) { } else if ($mapping->isOneToMany() && $mapping->isOwningSide()) {
//... create join table, one-many through join table supported later //... 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()) { } else if ($mapping->isManyToMany() && $mapping->isOwningSide()) {
//... create join table //... create join table
$joinTableColumns = array(); $joinTableColumns = array();
......
...@@ -61,7 +61,7 @@ class Assigned extends AbstractIdGenerator ...@@ -61,7 +61,7 @@ class Assigned extends AbstractIdGenerator
} }
if ( ! $identifier) { 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; return $identifier;
......
...@@ -12,7 +12,7 @@ class TableGenerator extends AbstractIdGenerator ...@@ -12,7 +12,7 @@ class TableGenerator extends AbstractIdGenerator
public function generate($entity) public function generate($entity)
{ {
throw new \Exception("Not implemented"); throw \Doctrine\Common\DoctrineException::updateMe("Not implemented");
} }
} }
......
...@@ -353,7 +353,7 @@ abstract class AbstractHydrator ...@@ -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 */ /** Needed only temporarily until the new parser is ready */
......
...@@ -389,7 +389,7 @@ final class ClassMetadata ...@@ -389,7 +389,7 @@ final class ClassMetadata
public function getSingleIdReflectionProperty() public function getSingleIdReflectionProperty()
{ {
if ($this->_isIdentifierComposite) { 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]]; return $this->_reflectionProperties[$this->_identifier[0]];
} }
......
...@@ -48,7 +48,7 @@ class AnnotationDriver ...@@ -48,7 +48,7 @@ class AnnotationDriver
// Evaluate DoctrineEntity annotation // Evaluate DoctrineEntity annotation
if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) { 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); $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
...@@ -109,7 +109,7 @@ class AnnotationDriver ...@@ -109,7 +109,7 @@ class AnnotationDriver
// DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany // DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany
if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) { if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
if ($columnAnnot->type == null) { 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['type'] = $columnAnnot->type;
$mapping['length'] = $columnAnnot->length; $mapping['length'] = $columnAnnot->length;
......
...@@ -127,7 +127,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection ...@@ -127,7 +127,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
$this->_ownerClass = $em->getClassMetadata($type); $this->_ownerClass = $em->getClassMetadata($type);
if ($keyField !== null) { if ($keyField !== null) {
if ( ! $this->_ownerClass->hasField($keyField)) { 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; $this->_keyField = $keyField;
} }
......
...@@ -173,7 +173,7 @@ abstract class AbstractEntityPersister ...@@ -173,7 +173,7 @@ abstract class AbstractEntityPersister
$mapping = $this->_classMetadata->getFieldMapping($fieldName); $mapping = $this->_classMetadata->getFieldMapping($fieldName);
return $mapping['inherited']; 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'.");
} }
/** /**
......
...@@ -328,7 +328,7 @@ class Query extends AbstractQuery ...@@ -328,7 +328,7 @@ class Query extends AbstractQuery
public function setResultCache($resultCache) public function setResultCache($resultCache)
{ {
if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\ORM\Cache\Cache)) { 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.' 'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.'
); );
} }
...@@ -410,7 +410,7 @@ class Query extends AbstractQuery ...@@ -410,7 +410,7 @@ class Query extends AbstractQuery
public function setQueryCache($queryCache) public function setQueryCache($queryCache)
{ {
if ($queryCache !== null && ! ($queryCache instanceof \Doctrine\ORM\Cache\Cache)) { 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.' 'Method setResultCache() accepts only an instance of Doctrine_ORM_Cache_Interface or null.'
); );
} }
......
...@@ -18,13 +18,13 @@ class ArithmeticExpression extends Node ...@@ -18,13 +18,13 @@ class ArithmeticExpression extends Node
public function setSimpleArithmeticExpression($simpleArithmeticExpr) public function setSimpleArithmeticExpression($simpleArithmeticExpr)
{ {
if ($this->_subselect) throw new Doctrine_Exception; if ($this->_subselect) throw \Doctrine\Common\DoctrineException::updateMe();
$this->_simpleArithmeticExpression = $simpleArithmeticExpr; $this->_simpleArithmeticExpression = $simpleArithmeticExpr;
} }
public function setSubselect($subselect) public function setSubselect($subselect)
{ {
if ($this->_simpleArithmeticExpression) throw new Doctrine_Exception; if ($this->_simpleArithmeticExpression) throw \Doctrine\Common\DoctrineException::updateMe();
$this->_subselect = $subselect; $this->_subselect = $subselect;
} }
......
...@@ -244,7 +244,7 @@ class Parser ...@@ -244,7 +244,7 @@ class Parser
$message .= "'{$this->_lexer->lookahead['value']}'"; $message .= "'{$this->_lexer->lookahead['value']}'";
} }
throw new QueryException($message); throw \Doctrine\Common\DoctrineException::updateMe($message);
} }
/** /**
...@@ -259,7 +259,7 @@ class Parser ...@@ -259,7 +259,7 @@ class Parser
$token = $this->_lexer->token; $token = $this->_lexer->token;
} }
//TODO: Include $token in $message //TODO: Include $token in $message
throw new QueryException($message); throw \Doctrine\Common\DoctrineException::updateMe($message);
} }
/** /**
...@@ -1139,7 +1139,7 @@ class Parser ...@@ -1139,7 +1139,7 @@ class Parser
default: default:
$this->syntaxError(); $this->syntaxError();
} }
throw new QueryException("Not yet implemented."); throw \Doctrine\Common\DoctrineException::updateMe("Not yet implemented.");
//TODO... //TODO...
} }
......
...@@ -174,9 +174,9 @@ class SqlWalker ...@@ -174,9 +174,9 @@ class SqlWalker
$sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName) . $sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName) .
' AS ' . $sqlTableAlias . '__' . $class->getColumnName($fieldName); ' AS ' . $sqlTableAlias . '__' . $class->getColumnName($fieldName);
} else if ($pathExpression->isSimpleStateFieldAssociationPathExpression()) { } else if ($pathExpression->isSimpleStateFieldAssociationPathExpression()) {
throw new DoctrineException("Not yet implemented."); \Doctrine\Common\DoctrineException::updateMe("Not yet implemented.");
} else { } 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) { else if ($selectExpression->getExpression() instanceof AST\AggregateExpression) {
...@@ -380,9 +380,9 @@ class SqlWalker ...@@ -380,9 +380,9 @@ class SqlWalker
$sqlTableAlias = $this->_dqlToSqlAliasMap[$dqlAlias]; $sqlTableAlias = $this->_dqlToSqlAliasMap[$dqlAlias];
$sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName); $sql .= $sqlTableAlias . '.' . $class->getColumnName($fieldName);
} else if ($pathExpr->isSimpleStateFieldAssociationPathExpression()) { } else if ($pathExpr->isSimpleStateFieldAssociationPathExpression()) {
throw new DoctrineException("Not yet implemented."); \Doctrine\Common\DoctrineException::updateMe("Not yet implemented.");
} else { } else {
throw new DoctrineException("Encountered invalid PathExpression during SQL construction."); \Doctrine\Common\DoctrineException::updateMe("Encountered invalid PathExpression during SQL construction.");
} }
return $sql; return $sql;
} }
......
...@@ -470,7 +470,7 @@ class UnitOfWork ...@@ -470,7 +470,7 @@ class UnitOfWork
$this->_entityChangeSets[$oid] = $changeSet; $this->_entityChangeSets[$oid] = $changeSet;
$this->_originalEntityData[$oid] = $data; $this->_originalEntityData[$oid] = $data;
} else if ($state == self::STATE_DELETED) { } 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 // 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.
...@@ -605,13 +605,13 @@ class UnitOfWork ...@@ -605,13 +605,13 @@ class UnitOfWork
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if (isset($this->_entityUpdates[$oid])) { 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])) { 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])) { 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; $this->_entityInsertions[$oid] = $entity;
...@@ -642,11 +642,11 @@ class UnitOfWork ...@@ -642,11 +642,11 @@ class UnitOfWork
{ {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if ( ! isset($this->_entityIdentifiers[$oid])) { if ( ! isset($this->_entityIdentifiers[$oid])) {
throw new DoctrineException("Entity without identity " \Doctrine\Common\DoctrineException::updateMe("Entity without identity "
. "can't be registered as dirty."); . "can't be registered as dirty.");
} }
if (isset($this->_entityDeletions[$oid])) { 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])) { if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) {
...@@ -784,7 +784,7 @@ class UnitOfWork ...@@ -784,7 +784,7 @@ class UnitOfWork
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = $this->getIdentifierHash($this->_entityIdentifiers[spl_object_hash($entity)]); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[spl_object_hash($entity)]);
if ($idHash === '') { 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."); . "' has no identity and therefore can't be added to the identity map.");
} }
$className = $classMetadata->getRootClassName(); $className = $classMetadata->getRootClassName();
...@@ -827,7 +827,7 @@ class UnitOfWork ...@@ -827,7 +827,7 @@ class UnitOfWork
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = $this->getIdentifierHash($this->_entityIdentifiers[$oid]); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[$oid]);
if ($idHash === '') { 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."); . "' has no identity and therefore can't be removed from the identity map.");
} }
$className = $classMetadata->getRootClassName(); $className = $classMetadata->getRootClassName();
...@@ -989,7 +989,7 @@ class UnitOfWork ...@@ -989,7 +989,7 @@ class UnitOfWork
$this->registerNew($entity); $this->registerNew($entity);
break; break;
case self::STATE_DETACHED: 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."); . "is not yet defined.");
case self::STATE_DELETED: case self::STATE_DELETED:
// entity becomes managed again // entity becomes managed again
...@@ -1003,7 +1003,7 @@ class UnitOfWork ...@@ -1003,7 +1003,7 @@ class UnitOfWork
break; break;
default: default:
//TODO: throw UnitOfWorkException::invalidEntityState() //TODO: throw UnitOfWorkException::invalidEntityState()
throw new DoctrineException("Encountered invalid entity state."); \Doctrine\Common\DoctrineException::updateMe("Encountered invalid entity state.");
} }
$this->_cascadeSave($entity, $visited, $insertNow); $this->_cascadeSave($entity, $visited, $insertNow);
} }
...@@ -1045,9 +1045,9 @@ class UnitOfWork ...@@ -1045,9 +1045,9 @@ class UnitOfWork
$this->registerDeleted($entity); $this->registerDeleted($entity);
break; break;
case self::STATE_DETACHED: 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: default:
throw new DoctrineException("Encountered invalid entity state."); \Doctrine\Common\DoctrineException::updateMe("Encountered invalid entity state.");
} }
$this->_cascadeDelete($entity, $visited); $this->_cascadeDelete($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