Ejemplo n.º 1
0
 /**
  * Validates entity attributes on EntityMetadata.
  *
  * @param   EntityMetadata  $metadata
  * @param   MetadataFactory $mf
  * @return  bool
  * @throws  MetadataException
  */
 public function validateMetadataAttributes(EntityMetadata $metadata, MetadataFactory $mf)
 {
     foreach ($metadata->getAttributes() as $key => $attribute) {
         if ($key != $attribute->key) {
             throw MetadataException::invalidMetadata($metadata->type, sprintf('Attribute key mismtach. "%s" !== "%s"', $key, $attribute->key));
         }
         if (false === $this->isFieldKeyValid($attribute->key)) {
             throw MetadataException::invalidMetadata($metadata->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($metadata->type, sprintf('The data type "%s" for attribute "%s" is invalid', $attribute->dataType, $attribute->key));
         }
         if (true === $metadata->isChildEntity()) {
             $parent = $mf->getMetadataForType($metadata->extends);
             if ($parent->hasAttribute($attribute->key)) {
                 throw MetadataException::invalidMetadata($metadata->type, sprintf('Parent entity type "%s" already contains attribute field "%s"', $parent->type, $attribute->key));
             }
         }
         // @todo Determine how to validate object and array
         $todo = ['object', 'array'];
         if (in_array($attribute->dataType, $todo)) {
             throw MetadataException::invalidMetadata($metadata->type, 'NYI: Object and array attribute types still need expanding!!');
         }
         if (true === $attribute->isCalculated()) {
             if (false === class_exists($attribute->calculated['class']) || false === method_exists($attribute->calculated['class'], $attribute->calculated['method'])) {
                 throw MetadataException::invalidMetadata($metadata->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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }