Example #1
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $validator = new Validator();
     $reflClass = $this->getMetaReflectionClass($meta);
     foreach ($reflClass->getProperties() as $reflProperty) {
         if ($referenceIntegrity = $this->reader->getPropertyAnnotation($reflProperty, self::REFERENCE_INTEGRITY)) {
             $property = $reflProperty->getName();
             if (!$meta->hasField($property)) {
                 throw new InvalidMappingException(sprintf("Unable to find reference integrity [%s] as mapped property in entity - %s", $property, $meta->name));
             }
             $fieldMapping = $meta->getFieldMapping($property);
             if (!isset($fieldMapping['mappedBy'])) {
                 throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->name));
             }
             if (!in_array($referenceIntegrity->value, $validator->getIntegrityActions())) {
                 throw new InvalidMappingException(sprintf("Field - [%s] does not have a valid integrity option, [%s] in class - %s", $property, implode($validator->getIntegrityActions(), ', '), $meta->name));
             }
             $config['referenceIntegrity'][$property] = $referenceIntegrity->value;
         }
     }
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata($meta, array &$config)
 {
     $mapping = $this->_getMapping($meta->name);
     $validator = new Validator();
     if (isset($mapping['fields'])) {
         foreach ($mapping['fields'] as $property => $fieldMapping) {
             if (isset($fieldMapping['gedmo']['referenceIntegrity'])) {
                 if (!$meta->hasField($property)) {
                     throw new InvalidMappingException(sprintf("Unable to find reference integrity [%s] as mapped property in entity - %s", $property, $meta->name));
                 }
                 if (empty($mapping['fields'][$property]['mappedBy'])) {
                     throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->name));
                 }
                 if (!in_array($fieldMapping['gedmo']['referenceIntegrity'], $validator->getIntegrityActions())) {
                     throw new InvalidMappingException(sprintf("Field - [%s] does not have a valid integrity option, [%s] in class - %s", $property, implode($validator->getIntegrityActions(), ', '), $meta->name));
                 }
                 $config['referenceIntegrity'][$property][$mapping['fields'][$property]['mappedBy']] = $fieldMapping['gedmo']['referenceIntegrity'];
             }
         }
     }
 }