Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function validateAttribute(AttributeMetadata $attribute)
 {
     if (true === $this->hasRelationship($attribute->getKey())) {
         throw MetadataException::fieldKeyInUse('attribute', 'relationship', $attribute->getKey(), $this->name);
     }
     if (true === $this->hasEmbed($attribute->getKey())) {
         throw MetadataException::fieldKeyInUse('attribute', 'embed', $attribute->getKey(), $this->name);
     }
 }
Example #2
0
 /**
  * Sets the entity attribute metadata from the metadata mapping.
  *
  * @param   Metadata\Interfaces\AttributeInterface  $metadata
  * @param   array                                   $attrMapping
  * @return  Metadata\EntityMetadata
  */
 protected function setAttributes(Metadata\Interfaces\AttributeInterface $metadata, array $attrMapping)
 {
     foreach ($attrMapping as $key => $mapping) {
         if (!is_array($mapping)) {
             $mapping = ['type' => null];
         }
         if (!isset($mapping['type'])) {
             $mapping['type'] = null;
         }
         if (!isset($mapping['search'])) {
             $mapping['search'] = [];
         }
         $attribute = new Metadata\AttributeMetadata($key, $mapping['type'], $this->isMixin($metadata));
         if (isset($mapping['description'])) {
             $attribute->description = $mapping['description'];
         }
         if (isset($mapping['defaultValue'])) {
             $attribute->defaultValue = $mapping['defaultValue'];
         }
         if (isset($mapping['calculated']) && is_array($mapping['calculated'])) {
             $calculated = $mapping['calculated'];
             if (isset($calculated['class']) && isset($calculated['method'])) {
                 $attribute->calculated['class'] = $calculated['class'];
                 $attribute->calculated['method'] = $calculated['method'];
             }
         }
         if (isset($mapping['search']['autocomplete'])) {
             $attribute->setAutocomplete(true);
         } else {
             if (isset($mapping['search']['store'])) {
                 $attribute->setSearchProperty(true);
             }
         }
         if (isset($mapping['save'])) {
             $attribute->enableSave($mapping['save']);
         }
         if (isset($mapping['serialize'])) {
             $attribute->enableSerialize($mapping['serialize']);
         }
         $metadata->addAttribute($attribute);
     }
     return $metadata;
 }