Gets the mapping of a (regular) field that holds some data but not a
reference to another object.
public getFieldMapping ( string $fieldName ) : array | ||
$fieldName | string | The field name. |
Résultat | array | The field mapping. |
/** * Assertion shortcut: * Check the given $metadata contain a field mapping for $field that contains the $key and having the value $expectedValue. * @param $expectedValue The expected value * @param \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $metadata The class metadata to test * @param $field The name of the field's mapping to test * @param $key The key expected to be in the field mapping */ protected function assertFieldMetadataEquals($expectedValue, ClassMetadata $metadata, $field, $key) { $mapping = $metadata->getFieldMapping($field); $this->assertInternalType('array', $mapping); $this->assertTrue(array_key_exists($key, $mapping)); $this->assertEquals($expectedValue, $mapping[$key]); }
private function getFieldName(ClassMetadata $metadata) { foreach ($metadata->getFieldNames() as $fieldName) { $field = $metadata->getFieldMapping($fieldName); if ('jcr:lastModified' == $field['property']) { return $fieldName; } } return; }
/** * Identify whether a PHPCR property is autocreated or not. * * @param ClassMetadata $class * @param string $fieldName * * @return boolean */ private function isAutocreatedProperty(ClassMetadata $class, $fieldName) { $field = $class->getFieldMapping($fieldName); if ('jcr:uuid' === $field['property']) { // jackrabbit at least does not identify this as auto created // it is strictly speaking no property return true; } $ntm = $this->session->getWorkspace()->getNodeTypeManager(); $nodeType = $ntm->getNodeType($class->getNodeType()); $propertyDefinitions = $nodeType->getPropertyDefinitions(); foreach ($class->getMixins() as $mixinTypeName) { $nodeType = $ntm->getNodeType($mixinTypeName); $propertyDefinitions = array_merge($propertyDefinitions, $nodeType->getPropertyDefinitions()); } foreach ($propertyDefinitions as $property) { if ($class->mappings[$fieldName]['property'] === $property->getName() && $property->isAutoCreated()) { return true; } } return false; }
/** * @depends testMapFieldWithId * * @expectedException \Doctrine\ODM\PHPCR\Mapping\MappingException */ public function testGetFieldNonexisting(ClassMetadata $cm) { $cm->getFieldMapping('nonexisting'); }