/** * {@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); } } }
private function doAddPropertyMetadata(PsiPropertyMetadata $metadata) { parent::addPropertyMetadata($metadata); if (!$metadata->getRole()) { return; } if (isset($this->roles[$metadata->getRole()])) { $propertyName = $this->roles[$metadata->getRole()]; throw new \InvalidArgumentException(sprintf('Role "%s" has already been assigned to property "%s" (on property "%s")', $metadata->getRole(), $propertyName, $metadata->getName())); } $this->roles[$metadata->getRole()] = $metadata->name; }
public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new MergeableClassMetadata($class->getName()); foreach ($class->getProperties() as $property) { $field = $this->reader->getPropertyAnnotation($property, self::MOGRIFY); if (!is_null($field)) { $propertyMetadata = new MogrifyMetadata($class->getName(), $property->getName()); $propertyMetadata->params = $field->params; $classMetadata->addPropertyMetadata($propertyMetadata); } } return $classMetadata; }
/** * {@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); } } }
public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new MergeableClassMetadata($class->getName()); foreach ($class->getProperties() as $reflectionProperty) { $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName()); $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Tapir\\AnnotationBundle\\Annotation\\Descripcion'); if (null !== $annotation) { // Un @Descripcion fue encontrado $propertyMetadata->descripcion = $annotation->value; } $classMetadata->addPropertyMetadata($propertyMetadata); } return $classMetadata; }
/** * {@inheritdoc} */ protected function loadMetadataFromFile(\ReflectionClass $class, $file) { $classMetadata = new MergeableClassMetadata($class->getName()); // load xml file // TODO xsd validation $xmlDoc = XmlUtils::loadFile($file); $xpath = new \DOMXPath($xmlDoc); $xpath->registerNamespace('x', 'http://schemas.sulu.io/class/general'); $xpath->registerNamespace('list', 'http://schemas.sulu.io/class/list'); foreach ($xpath->query('/x:class/x:properties/x:*') as $propertyNode) { $classMetadata->addPropertyMetadata($this->getPropertyMetadata($xpath, $propertyNode, $class->getName())); } return $classMetadata; }
/** * {@inheritdoc} */ public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new MergeableClassMetadata($class->getName()); foreach ($class->getProperties() as $reflectionProperty) { $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName()); /** @var \Integrated\Bundle\SlugBundle\Mapping\Annotations\Slug $annotation */ $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Integrated\\Bundle\\SlugBundle\\Mapping\\Annotations\\Slug'); if (null !== $annotation) { $propertyMetadata->slugFields = $annotation->fields; $propertyMetadata->slugSeparator = $annotation->separator; } $classMetadata->addPropertyMetadata($propertyMetadata); } return $classMetadata; }
/** * {@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); } } }
public function addPropertyMetadata(BasePropertyMetadata $metadata) { parent::addPropertyMetadata($metadata); $this->sortProperties(); }