public function testToArray()
 {
     $structure = new \databox_descriptionStructure();
     $array = ['name1' => 'value1', 'name2' => 'value2'];
     $element = $this->provideDataboxFieldMock();
     $element->expects($this->once())->method('toArray')->will($this->returnValue($array));
     $structure->add_element($element);
     $this->assertEquals([$array], $structure->toArray());
 }
Example #2
0
 /**
  *
  * @return databox_descriptionStructure
  */
 public function get_meta_structure()
 {
     if ($this->meta_struct) {
         return $this->meta_struct;
     }
     try {
         $metaStructData = $this->get_data_from_cache(self::CACHE_META_STRUCT);
     } catch (\Exception $e) {
         $sql = 'SELECT id, `name` FROM metadatas_structure ORDER BY sorter ASC';
         $stmt = $this->get_connection()->prepare($sql);
         $stmt->execute();
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         if ($rs) {
             $metaStructData = $rs;
             $this->set_data_to_cache($metaStructData, self::CACHE_META_STRUCT);
         }
     }
     $this->meta_struct = new databox_descriptionStructure();
     if ($metaStructData) {
         foreach ($metaStructData as $row) {
             $this->meta_struct->add_element(databox_field::get_instance($this->app, $this, $row['id']));
         }
     }
     return $this->meta_struct;
 }
Example #3
0
 protected function readXMLForDatabox(Application $app, \databox_descriptionStructure $metadatasStructure, $pathfile)
 {
     if (false === $app['filesystem']->exists($pathfile)) {
         throw new \InvalidArgumentException(sprintf('file %s does not exists', $pathfile));
     }
     if (false === ($sxcaption = @simplexml_load_file($pathfile))) {
         throw new \InvalidArgumentException(sprintf('Invalid XML file %s', $pathfile));
     }
     $metadataBag = new MetaFieldsBag();
     foreach ($sxcaption->description->children() as $tagname => $field) {
         $field = trim($field);
         $meta = $metadatasStructure->get_element_by_name(trim($tagname));
         if (!$meta) {
             continue;
         }
         if ($meta->is_multi()) {
             $fields = caption_field::get_multi_values($field, $meta->get_separator());
             if (!$metadataBag->containsKey($meta->get_name())) {
                 $values = $fields;
             } else {
                 $values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields);
             }
             $metadataBag->set($meta->get_name(), new BorderAttribute\MetaField($meta, $values));
         } else {
             $metadataBag->set($meta->get_name(), new BorderAttribute\MetaField($meta, [$field]));
         }
     }
     return $metadataBag;
 }
Example #4
0
 private function validateNameField(\databox_descriptionStructure $metaStructure, array $field)
 {
     if (null !== $metaStructure->get_element_by_name($field['name'])) {
         throw new BadRequestHttpException(sprintf('Field %s already exists.', $field['name']));
     }
 }