예제 #1
0
 public function testCountShouldBeCorrectAfterAddingEntities()
 {
     $type = new ArticleType();
     $test_entity = $type->createEntity();
     $list = new EntityList([]);
     $list->push($test_entity);
     $list->push($test_entity);
     $entity1 = $list[0];
     $entity2 = $list[1];
     $this->assertEquals($test_entity, $entity1);
     $this->assertEquals($test_entity, $entity2);
     $this->assertCount(2, $list);
     $this->assertTrue(count($list) === 2);
     $this->assertTrue($list->getSize() === 2);
 }
예제 #2
0
 /**
  * Create a EntityList from a given array of entity data.
  *
  * @param array $entities_data
  *
  * @return EntityList
  */
 protected function createEntityList(array $entities_data)
 {
     $type_map = [];
     foreach ($this->getOption(self::OPTION_REFERENCE_MODULES, []) as $type) {
         $type_map[$type->getEntityType()] = $type;
     }
     $collection = new EntityList();
     ksort($entities_data);
     foreach ($entities_data as $entity_data) {
         if (!isset($entity_data[self::OBJECT_TYPE])) {
             $this->throwError('missing_doc_type', [], IncidentInterface::CRITICAL);
             continue;
         }
         $reference_type = $entity_data[self::OBJECT_TYPE];
         unset($entity_data['@type']);
         if ($reference_type[0] !== '\\') {
             $reference_type = '\\' . $reference_type;
         }
         if (!isset($type_map[$reference_type])) {
             $this->throwError('invalid_doc_type', array('type' => @$entity_data[self::OBJECT_TYPE]), IncidentInterface::NOTICE);
             continue;
         }
         $reference_type = $type_map[$reference_type];
         $collection->push($reference_type->createEntity($entity_data));
     }
     return $collection;
 }
예제 #3
0
 /**
  * Create a EntityList from a given array of entity data.
  *
  * @param array $entities_data
  *
  * @return EntityList
  */
 protected function createEntityList(array $entities_data, EntityList $list, EntityInterface $parent_entity = null)
 {
     $success = true;
     $embedded_entity_type_map = $this->getOption(self::OPTION_ENTITY_TYPES, new EntityTypeMap());
     foreach ($entities_data as $embedded_entity_data) {
         if (!isset($embedded_entity_data[self::OBJECT_TYPE])) {
             $success = false;
             $this->throwError('missing_embed_prefix', [], IncidentInterface::CRITICAL);
             continue;
         }
         $embed_prefix = $embedded_entity_data[self::OBJECT_TYPE];
         if (!$embedded_entity_type_map->hasKey($embed_prefix)) {
             //var_dump(array_keys($type_map), $trimmed_embed_type);exit;
             $success = false;
             $this->throwError('invalid_embed_prefix', ['type' => var_export($embedded_entity_data[self::OBJECT_TYPE], true)], IncidentInterface::CRITICAL);
             continue;
         }
         unset($embedded_entity_data['@type']);
         $embedded_type = $embedded_entity_type_map->getItem($embed_prefix);
         $list->push($embedded_type->createEntity($embedded_entity_data, $parent_entity));
     }
     return $success;
 }