public function flatten(Metadata $metadata)
 {
     $flatTags = [];
     foreach ($metadata->getFlattenedMetadata() as $key => $value) {
         $flatTags[] = $key . ':' . $value;
     }
     return $flatTags;
 }
 /**
  * `Simple` mapping rules assume that { "patternPath" : "tagType:tagName" }
  */
 public function mapTagsSimple(Metadata $metadata, $inputRules)
 {
     $rules = $this->buildAndValidateRules($inputRules);
     $convertedTags = [];
     foreach ($rules as $pathPattern => $rule) {
         $matches = $metadata->matchAndRemoveByKey($pathPattern);
         foreach ($matches as $key => $value) {
             $value = $value['value'];
             // Yap this guy got matched so let's fix convert it to tags
             $tagTypeRule = $rule['tagTypeRule'];
             $tagNameRule = $rule['tagNameRule'];
             // Build the tag name by replacing '{{value}}' at the rule with the actual value
             $tagName = str_replace('{{value}}', $value, $tagNameRule);
             // And simply match use the tag type rule as dah` tag type ~ simple :)
             $tagType = $tagTypeRule;
             // Let's save it!
             $convertedTags[$tagType][] = $tagName;
             $touchedFlatTagsKey[] = $key;
         }
     }
     return [$convertedTags, $metadata];
 }
Exemplo n.º 3
0
 public function convert(Metadata $metadata, $rules = [])
 {
     // Shall we trim?
     $trim = isset($rules['trim']) ? $rules['trim'] : true;
     if ($trim == true) {
         $metadata->trimValues();
     }
     // Shall we include unmapped metadata?
     $includeUnmapped = isset($rules['includeUnmapped']) ? $rules['includeUnmapped'] : true;
     // Lets do mapping!
     $convertedTags = [];
     // TODO: Some mapping hack, need proper test and tidy up also proper JSON validation
     // Do `simple` mapping
     if (!$metadata->isEmpty() && isset($rules['rules']['simple'])) {
         $simpleRules = $rules['rules']['simple'];
         $engine = new SimpleMetadataEngine();
         list($convertedTags, $metadata) = $engine->mapTagsSimple($metadata, $simpleRules);
     }
     // TODO: Some mapping hack, need proper test and tidy up also proper JSON validation
     // Do `valueMap` mapping
     if (!$metadata->isEmpty() && isset($rules['rules']['valueMap'])) {
         $valueMapRules = $rules['rules']['valueMap'];
         $engine = new ValueMapEngine();
         list($valueMapTags, $metadata) = $engine->mapValueMap($metadata, $valueMapRules);
         $convertedTags = array_merge_recursive($convertedTags, $valueMapTags);
     }
     // Fix the rest with dah default `flat` mapping
     if (!$metadata->isEmpty() && $includeUnmapped === true) {
         $engine = new FlatMetadataEngine();
         $otherTags = ['IMSMDMetadata' => $engine->flatten($metadata)];
         $convertedTags = array_merge_recursive($convertedTags, $otherTags);
     }
     // Avoid duplication
     foreach ($convertedTags as &$tags) {
         $tags = array_values(array_unique($tags));
     }
     return $convertedTags;
 }
Exemplo n.º 4
0
 public function mapValueMap(Metadata $metadata, array $rules = [])
 {
     $rules = $this->validateRules($rules);
     $convertedTags = [];
     foreach ($rules as $patternPath => $rule) {
         $parameters = $rule['parameters'];
         $tagTypeRule = $rule['tagType'];
         $tagNameRule = $rule['tagName'];
         $matches = $metadata->matchAndRemoveByKey($patternPath);
         if (!empty($matches)) {
             $matchesGroups = $this->groupMatches($matches);
             foreach ($matchesGroups as $matchedGroup) {
                 $matchedParameters = $this->matchParameters($parameters, $matchedGroup);
                 // Now build tag type
                 $tagType = $this->replaceParameters($matchedParameters, $tagTypeRule);
                 // Then build tagname
                 $tagName = $this->replaceParameters($matchedParameters, $tagNameRule);
                 // Then the whole tags
                 $convertedTags[$tagType][] = $tagName;
             }
         }
     }
     return [$convertedTags, $metadata];
 }