Example #1
0
 /**
  * This method returns the field for the specified data format.
  *
  * @access public
  * @static
  * @param MappingService\Data\Field $field                  the data field to store the items
  * @param Core\Data\XML $translation                        the translation to be parsed
  */
 public static function translate(MappingService\Data\Field $field, Core\Data\XML $translation)
 {
     $format = $field->getFormatType()->__name();
     $nodes = $translation->xpath("./Field[@Format='{$format}']");
     if (!empty($nodes)) {
         $children = $nodes[0]->children();
         if (count($children) > 0) {
             foreach ($children as $child) {
                 $name = $child->getName();
                 if ($name == 'Item') {
                     $attributes = $child->attributes();
                     if (isset($attributes['Name'])) {
                         $key = Core\Data\XML::valueOf($attributes['Name']);
                         $value = Core\Data\XML::valueOf($child[0]);
                         if (isset($attributes['Type'])) {
                             $type = Core\Data\XML::valueOf($attributes['Type']);
                             if (!(is_string($type) && preg_match('/^(bool(ean)?|int(eger)?|float|string)$/i', $type))) {
                                 $type = 'string';
                             }
                             settype($value, $type);
                         } else {
                             settype($value, 'string');
                         }
                         $field->putItem($key, $value);
                     }
                 }
             }
         }
     }
 }