/**
  * Validates & completes the mapping. Mapping defaults are applied here.
  *
  * @param array $mapping
  * @throws MappingException If something is wrong with the mapping.
  */
 protected function _validateAndCompleteMapping(array $mapping)
 {
     // Mandatory attributes for both sides
     if (!isset($mapping['fieldName'])) {
         throw MappingException::missingFieldName();
     }
     $this->sourceFieldName = $mapping['fieldName'];
     if (!isset($mapping['sourceEntity'])) {
         throw MappingException::missingSourceEntity($mapping['fieldName']);
     }
     $this->sourceEntityName = $mapping['sourceEntity'];
     if (!isset($mapping['targetEntity'])) {
         throw MappingException::missingTargetEntity($mapping['fieldName']);
     }
     $this->targetEntityName = $mapping['targetEntity'];
     // Mandatory and optional attributes for either side
     if (!isset($mapping['mappedBy'])) {
         // Optional
         if (isset($mapping['joinTable']) && $mapping['joinTable']) {
             if ($mapping['joinTable']['name'][0] == '`') {
                 $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
                 $mapping['joinTable']['quoted'] = true;
             }
             $this->joinTable = $mapping['joinTable'];
         }
         if (isset($mapping['inversedBy'])) {
             $this->inversedBy = $mapping['inversedBy'];
         }
     } else {
         $this->isOwningSide = false;
         $this->mappedBy = $mapping['mappedBy'];
     }
     // Optional attributes for both sides
     $this->fetchMode = isset($mapping['fetch']) ? $mapping['fetch'] : self::FETCH_LAZY;
     $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array();
     if (in_array('all', $cascades)) {
         $cascades = array('remove', 'persist', 'refresh', 'merge', 'detach');
     }
     $this->isCascadeRemove = in_array('remove', $cascades);
     $this->isCascadePersist = in_array('persist', $cascades);
     $this->isCascadeRefresh = in_array('refresh', $cascades);
     $this->isCascadeMerge = in_array('merge', $cascades);
     $this->isCascadeDetach = in_array('detach', $cascades);
 }
예제 #2
0
 /**
  * Validates & completes the given field mapping.
  *
  * @param array $mapping  The field mapping to validated & complete.
  * @return array  The validated and completed field mapping.
  */
 protected function _validateAndCompleteFieldMapping(array &$mapping)
 {
     // Check mandatory fields
     if (!isset($mapping['fieldName'])) {
         throw MappingException::missingFieldName($this->name, $mapping);
     }
     if (!isset($mapping['type'])) {
         // Default to string
         $mapping['type'] = 'string';
     }
     // Complete fieldName and columnName mapping
     if (!isset($mapping['columnName'])) {
         $mapping['columnName'] = $mapping['fieldName'];
     } else {
         if ($mapping['columnName'][0] == '`') {
             $mapping['columnName'] = trim($mapping['columnName'], '`');
             $mapping['quoted'] = true;
         }
     }
     $this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
     if (isset($this->fieldNames[$mapping['columnName']]) || $this->discriminatorColumn != null && $this->discriminatorColumn['name'] == $mapping['columnName']) {
         throw MappingException::duplicateColumnName($this->name, $mapping['columnName']);
     }
     $this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];
     // Complete id mapping
     if (isset($mapping['id']) && $mapping['id'] === true) {
         if (!in_array($mapping['fieldName'], $this->identifier)) {
             $this->identifier[] = $mapping['fieldName'];
         }
         // Check for composite key
         if (!$this->isIdentifierComposite && count($this->identifier) > 1) {
             $this->isIdentifierComposite = true;
         }
     }
 }
예제 #3
0
 /**
  * Validates & completes the mapping. Mapping defaults are applied here.
  *
  * @param array $mapping
  */
 protected function _validateAndCompleteMapping(array $mapping)
 {
     // Mandatory attributes for both sides
     if (!isset($mapping['fieldName'])) {
         throw MappingException::missingFieldName();
     }
     $this->sourceFieldName = $mapping['fieldName'];
     if (!isset($mapping['sourceEntity'])) {
         throw MappingException::missingSourceEntity($mapping['fieldName']);
     }
     $this->sourceEntityName = $mapping['sourceEntity'];
     if (!isset($mapping['targetEntity'])) {
         throw MappingException::missingTargetEntity($mapping['fieldName']);
     }
     $this->targetEntityName = $mapping['targetEntity'];
     // Mandatory and optional attributes for either side
     if (!isset($mapping['mappedBy'])) {
         // Optional
         if (isset($mapping['joinTable'])) {
             $this->joinTable = $mapping['joinTable'];
         }
     } else {
         $this->isOwningSide = false;
         $this->mappedByFieldName = $mapping['mappedBy'];
     }
     // Optional attributes for both sides
     $this->isOptional = isset($mapping['optional']) ? (bool) $mapping['optional'] : true;
     $this->cascades = isset($mapping['cascade']) ? (array) $mapping['cascade'] : array();
     $this->isCascadeDelete = in_array('delete', $this->cascades);
     $this->isCascadeSave = in_array('save', $this->cascades);
     $this->isCascadeRefresh = in_array('refresh', $this->cascades);
     $this->isCascadeMerge = in_array('merge', $this->cascades);
 }