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;
 }
 /**
  * @param TransformerInterface $transformer
  * @throws \Exception
  */
 public function registerTransformer(TransformerInterface $transformer)
 {
     $id = $transformer->getId();
     if (isset($this->transformers[$id])) {
         throw new \Exception("Transformer with ID {$id} already exists");
     }
     $this->transformers[$id] = $transformer;
 }
 /**
  * Transforms the data into one unique format
  *
  * @return array
  */
 public function transform()
 {
     $originalData = $this->getData();
     $transformedData = $this->transformer->transform();
     $restData = $this->unsetKeys($originalData, $this->transformer->getSupportedKeys());
     $this->checkIfAllValuesWereProceeded($restData, $this->transformer);
     return $transformedData;
 }
Exemple #4
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;
 }
 /**
  * load the children collection.
  */
 private function load()
 {
     if ($this->collection == null) {
         $this->collection = $this->transformer->getChildren($this->page);
     }
 }