Skip to content

Commit a593b1f

Browse files
committed
Merge pull request #592 from Wepala/field-map-fix
Added getFieldMapping method
2 parents c9507ab + 42933bf commit a593b1f

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use PHPCR\Util\PathHelper;
2727
use ReflectionProperty;
2828
use ReflectionClass;
29+
use Doctrine\ODM\PHPCR\Mapping\MappingException;
2930
use Doctrine\Common\Persistence\Mapping\ReflectionService;
3031
use Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
3132
use Doctrine\Common\ClassLoader;
@@ -1126,14 +1127,11 @@ public function hasField($fieldName)
11261127

11271128
/**
11281129
* {@inheritDoc}
1130+
* @deprecated use getFieldMapping instead
11291131
*/
11301132
public function getField($fieldName)
11311133
{
1132-
if (!$this->hasField($fieldName)) {
1133-
throw MappingException::fieldNotFound($this->name, $fieldName);
1134-
}
1135-
1136-
return $this->mappings[$fieldName];
1134+
return $this->getFieldMapping($fieldName);
11371135
}
11381136

11391137
/**
@@ -1289,7 +1287,7 @@ public function isInheritedField($fieldName)
12891287
*/
12901288
public function isNullable($fieldName)
12911289
{
1292-
$mapping = $this->getField($fieldName);
1290+
$mapping = $this->getFieldMapping($fieldName);
12931291
if ($mapping !== false) {
12941292
return isset($mapping['nullable']) && true == $mapping['nullable'];
12951293
}
@@ -1560,6 +1558,25 @@ public function getFieldValue($document, $field)
15601558
return null;
15611559
}
15621560

1561+
/**
1562+
* Gets the mapping of a (regular) field that holds some data but not a
1563+
* reference to another object.
1564+
*
1565+
* @param string $fieldName The field name.
1566+
*
1567+
* @return array The field mapping.
1568+
*
1569+
* @throws MappingException
1570+
*/
1571+
public function getFieldMapping($fieldName)
1572+
{
1573+
if (!$this->hasField($fieldName)) {
1574+
throw MappingException::fieldNotFound($this->name, $fieldName);
1575+
}
1576+
1577+
return $this->mappings[$fieldName];
1578+
}
1579+
15631580
/**
15641581
* Dispatches the lifecycle event of the given document to the registered
15651582
* lifecycle callbacks and lifecycle listeners.

lib/Doctrine/ODM/PHPCR/Query/Builder/BuilderConverterPhpcr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function getPhpcrProperty($originalAlias, $odmField)
133133
$meta = $this->aliasMetadata[$originalAlias];;
134134

135135
if ($meta->hasField($odmField)) {
136-
$fieldMeta = $meta->getField($odmField);
136+
$fieldMeta = $meta->getFieldMapping($odmField);
137137
} elseif ($meta->hasAssociation($odmField)) {
138138
$fieldMeta = $meta->getAssociation($odmField);
139139
} else {

lib/Doctrine/ODM/PHPCR/UnitOfWork.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ private function executeInserts($documents)
24122412
*/
24132413
private function isAutocreatedProperty(ClassMetadata $class, $fieldName)
24142414
{
2415-
$field = $class->getField($fieldName);
2415+
$field = $class->getFieldMapping($fieldName);
24162416
if ('jcr:uuid' === $field['property']) {
24172417
// jackrabbit at least does not identify this as auto created
24182418
// it is strictly speaking no property

tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testGetAssociationNonexisting(ClassMetadata $cm)
9999
*/
100100
public function testGetFieldNonexisting(ClassMetadata $cm)
101101
{
102-
$cm->getField('nonexisting');
102+
$cm->getFieldMapping('nonexisting');
103103
}
104104

105105
/**

tests/Doctrine/Tests/ODM/PHPCR/Query/Builder/BuilderConverterPhpcrTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function setUp()
4444
->will($me->returnValue(true));
4545

4646
$meta->expects($me->any())
47-
->method('getField')
47+
->method('getFieldMapping')
4848
->will($me->returnCallback(function ($name) {
4949

5050
$res = array(

0 commit comments

Comments
 (0)