diff --git a/composer.json b/composer.json index 1a9f699..0896443 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,6 @@ "type": "drupal-module", "license": "GPL-2.0+", "require": { - "league/csv": "^8.0" + "league/csv": "^9.1" } } diff --git a/composer.lock b/composer.lock index cbc9f93..5b30eda 100644 --- a/composer.lock +++ b/composer.lock @@ -4,40 +4,47 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "7be0ca58917fe33e4131446b9b871425", + "content-hash": "bf7c9a7d4a6d4836f9eba13ecb7c7f74", "packages": [ { "name": "league/csv", - "version": "8.2.2", + "version": "9.1.1", "source": { "type": "git", "url": "https://github.com/thephpleague/csv.git", - "reference": "fa8bc05f64eb6c66b96edfaf60648f022ecb5f55" + "reference": "66118f5c2a7e4da77e743e69f74773c63b73e8f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/csv/zipball/fa8bc05f64eb6c66b96edfaf60648f022ecb5f55", - "reference": "fa8bc05f64eb6c66b96edfaf60648f022ecb5f55", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/66118f5c2a7e4da77e743e69f74773c63b73e8f9", + "reference": "66118f5c2a7e4da77e743e69f74773c63b73e8f9", "shasum": "" }, "require": { "ext-mbstring": "*", - "php": ">=5.5.0" + "php": ">=7.0.10" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^1.9", - "phpunit/phpunit": "^4.0" + "ext-curl": "*", + "friendsofphp/php-cs-fixer": "^2.0", + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "8.2-dev" + "dev-master": "9.x-dev" } }, "autoload": { "psr-4": { "League\\Csv\\": "src" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -61,7 +68,7 @@ "read", "write" ], - "time": "2017-07-12T07:18:20+00:00" + "time": "2017-11-28T08:29:49+00:00" } ], "packages-dev": [], diff --git a/src/Encoder/CsvEncoder.php b/src/Encoder/CsvEncoder.php index 3c10348..813d431 100644 --- a/src/Encoder/CsvEncoder.php +++ b/src/Encoder/CsvEncoder.php @@ -9,6 +9,8 @@ use League\Csv\Reader; use SplTempFileObject; use Drupal\Component\Utility\Html; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; +use League\Csv\ByteSequence; +use League\Csv\CharsetConverter; /** * Adds CSV encoder support for the Serialization API. @@ -138,15 +140,13 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { // Set data. if ($this->useUtf8Bom) { - $csv->setOutputBOM(Writer::BOM_UTF8); + $csv->setOutputBOM(ByteSequence::BOM_UTF8); } $headers = $this->extractHeaders($data, $context); $csv->insertOne($headers); $csv->addFormatter(array($this, 'formatRow')); - foreach ($data as $row) { - $csv->insertOne($row); - } - $output = $csv->__toString(); + $csv->insertAll($data); + $output = $csv->getContent(); return trim($output); } @@ -168,7 +168,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { * will all other rows. This is inherent in the structure of a CSV. * * @return array - * An array of CSV headesr. + * An array of CSV headers. */ protected function extractHeaders($data, array $context = array()) { $headers = []; @@ -203,7 +203,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { public function formatRow($row) { $formatted_row = array(); - foreach ($row as $column_name => $cell_data) { + foreach ($row as $cell_data) { if (is_array($cell_data)) { $cell_value = $this->flattenCell($cell_data); } @@ -250,7 +250,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { * * @return string * The formatted value. - * */ protected function formatValue($value) { if ($this->stripTags) { @@ -274,7 +273,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { $csv->setEscape($this->escapeChar); $results = []; - foreach ($csv->fetchAssoc() as $row) { + foreach ($csv->getRecords() as $row) { $results[] = $this->expandRow($row); } @@ -322,7 +321,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { protected function arrayDepth($array) { $max_indentation = 1; - $array_str = print_r($array, true); + $array_str = print_r($array, TRUE); $lines = explode("\n", $array_str); foreach ($lines as $line) { @@ -339,8 +338,17 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { /** * Set CSV settings from the Views settings array. * + * This allows modules which provides integration + * (views_data_export for example) to change default settings. + * * If a tab character ('\t') is used for the delimiter, it will be properly * converted to "\t". + * + * @param array $settings + * Array of settings. + * + * @see \Drupal\views_data_export\Plugin\views\style\DataExport() + * for list of settings. */ protected function setSettings(array $settings) { // Replace tab character with one that will be properly interpreted. diff --git a/src/EventSubscriber/CsvSubscriber.php b/src/EventSubscriber/CsvSubscriber.php index 9a5a399..ccf852c 100644 --- a/src/EventSubscriber/CsvSubscriber.php +++ b/src/EventSubscriber/CsvSubscriber.php @@ -4,7 +4,6 @@ namespace Drupal\csv_serialization\EventSubscriber; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /**