/** * Validates entity attributes on the AttributeInterface. * * @param AttributeInterface $metadata * @param MetadataFactory $mf * @return bool * @throws MetadataException */ public function validateMetadataAttributes(AttributeInterface $metadata, MetadataFactory $mf) { $type = $metadata instanceof EntityMetadata ? $metadata->type : (property_exists($metadata, 'name') ? $metadata->name : ''); foreach ($metadata->getAttributes() as $key => $attribute) { if ($key != $attribute->key) { throw MetadataException::invalidMetadata($type, sprintf('Attribute key mismtach. "%s" !== "%s"', $key, $attribute->key)); } if (false === $this->isFieldKeyValid($attribute->key)) { throw MetadataException::invalidMetadata($type, sprintf('The attribute key "%s" is invalid based on the configured name format "%s"', $attribute->key, $this->config->getFieldKeyFormat())); } if (false === $this->typeFactory->hasType($attribute->dataType)) { throw MetadataException::invalidMetadata($type, sprintf('The data type "%s" for attribute "%s" is invalid', $attribute->dataType, $attribute->key)); } if ($metadata instanceof EntityMetadata && true === $metadata->isChildEntity()) { $parent = $mf->getMetadataForType($metadata->extends); if ($parent->hasAttribute($attribute->key)) { throw MetadataException::invalidMetadata($type, sprintf('Parent entity type "%s" already contains attribute field "%s"', $parent->type, $attribute->key)); } } if (true === $attribute->isCalculated()) { if (false === class_exists($attribute->calculated['class']) || false === method_exists($attribute->calculated['class'], $attribute->calculated['method'])) { throw MetadataException::invalidMetadata($type, sprintf('The attribute field "%s" is calculated, but was unable to find method "%s:%s"', $attribute->key, $attribute->calculated['class'], $attribute->calculated['method'])); } } } return true; }
/** * Converts an attribute value to the proper Modlr data type. * * @param string $dataType The data type, such as string, integer, boolean, etc. * @param mixed $value The value to convert. * @return mixed */ public function convertAttributeValue($dataType, $value) { return $this->typeFactory->convertToModlrValue($dataType, $value); }