Example #1
0
 public function apply($value)
 {
     // Note: PHP doesn't like $this->callback($value)
     $callback = $this->callback;
     $result = $callback($value);
     return false === is_null($this->chain) ? $this->chain->apply($result) : $result;
 }
Example #2
0
 /**
  * Applies the defined transformations to a CSV row.
  * Called internally by the Reader\CSV for each row, but can also be invoked
  * manually outside the processing pipeline.
  *
  * @param array $value
  * @return array
  */
 public function apply($value)
 {
     $resultant = [];
     $has_columns_filter = !empty($this->only_columns);
     $has_column_mappings = !empty($this->column_maps);
     $has_column_names = !empty($this->columns_to_names);
     foreach ($value as $id => $value) {
         if ($has_columns_filter && !in_array($id, $this->only_columns)) {
             continue;
         }
         $key = $has_column_names && isset($this->columns_to_names[$id]) ? $this->columns_to_names[$id] : $id;
         $resultant[$key] = $has_column_mappings && isset($this->column_maps[$id]) ? $this->column_maps[$id]($value) : $value;
     }
     return false === is_null($this->chain) ? $this->chain->apply($resultant) : $resultant;
 }