Doctrine\ODM\CouchDB\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 - jsonName - JSON key name of this field in CouchDB. - name - The JSON key of this field in the CouchDB document - id - True for an ID field. - strategy - ID Generator strategy when the field is an id-field. - indexed - Is this field indexed for the Doctrine CouchDB repository view - isVersionField - Is this field containing the revision number of this document?
public mapField ( array $mapping )
$mapping array The mapping information.
    public function mapField(array $mapping)
    {
        $mapping = $this->validateAndCompleteFieldMapping($mapping);
        if (!isset($mapping['type'])) {
            $mapping['type'] = "mixed";
        }
        if (isset($mapping['id']) && $mapping['id'] === true) {
            $mapping['type'] = 'string';
            $mapping['jsonName'] = '_id';
            $this->setIdentifier($mapping['fieldName']);
            if (isset($mapping['strategy'])) {
                $this->idGenerator = constant('Doctrine\\ODM\\CouchDB\\Mapping\\ClassMetadata::IDGENERATOR_' . strtoupper($mapping['strategy']));
                unset($mapping['strategy']);
            }
        } else {
            if (isset($mapping['isVersionField'])) {
                $this->isVersioned = true;
                $this->versionField = $mapping['fieldName'];
            }
        }
        $mapping = $this->checkAndStoreIndexMapping($mapping);
        $this->fieldMappings[$mapping['fieldName']] = $mapping;
        $this->jsonNames[$mapping['jsonName']] = $mapping['fieldName'];
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /* @var $xmlRoot SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     if ($xmlRoot->getName() == "document") {
         $class->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
         if (isset($xmlRoot['indexed']) && $xmlRoot['indexed'] == true) {
             $class->indexed = true;
         }
     } else {
         if ($xmlRoot->getName() == "embedded-document") {
             $class->isEmbeddedDocument = true;
         } else {
             if ($xmlRoot->getName() == "mapped-superclass") {
                 $class->isMappedSuperclass = true;
             } else {
                 throw MappingException::classIsNotAValidDocument($className);
             }
         }
     }
     // Evaluate <field ...> mappings
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $fieldMapping) {
             $class->mapField(array('fieldName' => (string) $fieldMapping['name'], 'jsonName' => isset($fieldMapping['json-name']) ? (string) $fieldMapping['json-name'] : null, 'indexed' => isset($fieldMapping['index']) ? (bool) $fieldMapping['index'] : false, 'type' => isset($fieldMapping['type']) ? (string) $fieldMapping['type'] : null, 'isVersionField' => isset($fieldMapping['version']) ? true : null));
         }
     }
     // Evaluate <id ..> mappings
     foreach ($xmlRoot->id as $idElement) {
         $class->mapField(array('fieldName' => (string) $idElement['name'], 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? (string) $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? (string) $idElement['strategy'] : null));
     }
     // Evaluate <many-to-one ..> mappings
     if (isset($xmlRoot->{"reference-one"})) {
         foreach ($xmlRoot->{"reference-one"} as $referenceOneElement) {
             $class->mapManyToOne(array('cascade' => isset($referenceManyElement->cascade) ? $this->getCascadeMode($referenceManyElement->cascade) : 0, 'targetDocument' => (string) $referenceOneElement['target-document'], 'fieldName' => (string) $referenceOneElement['field'], 'jsonName' => isset($referenceOneElement['json-name']) ? (string) $referenceOneElement['json-name'] : null));
         }
     }
     // Evaluate <many-to-one ..> mappings
     if (isset($xmlRoot->{"reference-many"})) {
         foreach ($xmlRoot->{"reference-many"} as $referenceManyElement) {
             $class->mapManyToMany(array('cascade' => isset($referenceManyElement->cascade) ? $this->getCascadeMode($referenceManyElement->cascade) : 0, 'targetDocument' => (string) $referenceManyElement['target-document'], 'fieldName' => (string) $referenceManyElement['field'], 'jsonName' => isset($referenceManyElement['json-name']) ? (string) $referenceManyElement['json-name'] : null, 'mappedBy' => isset($referenceManyElement['mapped-by']) ? (string) $referenceManyElement['mapped-by'] : null));
         }
     }
     // Evaluate <attachments ..> mapping
     if (isset($xmlRoot->{"attachments"})) {
         $class->mapAttachments((string) $xmlRoot->{"attachments"}[0]['field']);
     }
     // Evaluate <embed-one />
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $embedOneElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['target-document'], 'fieldName' => (string) $embedOneElement['field'], 'jsonName' => isset($embedOneElement['json-name']) ? (string) $embedOneElement['json-name'] : null, 'embedded' => 'one'));
         }
     }
     // Evaluate <embed-many />
     if (isset($xmlRoot->{'embed-many'})) {
         foreach ($xmlRoot->{'embed-many'} as $embedManyElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['target-document'], 'fieldName' => (string) $embedManyElement['field'], 'jsonName' => isset($embedManyElement['json-name']) ? (string) $embedManyElement['json-name'] : null, 'embedded' => 'many'));
         }
     }
 }
All Usage Examples Of Doctrine\ODM\CouchDB\Mapping\ClassMetadata::mapField