예제 #1
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;
 }
예제 #2
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']));
     }
 }