Doctrine\ODM\PHPCR\Mapping\ClassMetadata::mapField PHP Method

mapField() public method

- type - The Doctrine Type of this field. - fieldName - The name of the property/field on the mapped php class - name - The Property key of this field in the PHPCR document - id - True for an ID field.
public mapField ( array $mapping, ClassMetadata $inherited = null )
$mapping array The mapping information.
$inherited ClassMetadata
    public function mapField(array $mapping, ClassMetadata $inherited = null)
    {
        $parentMapping = isset($mapping['fieldName']) && isset($this->mappings[$mapping['fieldName']]) ? $this->mappings[$mapping['fieldName']] : null;
        if (!$inherited) {
            if (isset($mapping['id']) && $mapping['id'] === true) {
                $mapping['type'] = 'string';
                $this->setIdentifier($mapping['fieldName']);
                if (isset($mapping['strategy'])) {
                    $this->setIdGenerator($mapping['strategy']);
                }
            } elseif (isset($mapping['uuid']) && $mapping['uuid'] === true) {
                $mapping['type'] = 'string';
                $mapping['property'] = 'jcr:uuid';
            }
            if (isset($parentMapping['type'])) {
                if (isset($mapping['type']) && $parentMapping['type'] !== $mapping['type']) {
                    throw new MappingException("You cannot change the type of a field via inheritance in '{$this->name}'");
                }
                $mapping['type'] = $parentMapping['type'];
            }
        }
        if (isset($mapping['property']) && $mapping['property'] == 'jcr:uuid') {
            if (null !== $this->uuidFieldName) {
                throw new MappingException("You can only designate a single 'Uuid' field in '{$this->name}'");
            }
            $this->uuidFieldName = $mapping['fieldName'];
        }
        if (!$inherited) {
            if (isset($parentMapping['multivalue'])) {
                $mapping['multivalue'] = $parentMapping['multivalue'];
                if (isset($parentMapping['assoc'])) {
                    $mapping['assoc'] = $parentMapping['assoc'];
                }
            } elseif (!isset($mapping['multivalue'])) {
                $mapping['multivalue'] = false;
            }
            if (!isset($mapping['nullable'])) {
                $mapping['nullable'] = isset($parentMapping['nullable']) ? $parentMapping['nullable'] : false;
            }
        }
        // Add the field to the list of translatable fields
        if (!empty($parentMapping['translated']) || !empty($mapping['translated'])) {
            $mapping['translated'] = true;
        }
        $mapping = $this->validateAndCompleteFieldMapping($mapping, $inherited);
        // Add the field to the list of translatable fields
        if (!empty($mapping['translated']) && !in_array($mapping['fieldName'], $this->translatableFields)) {
            $this->translatableFields[] = $mapping['fieldName'];
        }
        if (!$parentMapping) {
            $this->fieldMappings[] = $mapping['fieldName'];
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function setUp()
 {
     if (!class_exists('Jackalope\\Factory', true)) {
         $this->markTestSkipped('The Node needs to be properly mocked/stubbed. Remove dependency to Jackalope');
     }
     $this->factory = new Factory();
     $this->session = $this->getMock('Jackalope\\Session', array(), array($this->factory), '', false);
     $this->objectManager = $this->getMock('Jackalope\\ObjectManager', array(), array($this->factory), '', false);
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\UoWUser';
     $this->dm = DocumentManager::create($this->session);
     $this->uow = new UnitOfWork($this->dm);
     $cmf = $this->dm->getMetadataFactory();
     $metadata = new ClassMetadata($this->type);
     $metadata->initializeReflection($cmf->getReflectionService());
     $metadata->mapId(array('fieldName' => 'id', 'id' => true));
     $metadata->idGenerator = ClassMetadata::GENERATOR_TYPE_ASSIGNED;
     $metadata->mapField(array('fieldName' => 'username', 'type' => 'string'));
     $cmf->setMetadataFor($this->type, $metadata);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\Mapping\ClassMetadata::mapField
ClassMetadata