/**
  * 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 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);
 }