Exemple #1
0
 /**
  * Set a given configuration value.
  *
  * @param  array|string  $key
  * @param  mixed   $value
  * @return void
  */
 public function set($key, $value = null)
 {
     if (is_array($key)) {
         foreach ($key as $innerKey => $innerValue) {
             Arr::set($this->items, $innerKey, $innerValue);
         }
     } else {
         Arr::set($this->items, $key, $value);
     }
 }
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;
 }
Exemple #3
0
 public function testSet()
 {
     $array = ['products' => ['desk' => ['price' => 100]]];
     Arr::set($array, 'products.desk.price', 200);
     $this->assertEquals(['products' => ['desk' => ['price' => 200]]], $array);
     Arr::set($array, null, 'Yeehaw');
     $this->assertEquals('Yeehaw', $array);
 }