diff --git a/Doctrine/Hydration/DoctrineValueHydrator.php b/Doctrine/Hydration/DoctrineValueHydrator.php index 32e60010..d39efda9 100644 --- a/Doctrine/Hydration/DoctrineValueHydrator.php +++ b/Doctrine/Hydration/DoctrineValueHydrator.php @@ -16,19 +16,11 @@ public function mapValue($fieldName, $value, MetaInformationInterface $metaInfor return false; } + // is object with getter if ($metaInformation->getField($fieldName) && $metaInformation->getField($fieldName)->getter) { return false; } - $fieldSuffix = $this->removePrefixedKeyValues($fieldName); - if ($fieldSuffix === false) { - return false; - } - - if (array_key_exists($fieldSuffix, Field::getComplexFieldMapping())) { - return false; - } - return true; } diff --git a/Doctrine/Hydration/ValueHydrator.php b/Doctrine/Hydration/ValueHydrator.php index ed061234..cb25adce 100644 --- a/Doctrine/Hydration/ValueHydrator.php +++ b/Doctrine/Hydration/ValueHydrator.php @@ -76,7 +76,7 @@ protected function removeFieldSuffix($property) protected function removePrefixedKeyValues($value) { if (($pos = strrpos($value, '_')) !== false) { - return substr($value, ($pos+1)); + return substr($value, ($pos + 1)); } return $value; @@ -101,6 +101,12 @@ private function toCamelCase($fieldname) } /** + * Check if given field and value can be mapped + * + * @param string $fieldName + * @param string $value + * @param MetaInformationInterface $metaInformation + * * @return bool */ public function mapValue($fieldName, $value, MetaInformationInterface $metaInformation) diff --git a/Tests/Doctrine/Hydration/DoctrineHydratorTest.php b/Tests/Doctrine/Hydration/DoctrineHydratorTest.php index 35206084..97ee7b26 100644 --- a/Tests/Doctrine/Hydration/DoctrineHydratorTest.php +++ b/Tests/Doctrine/Hydration/DoctrineHydratorTest.php @@ -4,6 +4,7 @@ use FS\SolrBundle\Doctrine\Annotation\AnnotationReader; +use FS\SolrBundle\Doctrine\Annotation\Field; use FS\SolrBundle\Doctrine\Hydration\DoctrineHydrator; use FS\SolrBundle\Doctrine\Hydration\DoctrineHydratorInterface; use FS\SolrBundle\Doctrine\Hydration\DoctrineValueHydrator; diff --git a/Tests/Doctrine/Hydration/DoctrineValueHydratorTest.php b/Tests/Doctrine/Hydration/DoctrineValueHydratorTest.php new file mode 100644 index 00000000..e4c3a26a --- /dev/null +++ b/Tests/Doctrine/Hydration/DoctrineValueHydratorTest.php @@ -0,0 +1,55 @@ +assertFalse($hydrator->mapValue('createdAt', array(), new MetaInformation())); + } + + /** + * @test + */ + public function skipObjects() + { + $hydrator = new DoctrineValueHydrator(); + + $field = new Field(array('type' => 'datetime')); + $field->name = 'createdAt'; + $field->getter = 'format(\'Y-m-d\TH:i:s.z\Z\')'; + + $metaInformation = new MetaInformation(); + $metaInformation->setFields(array($field)); + + $this->assertFalse($hydrator->mapValue('createdAt', new \DateTime(), $metaInformation)); + } + + /** + * @test + */ + public function mapCommonType() + { + $hydrator = new DoctrineValueHydrator(); + + $field = new Field(array('type' => 'string')); + $field->name = 'title'; + + $metaInformation = new MetaInformation(); + $metaInformation->setFields(array($field)); + + $this->assertTrue($hydrator->mapValue('title_s', 'a title', $metaInformation)); + } +}