From 1013eb66c1a5e2d07b1c7e97343dee1553ee3891 Mon Sep 17 00:00:00 2001 From: romanb Date: Mon, 7 Dec 2009 12:47:23 +0000 Subject: [PATCH] [2.0] Fixed PHP Notice in SchemaTest (only variables should be passed by reference...) and a few other cosmetics in various parts. --- lib/Doctrine/ORM/EntityRepository.php | 4 +-- .../Internal/Hydration/AbstractHydrator.php | 11 ++++--- .../ORM/Internal/Hydration/ArrayHydrator.php | 3 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 2 +- .../Hydration/SingleScalarHydrator.php | 6 ---- .../ORM/Mapping/AssociationMapping.php | 4 ++- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 ++- lib/Doctrine/ORM/Mapping/OneToOneMapping.php | 29 +++++++++++++++++++ lib/Doctrine/ORM/OptimisticLockException.php | 9 ++++-- .../Persisters/StandardEntityPersister.php | 2 +- lib/Doctrine/ORM/UnitOfWork.php | 2 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 3 +- 12 files changed, 55 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 5b8563f9b..78cf37b2a 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -136,8 +136,8 @@ class EntityRepository * * @return array|object The found entity/entities. * @throws BadMethodCallException If the method called is an invalid find* method - * or no find* method at all and therefore an invalid - * method call. + * or no find* method at all and therefore an invalid + * method call. */ public function __call($method, $arguments) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 3239fd85e..c702cca17 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -22,8 +22,7 @@ namespace Doctrine\ORM\Internal\Hydration; use Doctrine\DBAL\Connection, - Doctrine\DBAL\Types\Type, - Doctrine\Common\DoctrineException; + Doctrine\DBAL\Types\Type; /** * Base class for all hydrators. A hydrator is a class that provides some form @@ -38,7 +37,7 @@ use Doctrine\DBAL\Connection, */ abstract class AbstractHydrator { - /** The ResultSetMapping. */ + /** @var ResultSetMapping The ResultSetMapping. */ protected $_rsm; /** @var EntityManager The EntityManager instance. */ @@ -152,7 +151,7 @@ abstract class AbstractHydrator */ protected function _hydrateRow(array &$data, array &$cache, array &$result) { - throw new DoctrineException("_hydrateRow() not implemented by this hydrator."); + throw new HydrationException("_hydrateRow() not implemented by this hydrator."); } /** @@ -301,7 +300,7 @@ abstract class AbstractHydrator * during hydration because the hydrator caches effectively. * * @return string The field name. - * @throws DoctrineException If the field name could not be found. + * @throws HydrationException If the field name could not be found. * @todo Remove. See inline FIXME comment. */ private function _lookupDeclaringClass($class, $fieldName) @@ -317,6 +316,6 @@ abstract class AbstractHydrator } } - throw DoctrineException::noOwnerFoundForField($class, $fieldName); + throw new HydrationException("No owner found for field $fieldName."); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index b00b34d81..2fe8acf22 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -81,8 +81,7 @@ class ArrayHydrator extends AbstractHydrator unset($rowData['scalars']); } - // 3) Now hydrate the rest of the data found in the current row, that - // belongs to other (related) entities. + // 2) Now hydrate the data found in the current row. foreach ($rowData as $dqlAlias => $data) { $index = false; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index d2be5fb1e..26f9e163e 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -137,7 +137,7 @@ class ObjectHydrator extends AbstractHydrator $value = new ArrayCollection; } - if ($value instanceof ArrayCollection) { + if ( ! $value instanceof PersistentCollection) { $value = new PersistentCollection( $this->_em, $this->_ce[$relation->targetEntityName], diff --git a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php index 8f76d2ec8..325e2ed1c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php @@ -42,10 +42,4 @@ class SingleScalarHydrator extends AbstractHydrator $result = $this->_gatherScalarRowData($result[key($result)], $cache); return array_shift($result); } - - /** {@inheritdoc} */ - protected function _getRowContainer() - { - return array(); - } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index e2280bf80..1bb1b5548 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -120,7 +120,9 @@ abstract class AssociationMapping */ public function __construct(array $mapping) { - $this->_validateAndCompleteMapping($mapping); + if ($mapping) { + $this->_validateAndCompleteMapping($mapping); + } } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index c8ceaef35..74bf53bc2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -183,8 +183,10 @@ class AnnotationDriver implements Driver $mapping['precision'] = $columnAnnot->precision; $mapping['scale'] = $columnAnnot->scale; $mapping['nullable'] = $columnAnnot->nullable; - $mapping['options'] = $columnAnnot->options; $mapping['unique'] = $columnAnnot->unique; + if ($columnAnnot->options) { + $mapping['options'] = $columnAnnot->options; + } if (isset($columnAnnot->default)) { $mapping['default'] = $columnAnnot->default; diff --git a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php index b9a720778..6b377a170 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php @@ -255,4 +255,33 @@ class OneToOneMapping extends AssociationMapping return $targetEntity; } + + /** + * @internal Experimental. For MetaModel API, Doctrine 2.1. + */ + public static function __set_state(array $state) + { + $assoc = new self(array()); + $assoc->isOptional = $state['isOptional']; + $assoc->joinColumnFieldNames = $state['joinColumnFieldNames']; + $assoc->joinColumns = $state['joinColumns']; + $assoc->orphanRemoval = $state['orphanRemoval']; + $assoc->sourceToTargetKeyColumns = $state['sourceToTargetKeyColumns']; + $assoc->targetToSourceKeyColumns = $state['targetToSourceKeyColumns']; + + $assoc->fetchMode = $state['fetchMode']; + $assoc->isCascadeDetach = $state['isCascadeDetach']; + $assoc->isCascadeRefresh = $state['isCascadeRefresh']; + $assoc->isCascadeRemove = $state['isCascadeRemove']; + $assoc->isCascadePersist = $state['isCascadePersist']; + $assoc->isCascadeMerge = $state['isCascadeMerge']; + $assoc->isOwningSide = $state['isOwningSide']; + $assoc->joinTable = $state['joinTable']; + $assoc->mappedByFieldName = $state['mappedByFieldName']; + $assoc->sourceEntityName = $state['sourceEntityName']; + $assoc->targetEntityName = $state['targetEntityName']; + $assoc->sourceFieldName = $state['sourceFieldName']; + + return $assoc; + } } diff --git a/lib/Doctrine/ORM/OptimisticLockException.php b/lib/Doctrine/ORM/OptimisticLockException.php index efcfaeb70..d937daed4 100644 --- a/lib/Doctrine/ORM/OptimisticLockException.php +++ b/lib/Doctrine/ORM/OptimisticLockException.php @@ -30,5 +30,10 @@ namespace Doctrine\ORM; * @since 2.0 * @version $Revision$ */ -class OptimisticLockException extends \Doctrine\Common\DoctrineException -{} \ No newline at end of file +class OptimisticLockException extends ORMException +{ + public static function lockFailed() + { + return new self("The optimistic lock failed."); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index cfbc4ca88..d18326e06 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -256,7 +256,7 @@ class StandardEntityPersister $result = $this->_conn->executeUpdate($sql, $params); if ($isVersioned && ! $result) { - throw \Doctrine\ORM\OptimisticLockException::optimisticLockFailed(); + throw \Doctrine\ORM\OptimisticLockException::lockFailed(); } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 3eaa83cc7..d8ba54ee6 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1344,7 +1344,7 @@ class UnitOfWork implements PropertyChangedListener $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); // Throw exception if versions dont match. if ($managedCopyVersion != $entityVersion) { - throw OptimisticLockException::versionMismatch(); + throw OptimisticLockException::lockFailed(); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 1890f6f2b..a37c71f0c 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -183,7 +183,8 @@ class SchemaTest extends \PHPUnit_Framework_TestCase $schema->visit(new \Doctrine\DBAL\Schema\Visitor\FixSchema(true)); $this->assertEquals(1, count($tableB->getIndexes())); - $index = current($tableB->getIndexes()); + $indexes = $tableB->getIndexes(); + $index = current($indexes); $this->assertTrue($index->hasColumnAtPosition('foo_id', 0)); } } \ No newline at end of file