Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function addMetadataFor(\SimpleXMLElement $xmlRoot, MergeableClassMetadata $classMetadata)
 {
     foreach ($xmlRoot->xpath('//cubiche:valueobject') as $item) {
         // get the field tag
         $field = $item->xpath('..')[0];
         $fieldMapping = $this->getMappingAttributes($field);
         $fieldName = $fieldMapping['name'];
         $itemMapping = $this->getMappingAttributes($item);
         foreach ($item->attributes() as $key => $value) {
             $itemMapping[$key] = (string) $value;
         }
         if (!isset($itemMapping['type'])) {
             throw MappingException::inField('The cubiche:valueobject definition should have a "type" value', $classMetadata->name, $fieldName);
         }
         $valueObjectType = $itemMapping['type'];
         if ($field->getName() == 'field') {
             if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) {
                 throw MappingException::inField('The cubiche:valueobject configuration is only for field tags that is not an id', $classMetadata->name, $fieldName);
             }
             if (!isset($fieldMapping['type']) || isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') {
                 throw MappingException::inField('The cubiche:valueobject parent should have a "type" value equal to CubicheType', $classMetadata->name, $fieldName);
             }
             $propertyMetadata = new PropertyMetadata($classMetadata->name, $fieldName, 'valueobject');
             $propertyMetadata->setType($valueObjectType);
             $classMetadata->addPropertyMetadata($propertyMetadata);
         } else {
             throw MappingException::inField('The cubiche:valueobject configuration is only for field tags that is not an id', $classMetadata->name, $fieldName);
         }
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function addMetadataFor(\SimpleXMLElement $xmlRoot, MergeableClassMetadata $classMetadata)
 {
     foreach ($xmlRoot->xpath('//cubiche:collection') as $item) {
         // get the field tag
         $field = $item->xpath('..')[0];
         $fieldMapping = $this->getMappingAttributes($field);
         $fieldName = isset($fieldMapping['name']) ? $fieldMapping['name'] : $fieldMapping['field'];
         $itemMapping = $this->getMappingAttributes($item, array('of' => null));
         if (!isset($itemMapping['type'])) {
             throw MappingException::inField('The cubiche:collection definition should have a "type" value', $classMetadata->name, $fieldName);
         }
         $collectionType = $itemMapping['type'];
         $collectionOf = $itemMapping['of'];
         if ($field->getName() == 'field') {
             if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) {
                 throw MappingException::inField('The cubiche:collection configuration is only for field tags that is not an id', $classMetadata->name, $fieldName);
             }
             if (!isset($fieldMapping['type']) || isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') {
                 throw MappingException::inField('The cubiche:collection parent should have a "type" value equal to CubicheType', $classMetadata->name, $fieldName);
             }
             $propertyMetadata = new CollectionPropertyMetadata($classMetadata->name, $fieldName);
             $propertyMetadata->setType($collectionType);
             $propertyMetadata->setOf($collectionOf);
             $classMetadata->addPropertyMetadata($propertyMetadata);
         } elseif ($field->getName() == 'embed-many' || $field->getName() == 'reference-many') {
             if (isset($fieldMapping['field'])) {
                 $field = $fieldMapping['field'];
             } else {
                 throw MappingException::inField('Cannot infer a field', $classMetadata->name, $fieldName);
             }
             $propertyMetadata = new CollectionPropertyMetadata($classMetadata->name, $field);
             $propertyMetadata->setType($collectionType);
             $classMetadata->addPropertyMetadata($propertyMetadata);
         } else {
             throw MappingException::inField('The cubiche:collection configuration is only for field, embed-many or reference-many tags', $classMetadata->name, $fieldName);
         }
     }
 }
Example #3
0
 /**
  * @param ClassMetadata $classMetadata
  *
  * @throws MappingException
  */
 protected function checkArrayCollectionType(ClassMetadata $classMetadata)
 {
     foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
         if (isset($mapping['embedded']) || isset($mapping['reference'])) {
             continue;
         }
         if (isset($mapping['cubiche:collection'])) {
             $collectionMapping = $mapping['cubiche:collection'];
             if ($collectionMapping['of'] === null) {
                 throw MappingException::inField('The "of" option in ' . $collectionMapping['type'] . ' type is missing', $classMetadata->name, $fieldName);
             }
             $type = $collectionMapping['of'] . $collectionMapping['type'];
             if (!Type::hasType($type)) {
                 Type::addType($type, $collectionMapping['typeClassName']);
                 Type::getType($type)->setInnerType($collectionMapping['of']);
             }
             $classMetadata->fieldMappings[$fieldName]['type'] = $type;
         }
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 protected function addMetadataForType($type, \SimpleXMLElement $xmlRoot, MergeableClassMetadata $classMetadata)
 {
     foreach ($xmlRoot->xpath('//cubiche:' . $type) as $item) {
         // get the field tag
         $field = $item->xpath('..')[0];
         $fieldMapping = $this->getMappingAttributes($field);
         $fieldName = $fieldMapping['name'];
         if ($field->getName() == 'field') {
             if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) {
                 throw MappingException::inField('The cubiche:' . $type . ' configuration is only for field tags that is not an id', $classMetadata->name, $fieldName);
             }
             if (!isset($fieldMapping['type']) || isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') {
                 throw MappingException::inField('The cubiche:' . $type . ' parent should have a "type" value equal to CubicheType', $classMetadata->name, $fieldName);
             }
             $propertyMetadata = new PropertyMetadata($classMetadata->name, $fieldName, $type);
             $classMetadata->addPropertyMetadata($propertyMetadata);
         } else {
             throw MappingException::inField('The cubiche:' . $type . ' configuration is only for id fields', $classMetadata->name, $fieldName);
         }
     }
 }