You are here

public function CsvEncoder::decode in CSV Serialization 8

Same name and namespace in other branches
  1. 8.2 src/Encoder/CsvEncoder.php \Drupal\csv_serialization\Encoder\CsvEncoder::decode()

File

src/Encoder/CsvEncoder.php, line 281

Class

CsvEncoder
Adds CSV encoder support for the Serialization API.

Namespace

Drupal\csv_serialization\Encoder

Code

public function decode($data, $format, array $context = []) {
  $csv = Reader::createFromString($data);
  $csv
    ->setDelimiter($this->delimiter);
  $csv
    ->setEnclosure($this->enclosure);
  $csv
    ->setEscape($this->escapeChar);
  $results = [];
  foreach ($csv
    ->fetchAssoc() as $row) {
    $results[] = $this
      ->expandRow($row);
  }
  return $results;
}