Example #1
0
 public static function getAttributeValueByPath(EntityInterface $entity, $value_path)
 {
     if (!mb_strpos($value_path, self::PATH_DELIMITER)) {
         return $entity->getValue($value_path);
     }
     // prepare path tuples
     $split_path = self::splitPath($value_path);
     $path_tuples = $split_path['path_tuples'];
     $target_attribute = $split_path['target_attribute'];
     $current_type = $entity->getType();
     $current_entity = $entity;
     // loop into path
     foreach ($path_tuples as $path_tuple) {
         $offset_spec = self::parseOffsetExpression($path_tuple[1]);
         $current_attribute = $current_type->getAttribute($path_tuple[0]);
         $entity_collection = $current_entity->getValue($current_attribute->getName());
         // try to find the next entity that matches the current offset_spec
         $type_offsets = array('_all' => 0);
         $current_entity = null;
         foreach ($entity_collection as $next_entity) {
             $type_prefix = $next_entity->getType()->getPrefix();
             if (!isset($type_offsets[$type_prefix])) {
                 $type_offsets[$type_prefix] = 0;
             }
             if (self::entityMatchesOffsetSpec($next_entity, $offset_spec, $type_offsets)) {
                 $current_entity = $next_entity;
                 break;
             }
             $type_offsets['_all']++;
             $type_offsets[$type_prefix]++;
         }
         // the value_path/offset_spec is valid, but doesn't match any entities in question
         if (!$current_entity) {
             return null;
         }
         // prepare for next iteration by switching the current_type to the next level
         if ($current_attribute instanceof EmbeddedEntityListAttribute) {
             $current_type = $current_attribute->getEmbeddedTypeByPrefix($offset_spec['entity_type']);
         } else {
             throw new RuntimeException('Invalid attribute-type given within attribute-value-path.' . 'Only Reference- and EmbeddedEntityListAttributes are supported.');
         }
     }
     return $target_attribute ? $current_entity->getValue($target_attribute) : $current_entity;
 }
Example #2
0
 /**
  * Tells whether this entity is considered equal to another given entity.
  * Entities are equal when they have the same type and values.
  *
  * @param EntityInterface $entity
  *
  * @return boolean true on both entities have the same type and values; false otherwise.
  */
 public function isEqualTo(EntityInterface $entity)
 {
     if ($entity->getType() !== $this->getType()) {
         return false;
     }
     if ($this->getType()->getAttributes()->getSize() !== $this->value_holder_map->getSize()) {
         return false;
     }
     foreach ($this->getType()->getAttributes()->getKeys() as $attribute_name) {
         $value_holder = $this->value_holder_map->getItem($attribute_name);
         if (!$value_holder->sameValueAs($entity->getValue($attribute_name))) {
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * Transform the entity value, which is described by the given attributespec,
  * to it's output representation.
  *
  * @param EntityInterface $entity
  * @param SpecificationInterface $specification
  *
  * @return mixed
  */
 public function apply(EntityInterface $entity, SpecificationInterface $specification)
 {
     $attribute_name = $specification->getOption('attribute', $specification->getName());
     $entity_value = $entity->getValue($attribute_name);
     return $entity_value;
 }
Example #4
0
 protected function onEmbeddedEntityRemoved(EntityInterface $projection, EmbeddedEntityRemovedEvent $event)
 {
     $projection_list = $projection->getValue($event->getParentAttributeName());
     $projection_to_remove = null;
     foreach ($projection_list as $embedded_projection) {
         if ($embedded_projection->getIdentifier() === $event->getEmbeddedEntityIdentifier()) {
             $projection_to_remove = $embedded_projection;
         }
     }
     if ($projection_to_remove) {
         $projection_list->removeItem($projection_to_remove);
     }
 }