Exemple #1
0
 public function testDot()
 {
     $array = Arr::dot(['foo' => ['bar' => 'baz']]);
     $this->assertEquals(['foo.bar' => 'baz'], $array);
     $array = Arr::dot([]);
     $this->assertEquals([], $array);
     $array = Arr::dot(['foo' => []]);
     $this->assertEquals(['foo' => []], $array);
     $array = Arr::dot(['foo' => ['bar' => []]]);
     $this->assertEquals(['foo.bar' => []], $array);
 }
Exemple #2
0
 /**
  * Transforms the input array into the output array based on the rules
  * stated in the configuration file.
  *
  * @return array
  */
 public function transform($root = '')
 {
     $output = [];
     $array = Arr::dot($this->feed_data);
     $rules = Arr::dot($this->rules);
     $all_rules = [];
     foreach ($rules as $key => $value) {
         if (strpos($key, '*')) {
             $new_keys = Arr::expandKeys($key, $this->expand_size);
             $new_values = Arr::expandKeys($value, $this->expand_size);
             $new_rules = array_combine($new_keys, $new_values);
             foreach ($new_rules as $new_key => $new_rule) {
                 if (array_key_exists($new_rule, $array)) {
                     $all_rules[$new_key] = $new_rule;
                 }
             }
         } else {
             $all_rules[$key] = $value;
         }
     }
     foreach ($all_rules as $k => $v) {
         Arr::set($output, $k, Arr::get($array, $v));
     }
     return $output;
 }